Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clowdflows
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alain Shakour
clowdflows
Commits
67f38203
Commit
67f38203
authored
Nov 02, 2012
by
matjaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved import/export and added function for the export to be callable from the web
parent
36b971d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
52 deletions
+92
-52
workflows/management/commands/export_package.py
workflows/management/commands/export_package.py
+35
-30
workflows/management/commands/import_package.py
workflows/management/commands/import_package.py
+22
-22
workflows/urls.py
workflows/urls.py
+2
-0
workflows/views.py
workflows/views.py
+33
-0
No files found.
workflows/management/commands/export_package.py
View file @
67f38203
...
...
@@ -21,7 +21,7 @@ class Command(BaseCommand):
)
def
handle
(
self
,
*
args
,
**
options
):
if
(
len
(
args
)
<
2
):
if
(
len
(
args
)
<
2
):
raise
CommandError
(
'Arguments "file_name" and "package_name" are required!'
)
try
:
...
...
@@ -29,25 +29,35 @@ class Command(BaseCommand):
except
:
raise
CommandError
(
'There was a problem with creating/overwriting given output file'
)
result
=
self
.
export_package_string
(
self
.
stdout
.
write
,
args
[
1
:],
options
[
'newuid'
],
options
[
'all'
])
try
:
f
.
write
(
result
)
except
:
raise
CommandError
(
'There was a problem with writing to the given output file'
)
self
.
stdout
.
write
(
'Export procedure successfully finished. Results written to the file.
\n
'
)
def
export_package_string
(
self
,
write
,
packages
,
newuid
,
all
):
result
=
[]
objs
=
[]
argsIter
=
iter
(
args
)
next
(
argsIter
)
if
options
[
'all'
]:
argsIter
=
[
'all'
]
for
package
in
argsIter
:
if
options
[
'all'
]:
if
all
:
packages
=
[
'all'
]
for
package
in
packages
:
if
all
:
wids
=
AbstractWidget
.
objects
.
all
()
else
:
wids
=
AbstractWidget
.
objects
.
filter
(
package
=
package
)
inps
=
AbstractInput
.
objects
.
filter
(
widget__in
=
[
x
.
id
for
x
in
wids
])
outs
=
AbstractOutput
.
objects
.
filter
(
widget__in
=
[
x
.
id
for
x
in
wids
])
opts
=
AbstractOption
.
objects
.
filter
(
abstract_input__in
=
[
x
.
id
for
x
in
inps
])
cats
=
Category
.
objects
.
filter
(
id__in
=
[
x
.
category
.
id
for
x
in
wids
])
inps
=
AbstractInput
.
objects
.
filter
(
widget__in
=
[
x
.
id
for
x
in
wids
])
outs
=
AbstractOutput
.
objects
.
filter
(
widget__in
=
[
x
.
id
for
x
in
wids
])
opts
=
AbstractOption
.
objects
.
filter
(
abstract_input__in
=
[
x
.
id
for
x
in
inps
])
cats
=
Category
.
objects
.
filter
(
id__in
=
[
x
.
category
.
id
for
x
in
wids
])
#retrieve all parents
catNum
=
len
(
cats
)
while
True
:
cats
=
cats
|
Category
.
objects
.
filter
(
id__in
=
[
x
.
parent
.
id
for
x
in
cats
if
x
.
parent
!=
None
])
cats
=
cats
|
Category
.
objects
.
filter
(
id__in
=
[
x
.
parent
.
id
for
x
in
cats
if
x
.
parent
!=
None
])
if
catNum
==
len
(
cats
):
break
else
:
...
...
@@ -59,28 +69,23 @@ class Command(BaseCommand):
objs
.
extend
(
inps
)
objs
.
extend
(
opts
)
if
len
(
wids
)
>
0
:
self
.
stdout
.
write
(
'Package "%s" contains:
\n
'
%
package
)
self
.
stdout
.
write
(
' % 4i AbstractWidget(s)
\n
'
%
len
(
wids
))
self
.
stdout
.
write
(
' % 4i AbstractInput(s)
\n
'
%
len
(
inps
))
self
.
stdout
.
write
(
' % 4i AbstractOutput(s)
\n
'
%
len
(
outs
))
self
.
stdout
.
write
(
' % 4i AbstractOption(s)
\n
'
%
len
(
opts
))
self
.
stdout
.
write
(
' % 4i Category(s)
\n
'
%
len
(
cats
))
if
len
(
wids
)
>
0
:
write
(
'Package "%s" contains:
\n
'
%
package
)
write
(
' % 4i AbstractWidget(s)
\n
'
%
len
(
wids
))
write
(
' % 4i AbstractInput(s)
\n
'
%
len
(
inps
))
write
(
' % 4i AbstractOutput(s)
\n
'
%
len
(
outs
))
write
(
' % 4i AbstractOption(s)
\n
'
%
len
(
opts
))
write
(
' % 4i Category(s)
\n
'
%
len
(
cats
))
else
:
self
.
stdout
.
write
(
'Package "%s" was not found!
\n
'
%
package
)
write
(
'Package "%s" was not found!
\n
'
%
package
)
#be careful uid is only changed on these instances and is not written to the database
if
options
[
'newuid'
]
:
if
newuid
:
for
a
in
objs
:
a
.
uid
=
str
(
uuid
.
uuid4
())
outstr
=
""
if
len
(
objs
)
>
0
:
outstr
=
serializers
.
serialize
(
"json"
,
objs
,
indent
=
2
,
ensure_ascii
=
False
)
try
:
f
.
write
(
outstr
)
except
:
raise
CommandError
(
'There was a problem with writing to the given output file'
)
result
=
""
if
len
(
objs
)
>
0
:
result
=
serializers
.
serialize
(
"json"
,
objs
,
indent
=
2
,
ensure_ascii
=
False
)
self
.
stdout
.
write
(
'Export procedure successfully finished. Results written to the file.
\n
'
)
\ No newline at end of file
return
result
\ No newline at end of file
workflows/management/commands/import_package.py
View file @
67f38203
...
...
@@ -23,20 +23,20 @@ class Command(BaseCommand):
raise
CommandError
(
'Arguments "file_name" and "package_name" are required!'
)
try
:
instr
=
open
(
args
[
0
],
'r'
).
read
()
string
=
open
(
args
[
0
],
'r'
).
read
()
except
:
raise
CommandError
(
'There was a problem with opening given input file'
)
self
.
import
String
(
self
,
instr
,
options
[
'replace'
])
self
.
import
_package_string
(
self
,
string
,
options
[
'replace'
])
self
.
stdout
.
write
(
'Import procedure successfully finished.
\n
'
)
def
import
String
(
self
,
obj
,
instr
,
replace
):
def
import
_package_string
(
self
,
outWriter
,
string
,
replace
):
#get all objects from file and eliminate empty UID and check for UID duplicates
objsFile
=
list
(
serializers
.
deserialize
(
"json"
,
instr
))
objsFile
=
list
(
serializers
.
deserialize
(
"json"
,
string
))
objsFileNoUid
=
[
x
for
x
in
objsFile
if
len
(
x
.
object
.
uid
)
==
0
]
objsFile
=
[
x
for
x
in
objsFile
if
len
(
x
.
object
.
uid
)
!=
0
]
if
len
(
objsFileNoUid
)
>
0
:
o
bj
.
stdout
.
write
(
'File contains %i model(s) without UID field set. Those will not be imported! If you wish to'
o
utWriter
.
stdout
.
write
(
'File contains %i model(s) without UID field set. Those will not be imported! If you wish to'
' assign them random UIDs then use the "-n" option when exporting models with the "export_package"'
' command. Afterwards, you will be able to import them.
\n
'
%
len
(
objsFileNoUid
))
if
len
(
Counter
([
x
.
object
.
uid
for
x
in
objsFile
]))
!=
len
(
objsFile
):
...
...
@@ -52,12 +52,12 @@ class Command(BaseCommand):
cats
=
[
x
for
x
in
objsFile
if
isinstance
(
x
.
object
,
Category
)]
#ouput statistics about file
o
bj
.
stdout
.
write
(
'Import contains:
\n
'
)
o
bj
.
stdout
.
write
(
' % 4i AbstractWidget(s)
\n
'
%
len
(
wids
))
o
bj
.
stdout
.
write
(
' % 4i AbstractInput(s)
\n
'
%
len
(
inps
))
o
bj
.
stdout
.
write
(
' % 4i AbstractOutput(s)
\n
'
%
len
(
outs
))
o
bj
.
stdout
.
write
(
' % 4i AbstractOption(s)
\n
'
%
len
(
opts
))
o
bj
.
stdout
.
write
(
' % 4i Category(s)
\n
'
%
len
(
cats
))
o
utWriter
.
stdout
.
write
(
'Import contains:
\n
'
)
o
utWriter
.
stdout
.
write
(
' % 4i AbstractWidget(s)
\n
'
%
len
(
wids
))
o
utWriter
.
stdout
.
write
(
' % 4i AbstractInput(s)
\n
'
%
len
(
inps
))
o
utWriter
.
stdout
.
write
(
' % 4i AbstractOutput(s)
\n
'
%
len
(
outs
))
o
utWriter
.
stdout
.
write
(
' % 4i AbstractOption(s)
\n
'
%
len
(
opts
))
o
utWriter
.
stdout
.
write
(
' % 4i Category(s)
\n
'
%
len
(
cats
))
#get all objects from database
objsDb
=
[]
...
...
@@ -88,9 +88,9 @@ class Command(BaseCommand):
'by type:
\n
- from file: %s
\n
- from database: %s
\n
Please resolve manually!'
%
(
objFileTypeId
,
objDbTypeId
))
#ouput statistics about database
o
bj
.
stdout
.
write
(
'Current database contains %i models,
\n
'
%
len
(
objsDb
))
o
bj
.
stdout
.
write
(
' of which %i models have UID set,
\n
'
%
len
(
objsdbDict
))
o
bj
.
stdout
.
write
(
' of which %i models match with the imported models and will be updated.
\n
'
%
len
(
idMappingDict
))
o
utWriter
.
stdout
.
write
(
'Current database contains %i models,
\n
'
%
len
(
objsDb
))
o
utWriter
.
stdout
.
write
(
' of which %i models have UID set,
\n
'
%
len
(
objsdbDict
))
o
utWriter
.
stdout
.
write
(
' of which %i models match with the imported models and will be updated.
\n
'
%
len
(
idMappingDict
))
#prepare statistics
statDict
=
dict
([(
'old:'
+
str
(
t
),
len
(
t
.
objects
.
all
()))
for
t
in
[
AbstractWidget
,
AbstractInput
,
AbstractOutput
,
AbstractOption
,
Category
]])
...
...
@@ -105,7 +105,7 @@ class Command(BaseCommand):
#objsFile = objsFileNew
#save models to the database - update the ids for the matching models and remove the ids (to get a new one) for the non matching models
o
bj
.
stdout
.
write
(
'Merging file and database models ...'
)
o
utWriter
.
stdout
.
write
(
'Merging file and database models ...'
)
importedUids
=
dict
()
for
objFile
in
objsFile
:
objFileTypeId
=
str
(
type
(
objFile
.
object
))
+
':'
+
str
(
objFile
.
object
.
id
)
...
...
@@ -132,10 +132,10 @@ class Command(BaseCommand):
objFile
.
save
()
idMappingDict
[
objFileTypeId
]
=
objFile
.
object
.
id
importedUids
[
objFile
.
object
.
uid
]
=
True
o
bj
.
stdout
.
write
(
' done.
\n
'
)
o
utWriter
.
stdout
.
write
(
' done.
\n
'
)
#correct also the foreign keys
o
bj
.
stdout
.
write
(
'Updating model
\'
s foreign keys ...'
)
o
utWriter
.
stdout
.
write
(
'Updating model
\'
s foreign keys ...'
)
for
objFile
in
wids
:
objFile
.
object
.
category
=
Category
.
objects
.
get
(
id
=
idMappingDict
[
str
(
Category
)
+
':'
+
str
(
objFile
.
old_category_id
)])
objFile
.
save
()
...
...
@@ -152,10 +152,10 @@ class Command(BaseCommand):
if
not
objFile
.
object
.
parent_id
is
None
:
objFile
.
object
.
parent
=
Category
.
objects
.
get
(
id
=
idMappingDict
[
str
(
Category
)
+
':'
+
str
(
objFile
.
old_parent_id
)])
objFile
.
save
()
o
bj
.
stdout
.
write
(
' done.
\n
'
)
o
utWriter
.
stdout
.
write
(
' done.
\n
'
)
if
replace
:
o
bj
.
stdout
.
write
(
'Removing unnecessary inputs/options/outputs...'
)
o
utWriter
.
stdout
.
write
(
'Removing unnecessary inputs/options/outputs...'
)
for
wid
in
[
wid
for
wid
in
objsFile
if
isinstance
(
wid
.
object
,
AbstractWidget
)]:
for
inp
in
AbstractInput
.
objects
.
filter
(
widget
=
wid
.
object
.
id
):
for
opt
in
AbstractOption
.
objects
.
filter
(
abstract_input
=
inp
.
id
):
...
...
@@ -169,13 +169,13 @@ class Command(BaseCommand):
if
not
importedUids
.
has_key
(
out
.
uid
):
statDict
[
'del:'
+
str
(
AbstractOutput
)]
+=
1
out
.
delete
()
o
bj
.
stdout
.
write
(
' done.
\n
'
)
o
utWriter
.
stdout
.
write
(
' done.
\n
'
)
#update and output statistics
statDict
=
dict
(
statDict
.
items
()
+
dict
([(
'new:'
+
str
(
t
),
len
(
t
.
objects
.
all
()))
for
t
in
[
AbstractWidget
,
AbstractInput
,
AbstractOutput
,
AbstractOption
,
Category
]]).
items
())
o
bj
.
stdout
.
write
(
'Database models count statistics: pre-import + ( added | modified | deleted ) = after-import
\n
'
)
o
utWriter
.
stdout
.
write
(
'Database models count statistics: pre-import + ( added | modified | deleted ) = after-import
\n
'
)
for
t
in
[
AbstractWidget
,
AbstractInput
,
AbstractOutput
,
AbstractOption
,
Category
]:
o
bj
.
stdout
.
write
(
' % 15s: % 5i + (% 4i | % 4i | % 4i ) = % 5i
\n
'
%
o
utWriter
.
stdout
.
write
(
' % 15s: % 5i + (% 4i | % 4i | % 4i ) = % 5i
\n
'
%
(
t
.
__name__
,
statDict
[
'old:'
+
str
(
t
)],
statDict
[
'add:'
+
str
(
t
)],
...
...
workflows/urls.py
View file @
67f38203
...
...
@@ -58,5 +58,7 @@ urlpatterns = patterns('',
url
(
r
'^get-executed-status/'
,
'workflows.views.get_executed_status'
,
name
=
'get executed status'
),
url
(
r
'^reset-workflow/'
,
'workflows.views.reset_workflow'
,
name
=
'reset workflow'
),
url
(
r
'^export-package/(?P<packages>.+)/$'
,
'workflows.views.export_package'
,
name
=
'export_package'
),
url
(
r
'^latino/'
,
include
(
urlpatterns_latino
)),
)
\ No newline at end of file
workflows/views.py
View file @
67f38203
...
...
@@ -6,6 +6,7 @@ from django.core import serializers
from django.utils import simplejson
from workflows.urls import *
from workflows.helpers import *
from workflows.management.commands.export_package import Command
import workflows.interaction_views
import workflows.visualization_views
import sys
...
...
@@ -1209,3 +1210,35 @@ def workflow_url(request):
return render(request,'workflow_url.html', {"workflow":request.user.userprofile.active_workflow})
else:
return HttpResponse(status=200)
@login_required
def export_package(request, packages):
try:
if not request.user.is_staff:
return HttpResponse(status=405)
except:
return HttpResponse(status=400)
newuid = request.GET.get('newuid', 'False')=='True'
all = request.GET.get('all', 'False')=='True'
packagesArray = packages.split('-')
class OutWriter:
msgs = ""
def write(self, msg):
self.msgs += msg
ov = OutWriter()
result = Command().export_package_string(ov.write, packagesArray, newuid, all)
content = '----------------------------------------\n' + \
'Export procedure message:' +\
"\n----------------------------------------\n" +\
ov.msgs + \
"\n----------------------------------------\n" + \
"Exported data:" +\
"\n----------------------------------------\n" +\
result + \
"\n----------------------------------------"
response = HttpResponse(mimetype='text/plain',content=content)
return response
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment