diff --git a/django_gem_taxonomy/management/commands/django_gem_taxonomy_postinstall.py b/django_gem_taxonomy/management/commands/django_gem_taxonomy_postinstall.py new file mode 100644 index 0000000..800c2c9 --- /dev/null +++ b/django_gem_taxonomy/management/commands/django_gem_taxonomy_postinstall.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# oq-geoviewer +# Copyright (C) 2018-2019 GEM Foundation +# +# oq-geoviewer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# oq-geoviewer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# import subprocess +# from django.conf import settings +import os +from django.core.management import call_command +from openquake import gem_taxonomy_data +from django.core.management.base import BaseCommand + + +class Command(BaseCommand): + help = ("Standard command that will be runned by OpenQuake Engine 'install.py'" + " installer for each django application, if it exists.") + + def handle(self, *args, **options): + data_path = os.path.join(os.path.dirname(gem_taxonomy_data.__file__), 'data') + data_file = os.listdir(data_path)[-1] + print("Data_file: [%s]" % data_file) + call_command('migrate', 'django_gem_taxonomy', 'zero') + call_command('migrate', 'django_gem_taxonomy') + call_command('taxonomy_load_standard', "--no-dump", os.path.join(data_path, data_file)) diff --git a/django_gem_taxonomy/management/commands/taxonomy_load_standard.py b/django_gem_taxonomy/management/commands/taxonomy_load_standard.py index d2662c2..5012bd7 100644 --- a/django_gem_taxonomy/management/commands/taxonomy_load_standard.py +++ b/django_gem_taxonomy/management/commands/taxonomy_load_standard.py @@ -36,9 +36,9 @@ def add_arguments(self, parser): parser.add_argument('json_filename') # Optional arguments - # parser.add_argument( - # '-p', '--docker-project', nargs=1, help='docker project name', - # default='oqgeoviewer') + parser.add_argument( + '-n', '--no-dump', help='avoid create json files from DB' + , action='store_true', default=False) # parser.add_argument( # '-l', '--list', action='store_true', help='Show projects that need' # ' maintenance') @@ -134,9 +134,9 @@ def handle(self, *args, **options): ) call_command('dumpdata', 'django_gem_taxonomy', indent=4, - output='out/taxonomy_standard_dump.json') + output='/tmp/taxonomy_standard_dump.json') - tax_dump_in = json.load(open('out/taxonomy_standard_dump.json', 'r')) + tax_dump_in = json.load(open('/tmp/taxonomy_standard_dump.json', 'r')) tax = {} for el in tax_dump_in: @@ -225,5 +225,6 @@ def handle(self, *args, **options): tax['param'] = copy.deepcopy(tax_json_in['Param']) - json.dump(tax, open('out/taxonomy_standard4taxtweb.json', 'w'), - indent=4) + if not options['no_dump']: + json.dump(tax, open('out/taxonomy_standard4taxtweb.json', 'w'), + indent=4) diff --git a/django_gem_taxonomy/version.py b/django_gem_taxonomy/version.py index 4e7c72a..9e0feee 100644 --- a/django_gem_taxonomy/version.py +++ b/django_gem_taxonomy/version.py @@ -1 +1 @@ -__version__ = '1.4.3' +__version__ = '1.4.4'