Commit 634688e8 authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

added --updateuid option to export_package, which assigns uuids to models with...

added --updateuid option to export_package, which assigns uuids to models with no uuids (new widgets, options, etc).
parent 58fba631
...@@ -46,7 +46,7 @@ def auto_import_all_packages(writeFunc, nobackup): ...@@ -46,7 +46,7 @@ def auto_import_all_packages(writeFunc, nobackup):
backupDir = os.path.join(BACKUP_DIR,"db_backup"+timeStamp) backupDir = os.path.join(BACKUP_DIR,"db_backup"+timeStamp)
writeFunc('Exporting to backup...\n') writeFunc('Exporting to backup...\n')
result = export_package.export_package_string(lambda text: writeFunc(' '+text), ('all',), False, True, 1) result = export_package.export_package_string(lambda text: writeFunc(' '+text), ('all',), False, False, True, 1)
try: try:
f = open(backupDir, 'w') f = open(backupDir, 'w')
f.write(result.encode('utf-8')) f.write(result.encode('utf-8'))
......
...@@ -14,6 +14,11 @@ class Command(BaseCommand): ...@@ -14,6 +14,11 @@ class Command(BaseCommand):
dest='newuid', dest='newuid',
default=False, default=False,
help='UID field of all exported models will be overwritten with new random values.'), help='UID field of all exported models will be overwritten with new random values.'),
make_option('-u', '--updateuid',
action="store_true",
dest='updateuid',
default=True,
help='Models without UIDs will be assigned new ones. Use this option when adding new parameters, widgets, etc, to an existing package.'),
make_option('-a', '--all', make_option('-a', '--all',
action="store_true", action="store_true",
dest='all', dest='all',
...@@ -25,12 +30,15 @@ class Command(BaseCommand): ...@@ -25,12 +30,15 @@ class Command(BaseCommand):
if (len(args) < 2): if (len(args) < 2):
raise CommandError('Arguments "file_name" and "package_name" are required!') raise CommandError('Arguments "file_name" and "package_name" are required!')
if options['newuid'] and options['updateuid']:
raise CommandError('--newuid and --updateuid flags are mutually exclusive.')
try: try:
f = open(args[0], 'w') f = open(args[0], 'w')
except: except:
raise CommandError('There was a problem with creating/overwriting given output file') raise CommandError('There was a problem with creating/overwriting given output file')
result = export_package_string(self.stdout.write, args[1:], options['newuid'], options['all'], int(options['verbosity'])) result = export_package_string(self.stdout.write, args[1:], options['newuid'], options['updateuid'], options['all'], int(options['verbosity']))
try: try:
f.write(result.encode('utf-8')) f.write(result.encode('utf-8'))
...@@ -42,9 +50,10 @@ class Command(BaseCommand): ...@@ -42,9 +50,10 @@ class Command(BaseCommand):
self.stdout.write('Tip: use higher "verbosity" option numbers to se more detailed output of what is being exported.\n') self.stdout.write('Tip: use higher "verbosity" option numbers to se more detailed output of what is being exported.\n')
self.stdout.write('Export procedure successfully finished. Results written to the file.\n') self.stdout.write('Export procedure successfully finished. Results written to the file.\n')
def export_package_string(writeFunc, packages, newuid, all, verbosity): def export_package_string(writeFunc, packages, newuid, updateuid, all, verbosity):
assert isinstance(packages, tuple) assert isinstance(packages, tuple)
assert isinstance(newuid, bool) assert isinstance(newuid, bool)
assert isinstance(updateuid, bool)
assert isinstance(all, bool) assert isinstance(all, bool)
objs = [] objs = []
...@@ -52,12 +61,11 @@ def export_package_string(writeFunc, packages, newuid, all, verbosity): ...@@ -52,12 +61,11 @@ def export_package_string(writeFunc, packages, newuid, all, verbosity):
objs.extend(get_package_objs_in_category(topCat, packages, all)) objs.extend(get_package_objs_in_category(topCat, packages, all))
if len(objs) == 0: if len(objs) == 0:
writeFunc('Selected package(s) were not found!\n') raise CommandError('Selected package(s) were not found!')
return "[\\n]"
#be careful uid is only changed on these instances and is not written to the database #be careful uid is only changed on these instances and is not written to the database
if newuid: for a in objs:
for a in objs: if newuid or (not a.uid and updateuid):
a.uid = str(uuid.uuid4()) a.uid = str(uuid.uuid4())
print_stataistics(objs, verbosity, writeFunc) print_stataistics(objs, verbosity, writeFunc)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment