Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-diu
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bryan BRANCOTTE
django-diu
Commits
37927795
Commit
37927795
authored
6 years ago
by
Hervé MENAGER
Browse files
Options
Downloads
Patches
Plain Diff
restructure command constructor to enable flexible args
parent
38f56f10
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
django_diu/import_command.py
+18
-6
18 additions, 6 deletions
django_diu/import_command.py
with
18 additions
and
6 deletions
django_diu/import_command.py
+
18
−
6
View file @
37927795
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment