Skip to content
Snippets Groups Projects
Commit 37927795 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

restructure command constructor to enable flexible args

parent 38f56f10
No related branches found
No related tags found
No related merge requests found
......@@ -33,13 +33,13 @@ class ImportTask(object):
depends_on = []
def __init__(self, command, traceback=False, stop_on_fail=False, progress_bar=False):
def __init__(self, command, **kwargs):
self.out_stream = command.stdout
self.err_stream = command.stderr
self.style = command.style
self.traceback = traceback
self.stop_on_fail = stop_on_fail
self.progress_bar = progress_bar
self.traceback = kwargs.get('traceback', False)
self.stop_on_fail = kwargs.get('stoponfail', False)
self.progress_bar = kwargs.get('progress_bar', False)
self.done = False
def _flush_target_models(self):
......@@ -125,6 +125,13 @@ class MysqlImportTask(ImportTask):
outer_sql = ""
def __init__(self, command, **kwargs):
super().__init__(*args, **kwargs)
try:
self.conn = kwargs['conn']
except KeyError as ke:
raise Exception('Connexion ("conn" kwarg) must be specified to create a {} object'.format(self.__class__.__name__))
def set_mysql_conn(self, conn):
self.conn = conn
......@@ -229,11 +236,16 @@ class ImportCommand(BaseCommand):
# list of tasks to run because they depend on initial option,
# directly or not
dependencies = append_dependencies(task_option)
print(dependencies)
dependencies_classes = {task_class for opt, task_class in option_to_task.items() if opt in dependencies}
task_kwargs = {
'traceback': options['errortb'],
'stoponfail': options['stoponfail'],
'progress_bar': options['progress_bar'],
'conn': options.get('conn')
}
while len(dependencies_classes)>0:
for task_class in copy.copy(dependencies_classes):
if not(set(task_class.depends_on) & dependencies_classes):
task = task_class(self, options['errortb'], options['stoponfail'], options['progress_bar'])
task = task_class(self, **task_kwargs)
task.run()
dependencies_classes.remove(task_class)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment