@@ -45,7 +45,7 @@ def write_csv(filename, header, data, encoding="utf-8"):
4545
4646def write_file (filename = None , header = None , data = None , fail = False , model = "auto" ,
4747 launchfile = "import_auto.sh" , worker = 1 , batch_size = 10 , init = False , encoding = "utf-8" ,
48- conf_file = False , groupby = '' , sep = ";" , python_exe = '' , path = '' , context = None , ignore = "" ):
48+ conf_file = False , groupby = '' , sep = ";" , python_exe = 'python ' , path = '' , context = None , ignore = "" ):
4949 def get_model ():
5050 if model == "auto" :
5151 return filename .split (os .sep )[- 1 ][:- 4 ]
@@ -58,13 +58,65 @@ def get_model():
5858 if not launchfile :
5959 return
6060
61+ if not path .endswith (os .sep ):
62+ path = os .path .join (path , "" )
63+
64+ py_script = 'odoo_import_thread.py'
65+ os_cmd = os .path .join (path , py_script )
66+ if ' ' in os_cmd :
67+ os_cmd = '' .join (('"' , os_cmd , '"' ))
68+
6169 mode = init and 'w' or 'a'
6270 with open (launchfile , mode ) as myfile :
63- myfile .write ("%s %sodoo_import_thread.py -c %s --file=%s --model=%s --encoding=%s --worker=%s --size=%s --groupby=%s --ignore=%s --sep=\" %s\" %s\n " %
64- (python_exe , path , conf_file , filename , get_model (), encoding , worker , batch_size , groupby , ignore , sep , context ))
71+ myfile .write ("%s %s -c %s --file=%s --model=%s --encoding=%s --worker=%s --size=%s --groupby=%s --ignore=%s --sep=\" %s\" %s\n " %
72+ (python_exe , os_cmd , conf_file , filename , get_model (), encoding , worker , batch_size , groupby , ignore , sep , context ))
6573 if fail :
66- myfile .write ("%s %sodoo_import_thread.py -c %s --fail --file=%s --model=%s --encoding=%s --ignore=%s --sep=\" %s\" %s\n " %
67- (python_exe , path , conf_file , filename , get_model (), encoding , ignore , sep , context ))
74+ myfile .write ("%s %s -c %s --fail --file=%s --model=%s --encoding=%s --ignore=%s --sep=\" %s\" %s\n " %
75+ (python_exe , os_cmd , conf_file , filename , get_model (), encoding , ignore , sep , context ))
76+
77+
78+ ################################################
79+ # Method to merge file together based on a key #
80+ ################################################
81+
82+ def write_file_dict (filename , header , data ):
83+ data_rows = []
84+ for _ , val in data .iteritems ():
85+ r = [val .get (h , '' ) for h in header ]
86+ data_rows .append (r )
87+ write_csv (filename , header , data_rows )
88+
89+
90+
91+ def read_file_dict (file_name , id_name ):
92+ file_ref = open (file_name , 'r' )
93+ reader = UnicodeReader (file_ref , delimiter = ';' )
94+
95+ head = reader .next ()
96+ res = {}
97+ for line in reader :
98+ if any (line ):
99+ line_dict = dict (zip (head , line ))
100+ res [line_dict [id_name ]] = line_dict
101+ return res , head
102+
103+ def merge_file (master , child , field ):
104+ res = {}
105+ for key , val in master .iteritems ():
106+ data = dict (child .get (val [field ], {}))
107+ new_dict = dict (val )
108+ new_dict .update (data )
109+ res [key ] = new_dict
110+ return res
111+
112+
113+ def merge_header (* args ):
114+ old_header = [item for sublist in args for item in sublist ]
115+ header = []
116+ for h in old_header :
117+ if h and h not in header :
118+ header .append (h )
119+ return header
68120
69121class ListWriter (object ):
70122 def __init__ (self ):
0 commit comments