Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions odoo_csv_tools/lib/internal/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def write_csv(filename, header, data):

def write_file(filename=None, header=None, data=None, fail=False, model="auto",
launchfile="import_auto.sh", worker=1, batch_size=10, init=False,
conf_file=False, groupby='', sep=";", python_exe='python', path='./', context=None, ignore=""):
conf_file=False, groupby='', sep=";", python_exe='python', path='', context=None, ignore=""):
def get_model():
if model == "auto":
return filename.split(os.sep)[-1][:-4]
Expand All @@ -56,13 +56,21 @@ def get_model():
conf_file = conf_file or "%s%s%s" % ('conf', os.sep, 'connection.conf')
write_csv(filename, header, data)

if not path.endswith(os.sep):
path = os.path.join(path, "")

py_script = 'odoo_import_thread.py'
os_cmd = os.path.join(path, py_script)
if ' ' in os_cmd:
os_cmd =''.join(('"', os_cmd, '"'))

mode = init and 'w' or 'a'
with open(launchfile, mode) as myfile:
myfile.write("%s %sodoo_import_thread.py -c %s --file=%s --model=%s --worker=%s --size=%s --groupby=%s --ignore=%s --sep=\"%s\" %s\n" %
(python_exe, path, conf_file, filename, get_model(), worker, batch_size, groupby, ignore, sep, context))
myfile.write("%s %s -c %s --file=%s --model=%s --worker=%s --size=%s --groupby=%s --ignore=%s --sep=\"%s\" %s\n" %
(python_exe, os_cmd, conf_file, filename, get_model(), worker, batch_size, groupby, ignore, sep, context))
if fail:
myfile.write("%s %sodoo_import_thread.py -c %s --fail --file=%s --model=%s --ignore=%s --sep=\"%s\" %s\n" %
(python_exe, path, conf_file, filename, get_model(), ignore, sep, context))
myfile.write("%s %s -c %s --fail --file=%s --model=%s --ignore=%s --sep=\"%s\" %s\n" %
(python_exe, os_cmd, conf_file, filename, get_model(), ignore, sep, context))


################################################
Expand Down
3 changes: 1 addition & 2 deletions odoo_csv_tools/lib/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from . internal.exceptions import SkippingException
from . import mapper


class Processor(object):
def __init__(self, filename=None, delimiter=";", encoding='utf-8-sig', header=None, data=None, preprocess=lambda header, data: (header, data), conf_file=False):
self.file_to_write = OrderedDict()
Expand Down Expand Up @@ -74,7 +73,7 @@ def process(self, mapping, filename_out, import_args, t='list', null_values=['NU
self._add_data(head, data, filename_out, import_args)
return head, data

def write_to_file(self, script_filename, fail=True, append=False, python_exe='python', path='./'):
def write_to_file(self, script_filename, fail=True, append=False, python_exe='python', path=''):
init = not append
for _, info in self.file_to_write.items():
info_copy = dict(info)
Expand Down