def handle(self, *args, **options): print(options) stub_base = options['stub_base'] if options['regulation'] is None and options['files'] == []: raise CommandError('Must supply either a regulation to import or a specific JSON file.') elif options['regulation'] is not None and options['files'] != []: raise CommandError('Cannot specify both regulation and files at the same time.') elif options['regulation'] is None and options['files'] != []: files = [os.path.join(stub_base, f) for f in options['files']] elif options['regulation'] is not None and options['files'] == []: reg = options['regulation'] files = self.find_regulation_files(stub_base, reg) # the request dummy is meant to fool the regcore_write api into thinking that # this is a request object class RequestDummy: def __init__(self): self.body = '' for f in files: data = json.dumps(json.load(open(f, 'r'))) request = RequestDummy() request.body = data filename_data = f.replace(stub_base + '/', '').split('/') file_type = filename_data[0] logger.info('importing {}'.format(os.path.join(*filename_data))) if file_type == 'regulation': label = filename_data[1] version = filename_data[2] regulation.add(request, label, version) elif file_type == 'notice': version = filename_data[1] notice.add(request, version) elif file_type == 'layer': layer_type = filename_data[1] label = filename_data[2] version = filename_data[3] layer.add(request, layer_type, label, version) elif file_type == 'diff': label = filename_data[1] old_version = filename_data[2] new_version = filename_data[3] diff.add(request, label, old_version, new_version) if settings.DEBUG: # If DEBUG is enabled, memory usage will increase linearly # for each JSON file imported. This should clean it up. # https://docs.djangoproject.com/en/1.6/faq/models/#why-is-django-leaking-memory db.reset_queries()
def handle(self, *args, **options): print(options) stub_base = options['stub_base'] if options['regulation'] is None and options['files'] == []: raise CommandError( 'Must supply either a regulation to import or a specific JSON file.' ) elif options['regulation'] is not None and options['files'] != []: raise CommandError( 'Cannot specify both regulation and files at the same time.') elif options['regulation'] is None and options['files'] != []: files = [os.path.join(stub_base, f) for f in options['files']] elif options['regulation'] is not None and options['files'] == []: reg = options['regulation'] files = self.find_regulation_files(stub_base, reg) # the request dummy is meant to fool the regcore_write api into thinking that # this is a request object class RequestDummy: def __init__(self): self.body = '' for f in files: data = json.dumps(json.load(open(f, 'r'))) request = RequestDummy() request.body = data filename_data = f.replace(stub_base + '/', '').split('/') file_type = filename_data[0] if file_type == 'regulation': label = filename_data[1] version = filename_data[2] regulation.add(request, label, version) elif file_type == 'notice': version = filename_data[1] notice.add(request, version) elif file_type == 'layer': layer_type = filename_data[1] label = filename_data[2] version = filename_data[3] layer.add(request, layer_type, label, version) elif file_type == 'diff': label = filename_data[1] old_version = filename_data[2] new_version = filename_data[3] diff.add(request, label, old_version, new_version)
def handle(self, *args, **options): print(options) stub_base = options['stub_base'] if options['regulation'] is None and options['files'] == []: raise CommandError('Must supply either a regulation to import or ' 'a specific JSON file.') elif options['regulation'] is not None and options['files'] != []: raise CommandError('Cannot specify both regulation and files at ' 'the same time.') elif options['regulation'] is None and options['files'] != []: files = [os.path.join(stub_base, f) for f in options['files']] elif options['regulation'] is not None and options['files'] == []: reg = options['regulation'] files = self.find_regulation_files(stub_base, reg) # the request dummy is meant to fool the regcore_write api into # thinking that this is a request object class RequestDummy: def __init__(self): self.body = '' for f in files: data = json.dumps(json.load(open(f, 'r'))) request = RequestDummy() request.body = data filename_data = f.replace(stub_base + '/', '').split('/') file_type = filename_data[0] if file_type == 'regulation': label = filename_data[1] version = filename_data[2] regulation.add(request, label, version) elif file_type == 'notice': version = filename_data[1] notice.add(request, version) elif file_type == 'layer': layer_type = filename_data[1] label = filename_data[2] version = filename_data[3] layer.add(request, layer_type, label, version) elif file_type == 'diff': label = filename_data[1] old_version = filename_data[2] new_version = filename_data[3] diff.add(request, label, old_version, new_version)
def handle(self, *args, **options): print(options) stub_base = options['stub_base'] if options['regulation'] is None and options['files'] == []: raise CommandError( 'Must supply either a regulation to import or a specific JSON file.' ) elif options['regulation'] is not None and options['files'] != []: raise CommandError( 'Cannot specify both regulation and files at the same time.') elif options['regulation'] is None and options['files'] != []: files = [os.path.join(stub_base, f) for f in options['files']] elif options['regulation'] is not None and options['files'] == []: reg = options['regulation'] files = self.find_regulation_files(stub_base, reg) # the request dummy is meant to fool the regcore_write api into thinking that # this is a request object class RequestDummy: def __init__(self): self.body = '' for f in files: data = json.dumps(json.load(open(f, 'r'))) request = RequestDummy() request.body = data filename_data = f.replace(stub_base + '/', '').split('/') file_type = filename_data[0] logger.info('importing {}'.format(os.path.join(*filename_data))) if file_type == 'regulation': label = filename_data[1] version = filename_data[2] regulation.add(request, label, version) elif file_type == 'notice': part = options['regulation'] version = filename_data[1] # Handle new-style per-part notices if version == part: version = filename_data[2] notice.add(request, part, version) elif file_type == 'layer': layer_type = filename_data[1] label = filename_data[2] version = filename_data[3] layer.add(request, layer_type, label, version) elif file_type == 'diff': label = filename_data[1] old_version = filename_data[2] new_version = filename_data[3] diff.add(request, label, old_version, new_version) if settings.DEBUG: # If DEBUG is enabled, memory usage will increase linearly # for each JSON file imported. This should clean it up. # https://docs.djangoproject.com/en/1.6/faq/models/#why-is-django-leaking-memory db.reset_queries()