Commit ba4585a0 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor to send data via json

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41720 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a284aa6b
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import sys import sys
import json
import helper_utils import helper_utils
from os import environ, path, putenv from os import environ, path, putenv
from getopt import getopt, GetoptError from getopt import getopt, GetoptError
...@@ -127,7 +128,7 @@ def main(): ...@@ -127,7 +128,7 @@ def main():
if not opt_list: if not opt_list:
help() help()
for opt, arg in opt_list: for opt, arg in opt_list:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
help() help()
...@@ -143,7 +144,8 @@ def main(): ...@@ -143,7 +144,8 @@ def main():
mimemapper = UnoMimemapper(hostname, port, **dict(environ)) mimemapper = UnoMimemapper(hostname, port, **dict(environ))
filter_dict = mimemapper.getFilterDict() filter_dict = mimemapper.getFilterDict()
type_dict = mimemapper.getTypeDict() type_dict = mimemapper.getTypeDict()
print "filter_dict = %s\ntype_dict = %s" % (filter_dict, type_dict)
print json.dumps((filter_dict, type_dict))
if "__main__" == __name__: if "__main__" == __name__:
main() main()
...@@ -35,6 +35,7 @@ from os import environ, path ...@@ -35,6 +35,7 @@ from os import environ, path
from interfaces.mimemapper import IMimemapper from interfaces.mimemapper import IMimemapper
from types import InstanceType from types import InstanceType
from utils import getCleanPythonEnvironment from utils import getCleanPythonEnvironment
import json
class MimeMapper(object): class MimeMapper(object):
...@@ -107,21 +108,21 @@ class MimeMapper(object): ...@@ -107,21 +108,21 @@ class MimeMapper(object):
uno_path = kw.get("uno_path", environ.get('uno_path')) uno_path = kw.get("uno_path", environ.get('uno_path'))
office_binary_path = kw.get("office_binary_path", office_binary_path = kw.get("office_binary_path",
environ.get('office_binary_path')) environ.get('office_binary_path'))
args = [path.join(office_binary_path, "python"), command = [path.join(office_binary_path, "python"),
pkg_resources.resource_filename(__name__, pkg_resources.resource_filename(__name__,
path.join("helper", "unomimemapper.py")), path.join("helper", "unomimemapper.py")),
"--uno_path=%s" % uno_path, "--uno_path=%s" % uno_path,
"--office_binary_path=%s" % office_binary_path, "--office_binary_path=%s" % office_binary_path,
"--hostname=%s" % hostname, "--hostname=%s" % hostname,
"--port=%s" % port] "--port=%s" % port]
stdout, stderr = Popen(args,
stdout, stderr = Popen(command,
stdout=PIPE, stdout=PIPE,
close_fds=True, close_fds=True,
env=getCleanPythonEnvironment()).communicate() env=getCleanPythonEnvironment()).communicate()
# XXX Use json here filter_dict, type_dict = json.loads(stdout)
exec(stdout)
for key, value in filter_dict.iteritems(): for filter_name, value in filter_dict.iteritems():
filter_name = key
flag = value.get("Flags") flag = value.get("Flags")
if flag in bad_flag_list: if flag in bad_flag_list:
continue continue
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment