diff options
Diffstat (limited to 'ishtar_common/management/commands')
17 files changed, 118 insertions, 673 deletions
| diff --git a/ishtar_common/management/commands/clean_ishtar.py b/ishtar_common/management/commands/clean_ishtar.py deleted file mode 100644 index 3117022ee..000000000 --- a/ishtar_common/management/commands/clean_ishtar.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2017  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.core.management.base import BaseCommand - -from archaeological_operations.models import Parcel - - -class Command(BaseCommand): -    args = '' -    help = 'Clean unused items' - -    def handle(self, *args, **options): -        for parcel in Parcel.objects.all(): -            parcel.clean_orphan() -        self.stdout.write('Parcel cleaned.\n') diff --git a/ishtar_common/management/commands/fix_missing_cached_labels.py b/ishtar_common/management/commands/fix_missing_cached_labels.py deleted file mode 100644 index ad2767c56..000000000 --- a/ishtar_common/management/commands/fix_missing_cached_labels.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2013-2018 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.core.management.base import BaseCommand - -from django.apps import apps -from django.db.models import Q - - -APPS = ['ishtar_common', 'archaeological_operations', -        'archaeological_context_records', 'archaeological_finds', -        'archaeological_warehouse'] - - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate cached labels and search vectors' - -    def add_arguments(self, parser): -        parser.add_argument('app_name', nargs='?', default=None, -                            choices=APPS) -        parser.add_argument('model_name', nargs='?', default=None) -        parser.add_argument( -            '--quiet', dest='quiet', action='store_true', -            help='Quiet output') - -    def handle(self, *args, **options): -        quiet = options['quiet'] -        limit = options['app_name'] -        model_name = options['model_name'] -        if model_name: -            model_name = model_name.lower() -        for app in APPS: -            if limit and app != limit: -                continue -            if not quiet: -                print("* app: {}".format(app)) -            for model in apps.get_app_config(app).get_models(): -                if model_name and model.__name__.lower() != model_name: -                    continue -                if model.__name__.startswith('Historical'): -                    continue -                if not bool( -                        [k for k in dir(model) -                         if k.startswith('_generate_') or -                            k == "search_vector"]): -                    continue -                if hasattr(model, "CACHED_LABELS") and model.CACHED_LABELS: -                    cached_keys = model.CACHED_LABELS -                elif hasattr(model, "cached_label") \ -                            and "Basket" not in model.__name__: -                    cached_keys = ["cached_label"] -                else: -                    continue -                query = None -                for cached in cached_keys: -                    subquery = Q(**{cached + "__isnull": True}) -                    subquery |= Q(**{cached: ""}) -                    if not query: -                        query = subquery -                    else: -                        query |= subquery -                q = model.objects.filter(query) -                msg = "-> processing {}: ".format(model._meta.verbose_name) -                ln = q.count() -                for idx, obj_id in enumerate(q.values('pk').all()): -                    obj = model.objects.get(pk=obj_id['pk']) -                    obj.skip_history_when_saving = True -                    obj._no_move = True -                    obj._no_geo_check = True -                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) -                    if not quiet: -                        sys.stdout.write(cmsg) -                        sys.stdout.flush() -                    obj.save() -                if not quiet and ln: -                    sys.stdout.write("\n") diff --git a/ishtar_common/management/commands/generate_external_ids.py b/ishtar_common/management/commands/generate_external_ids.py deleted file mode 100644 index d5d3d3bed..000000000 --- a/ishtar_common/management/commands/generate_external_ids.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2017  Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.core.management.base import BaseCommand - -from archaeological_files.models import File -from archaeological_operations.models import Parcel -from archaeological_context_records.models import ContextRecord -from archaeological_finds.models import BaseFind, Find -from archaeological_warehouse.models import Warehouse, Container - - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate external ids' - -    def handle(self, *args, **options): -        for model in (File, Parcel, ContextRecord, BaseFind, Find, Warehouse, -                      Container): -            self.stdout.write('{} regenerate.\n'.format(model)) -            for obj in model.objects.all(): -                obj.skip_history_when_saving = True -                obj.save() diff --git a/ishtar_common/management/commands/ishtar_maintenance.py b/ishtar_common/management/commands/ishtar_maintenance.py index 4f050088e..d57fb575e 100644 --- a/ishtar_common/management/commands/ishtar_maintenance.py +++ b/ishtar_common/management/commands/ishtar_maintenance.py @@ -1,14 +1,18 @@ -#!/usr/bin/env python +#!/usr/bin/env python3  # -*- coding: utf-8 -*-  from argparse import RawTextHelpFormatter  import csv  import datetime  import os +import tempfile +import shutil  import sys  from django.apps import apps  from django.conf import settings +from django.contrib.auth.management import create_permissions +from django.core.exceptions import FieldDoesNotExist  from django.core.management.base import BaseCommand, CommandError  from django.template.defaultfilters import slugify @@ -28,8 +32,12 @@ if not os.path.exists(log_path):      os.mkdir(log_path, mode=0o770) -def task_update_search_vectors(quiet=False, log=False): +def task_update_search_vectors(options): +    quiet = options.get("quiet", False) +    log = options.get("log", False)      for model in apps.get_models(): +        if options.get('model', None) and model.__name__ != options['model']: +            continue          if not hasattr(model, "update_search_vector") or \                  not (getattr(model, "BASE_SEARCH_VECTORS", None) or                       getattr(model, "INT_SEARCH_VECTORS", None) or @@ -64,8 +72,12 @@ def task_update_search_vectors(quiet=False, log=False):          _end_task(changed_nb, msg, quiet, store_results, log, log_name, csv_cols) -def task_check_cached_label(quiet=False, log=False): +def task_check_cached_label(options): +    quiet = options.get("quiet", False) +    log = options.get("log", False)      for model in apps.get_models(): +        if options.get('model', None) and model.__name__ != options['model']: +            continue          if model.__name__.startswith("Historical"):              continue          if hasattr(model, "CACHED_LABELS") and model.CACHED_LABELS: @@ -116,6 +128,32 @@ def task_check_cached_label(quiet=False, log=False):          _end_task(changed_nb, msg, quiet, store_results, log, log_name, csv_cols) +def task_update_external_id(options): +    quiet = options.get("quiet", False) +    for model in apps.get_models(): +        if options.get('model', None) and model.__name__ != options['model']: +            continue +        if model.__name__.startswith("Historical"): +            continue +        if not bool( +                [k for k in dir(model) if k == "external_id"]): +            continue +        msg = "-> processing {}: ".format(model._meta.verbose_name) +        ln = model.objects.count() +        for idx, item in enumerate(model.objects.all()): +            item.skip_history_when_saving = True +            item.external_id = "" +            item.complete_identifier = "" +            item._no_move = True +            if not quiet: +                cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) +                sys.stdout.write(cmsg) +                sys.stdout.flush() +            item.save() +        if not quiet: +            sys.stdout.write("\n") + +  def _end_task(changed_nb, msg, quiet, store_results, log, log_name, csv_cols):      if not quiet:          if changed_nb: @@ -134,7 +172,8 @@ def _end_task(changed_nb, msg, quiet, store_results, log, log_name, csv_cols):              sys.stdout.write(f"log: {path} written.\n") -def task_main_image(quiet=False, log=False): +def task_main_image(options): +    quiet = options.get("quiet", False)      for model in apps.get_models():          if not issubclass(model, models_common.DocumentItem):              continue @@ -155,14 +194,44 @@ def task_main_image(quiet=False, log=False):              sys.stdout.write(f"{nb} main image fixed for {model.__name__}\n") -def task_missing_parcels(quiet=False, log=False): +def task_regenerate_qrcodes(options): +    quiet = options.get("quiet", False) +    secure = not options['no-https'] +    for model in apps.get_models(): +        if options.get('model', None) and model.__name__ != options['model']: +            continue +        try: +            model._meta.get_field('qrcode') +        except FieldDoesNotExist: +            continue +        msg = "-> processing {}: ".format(model._meta.verbose_name) +        ln = model.objects.count() +        tmpdir = tempfile.mkdtemp("-qrcode") +        for idx, obj in enumerate(model.objects.all()): +            obj.skip_history_when_saving = True +            obj._no_move = True +            if not quiet: +                cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) +                sys.stdout.write(cmsg) +                sys.stdout.flush() +            obj.generate_qrcode(secure=secure, tmpdir=tmpdir) +        shutil.rmtree(tmpdir) +        if not quiet: +            sys.stdout.write("\n") + + +def task_regenerate_permissions(options): +    for app in ['ishtar_common', 'archaeological_operations', +                'archaeological_context_records', +                'archaeological_finds', 'archaeological_warehouse']: +        create_permissions(apps.get_app_config(app)) + + +def task_missing_parcels(options): +    quiet = options.get("quiet", False)      Parcel = apps.get_model("archaeological_operations", "Parcel")      q = Parcel.objects.filter(context_record__isnull=False, operation=None)      nb = q.count() -    if not nb: -        if not quiet: -            sys.stdout.write("No parcel to fix.\n") -            return      for idx, parcel in enumerate(q.all()):          if not quiet:              sys.stdout.write(f"\r[{percent(idx, nb)}] {idx + 1}/{nb}") @@ -175,6 +244,13 @@ def task_missing_parcels(quiet=False, log=False):          parcel.save()      if not quiet:          sys.stdout.write("\n") +    if not options.get("clean", False): +        return +    q = Parcel.objects.filter(associated_file=None, operation=None) +    nb = q.count() +    q.delete() +    if not quiet: +        sys.stdout.write(f"{nb} orphan parcel deleted.\n")  def percent(current, total): @@ -186,21 +262,34 @@ def get_time():  TASKS = { -    "main_image": { +    "fix_main_image": {          "help": "for items with images and no main image, put the first one created as a main image",          "action": task_main_image,      }, -    "cached_label": { -        "help": "regenerate cached label on all tables", +    "fix_missing_parcels": { +        "help": "fix lost parcel association on operation from context records. " +                "With --clean option delete orphan parcels.", +        "action": task_missing_parcels, +    }, +    "update_cached_label": { +        "help": "regenerate cached label",          "action": task_check_cached_label,      }, +    "update_permissions": { +        "help": "regenerate basic model permissions", +        "action": task_regenerate_permissions, +    }, +    "update_qrcodes": { +        "help": "regenerate qrcodes", +        "action": task_regenerate_qrcodes, +    },      "update_search_vector": { -        "help": "regenerate search vectors on all tables", +        "help": "regenerate search vectors",          "action": task_update_search_vectors,      }, -    "operation_missing_parcels": { -        "help": "fix lost parcel association on operation from context records.", -        "action": task_missing_parcels, +    "update_external_ids": { +        "help": "regenerate external and complete ID", +        "action": task_update_external_id,      },  } @@ -226,22 +315,32 @@ class Command(BaseCommand):          )          parser.add_argument("task", help=task_help)          parser.add_argument( +            '--model', type=str, default='', dest='model', +            help='Specific model to update') +        parser.add_argument(              "--quiet", dest="quiet", action="store_true", help="Quiet output"          )          parser.add_argument(              "--log", dest="log", action="store_true", help="Log into a file"          ) +        parser.add_argument( +            '--no-https', dest='no-https', action='store_true', +            default=False, +            help="[update_qrcodes] Use this parameter if https is not available") +        parser.add_argument( +            '--clean', dest='clean', action='store_true', +            default=False, +            help="[operation_missing_parcels] Delete orphan parcel after fix")      def handle(self, *args, **options):          if options["task"] not in TASKS.keys():              msg = f"{options['task']} is not a valid task. Available tasks are:\n"              msg += "\n".join(TASKS.keys())              raise CommandError(msg) -        log = options["log"]          quiet = options["quiet"]          if not quiet:              sys.stdout.write(f"[{get_time()}] Processing task {options['task']}\n") -        errors = TASKS[options["task"]]["action"](quiet=quiet, log=log) +        errors = TASKS[options["task"]]["action"](options)          if not errors:              if not quiet:                  sys.stdout.write(f"[{get_time()}] Task {options['task']} finished\n") diff --git a/ishtar_common/management/commands/ishtar_migrate_odts.py b/ishtar_common/management/commands/ishtar_migrate_odts.py deleted file mode 100644 index fe7836f0d..000000000 --- a/ishtar_common/management/commands/ishtar_migrate_odts.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2017  Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -from django.core.management.base import BaseCommand -from optparse import make_option -import sys - -from ishtar_common.models import DocumentTemplate -from ishtar_common.utils import BColors - - -class Command(BaseCommand): -    help = "Update ODT templates from v1 to v2" -    option_list = BaseCommand.option_list + ( -        make_option('--quiet', -                    action='store_true', -                    dest='quiet', -                    default=False, -                    help='Proceed silently with no interactive input.'), -    ) - -    def interactive_start(self): -        sys.stdout.write( -            BColors.HEADER + BColors.BOLD + -            "Update ODT templates from v1 to v2\n") -        sys.stdout.write( -            BColors.ENDC + BColors.WARNING + -            "This script need to be run only once. Running it on already " -            "migrated ODT files may be a source of error.\n") -        sys.stdout.write(BColors.ENDC) -        yes = None -        while yes != "yes": -            sys.stdout.write( -                "Are you sure you want to proceed? (yes/[n])\n") -            yes = input() -            if not yes or yes == "n": -                sys.stdout.write(BColors.FAIL + "Aborting\n") -                sys.stdout.write(BColors.ENDC) -                sys.exit() - -    def handle(self, *args, **options): -        quiet = options['quiet'] -        if not quiet: -            self.interactive_start() -        q = DocumentTemplate.objects -        nb = q.count() -        len_of_nb = str(len(str(nb))) -        if not quiet: -            sys.stdout.write(BColors.OKGREEN) - -        errors = [] -        for idx, document in enumerate(q.all()): -            if not quiet: -                sys.stdout.write( -                    ("Processing {:" + len_of_nb + "d}/{}\r").format( -                        idx + 1, nb)) -                sys.stdout.flush() -                try: -                    document.convert_from_v1() -                except IOError as e: -                    errors.append("Document ({}): ".format(document.pk) + -                                  str(e)) -        if errors: -            sys.stdout.write(BColors.FAIL + "Error while processing:\n") -            for error in errors: -                sys.stdout.write("* {}\n".format(error)) - -        sys.stdout.write(BColors.ENDC) -        print("\n\n") - diff --git a/ishtar_common/management/commands/load_towns.py b/ishtar_common/management/commands/load_towns.py deleted file mode 100644 index 00a1b8477..000000000 --- a/ishtar_common/management/commands/load_towns.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import csv -import datetime, time - -from django.conf import settings -from django.core.management.base import BaseCommand, CommandError - -from ishtar_common import tasks - -class Command(BaseCommand): -    help = "Load french towns" - -    def handle(self, *args, **options): -        self.stdout.write("* Loading towns\n") -        self.stdout.flush() -        created, updated = tasks.load_towns() -        self.stdout.write("%d towns created, %s towns updated\n\n" % (created, -                                                                      updated)) -        self.stdout.flush() - diff --git a/ishtar_common/management/commands/relations_update_cache_tables.py b/ishtar_common/management/commands/migrate_relations_cache_tables.py index 3e2dfaef5..3e2dfaef5 100644 --- a/ishtar_common/management/commands/relations_update_cache_tables.py +++ b/ishtar_common/management/commands/migrate_relations_cache_tables.py diff --git a/ishtar_common/management/commands/ishtar_migrate_srid.py b/ishtar_common/management/commands/migrate_srid.py index 19de96cb8..19de96cb8 100644 --- a/ishtar_common/management/commands/ishtar_migrate_srid.py +++ b/ishtar_common/management/commands/migrate_srid.py diff --git a/ishtar_common/management/commands/generate_merge_candidates.py b/ishtar_common/management/commands/process_generate_merge_candidates.py index 106ce8e13..106ce8e13 100644 --- a/ishtar_common/management/commands/generate_merge_candidates.py +++ b/ishtar_common/management/commands/process_generate_merge_candidates.py diff --git a/ishtar_common/management/commands/reassociate_similar_images.py b/ishtar_common/management/commands/process_reassociate_similar_images.py index 9e52bc6f6..3070650b8 100644 --- a/ishtar_common/management/commands/reassociate_similar_images.py +++ b/ishtar_common/management/commands/process_reassociate_similar_images.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3  # -*- coding: utf-8 -*-  import csv @@ -220,13 +220,3 @@ class Command(BaseCommand):                                                              filename))          if not quiet:              out.write("* {} distinct images\n".format(distinct_image)) - - - - - - - - - - diff --git a/ishtar_common/management/commands/regenerate_external_id.py b/ishtar_common/management/commands/regenerate_external_id.py deleted file mode 100644 index 9691cba27..000000000 --- a/ishtar_common/management/commands/regenerate_external_id.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2013-2018 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.core.management.base import BaseCommand, CommandError - -from django.apps import apps - - -class Command(BaseCommand): -    help = 'Regenerate external id and complete_identifier.' - -    def add_arguments(self, parser): -        parser.add_argument('model', nargs='+') - -    def handle(self, *args, **options): -        for app_model_name in options['model']: -            try: -                capp, model_name = app_model_name.split(".") -            except ValueError: -                raise CommandError( -                    "Model argument must be \"app_name.model_name\". Example: " -                    "archaeological_operations.Operation" -                ) -            ok = False -            for app in ['ishtar_common', 'archaeological_operations', -                        'archaeological_context_records', -                        'archaeological_finds', 'archaeological_warehouse']: -                if capp != app: -                    continue -                for model in apps.get_app_config(app).get_models(): -                    if model.__name__ != model_name: -                        continue -                    if not bool( -                            [k for k in dir(model) if k == "external_id"]): -                        continue -                    msg = "* processing {} - {}:".format( -                        app, model._meta.verbose_name) -                    ln = model.objects.count() -                    for idx, item in enumerate(model.objects.all()): -                        item.skip_history_when_saving = True -                        item.external_id = "" -                        item.complete_identifier = "" -                        item._no_move = True -                        cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) -                        sys.stdout.write(cmsg) -                        sys.stdout.flush() -                        item.save() -                    sys.stdout.write("\n") -                    ok = True -                if not ok: -                    raise CommandError( -                        "{} not found or have no external ID".format( -                            app_model_name)) diff --git a/ishtar_common/management/commands/regenerate_permissions.py b/ishtar_common/management/commands/regenerate_permissions.py deleted file mode 100644 index 9cd8b2277..000000000 --- a/ishtar_common/management/commands/regenerate_permissions.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2013-2017 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - - -from django.core.management.base import BaseCommand - -from django.contrib.auth.management import create_permissions -from django.apps import apps - - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate permissions' - -    def handle(self, *args, **options): -        for app in ['ishtar_common', 'archaeological_operations', -                    'archaeological_context_records', -                    'archaeological_finds', 'archaeological_warehouse']: -            create_permissions(apps.get_app_config(app)) diff --git a/ishtar_common/management/commands/regenerate_qrcodes.py b/ishtar_common/management/commands/regenerate_qrcodes.py deleted file mode 100644 index d915d2e21..000000000 --- a/ishtar_common/management/commands/regenerate_qrcodes.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2019 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys -import tempfile -import shutil - -from django.core.management.base import BaseCommand -from django.core.exceptions import FieldDoesNotExist - -from django.apps import apps - - -APPS = ['ishtar_common', 'archaeological_operations', -        'archaeological_context_records', 'archaeological_finds', -        'archaeological_warehouse'] - - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate QR codes' - -    def add_arguments(self, parser): -        parser.add_argument('app_name', nargs='?', default=None, -                            choices=APPS) -        parser.add_argument('model_name', nargs='?', default=None) -        parser.add_argument( -            '--no-https', dest='no-https', action='store_true', -            default=False, -            help='Use this parameter if https is not available.') - -    def handle(self, *args, **options): -        limit = options['app_name'] -        model_name = options['model_name'] -        secure = not options['no-https'] -        if model_name: -            model_name = model_name.lower() -        for app in APPS: -            if limit and app != limit: -                continue -            print("* app: {}".format(app)) -            for model in apps.get_app_config(app).get_models(): -                if model_name and model.__name__.lower() != model_name: -                    continue -                if model.__name__.startswith('Historical'): -                    continue -                try: -                    model._meta.get_field('qrcode') -                except FieldDoesNotExist: -                    continue -                msg = "-> processing {}: ".format(model._meta.verbose_name) -                ln = model.objects.count() -                tmpdir = tempfile.mkdtemp("-qrcode") -                for idx, object in enumerate(model.objects.all()): -                    object.skip_history_when_saving = True -                    object._no_move = True -                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) -                    sys.stdout.write(cmsg) -                    sys.stdout.flush() -                    object.generate_qrcode(secure=secure, tmpdir=tmpdir) -                shutil.rmtree(tmpdir) -                sys.stdout.write("\n") diff --git a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py b/ishtar_common/management/commands/regenerate_search_vector_cached_label.py deleted file mode 100644 index 1b9dd24d1..000000000 --- a/ishtar_common/management/commands/regenerate_search_vector_cached_label.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# Copyright (C) 2013-2018 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> - -# This program 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. - -# This program 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 <http://www.gnu.org/licenses/>. - -# See the file COPYING for details. - -import sys - -from django.core.management.base import BaseCommand - -from django.apps import apps - - -APPS = ['ishtar_common', 'archaeological_operations', -        'archaeological_context_records', 'archaeological_finds', -        'archaeological_warehouse'] - - -class Command(BaseCommand): -    args = '' -    help = 'Regenerate geo, cached labels and search vectors' - -    def add_arguments(self, parser): -        parser.add_argument('app_name', nargs='?', default=None, -                            choices=APPS) -        parser.add_argument('model_name', nargs='?', default=None) -        parser.add_argument( -            '--quiet', dest='quiet', action='store_true', -            help='Quiet output') - -    def handle(self, *args, **options): -        quiet = options['quiet'] -        limit = options['app_name'] -        model_name = options['model_name'] -        if model_name: -            model_name = model_name.lower() -        for app in APPS: -            if limit and app != limit: -                continue -            if not quiet: -                print("* app: {}".format(app)) -            for model in apps.get_app_config(app).get_models(): -                if model_name and model.__name__.lower() != model_name: -                    continue -                if model.__name__.startswith('Historical'): -                    continue -                if not bool( -                        [k for k in dir(model) -                         if k.startswith('_generate_') or -                            k == "search_vector"]): -                    continue -                msg = "-> processing {}: ".format(model._meta.verbose_name) -                ln = model.objects.count() -                for idx, obj_id in enumerate(model.objects.values('pk').all()): -                    obj = model.objects.get(pk=obj_id['pk']) -                    obj.skip_history_when_saving = True -                    obj._no_move = True -                    cmsg = "\r{} {}/{}".format(msg, idx + 1, ln) -                    if not quiet: -                        sys.stdout.write(cmsg) -                        sys.stdout.flush() -                    obj.save() -                if not quiet: -                    sys.stdout.write("\n") diff --git a/ishtar_common/management/commands/update_external_ids.py b/ishtar_common/management/commands/update_external_ids.py deleted file mode 100644 index f69a865d7..000000000 --- a/ishtar_common/management/commands/update_external_ids.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys - -from django.core.management.base import BaseCommand - -from archaeological_operations.models import Parcel -from archaeological_context_records.models import ContextRecord -from archaeological_finds.models import BaseFind, Find - - -class Command(BaseCommand): -    help = "./manage.py ishtar_execute_admin_tasks\n\n"\ -           "Launch pending administration tasks." - -    def handle(self, *args, **options): -        for model in [Parcel, ContextRecord, BaseFind, Find]: -            updated = 0 -            print("* {}".format(model)) -            total = model.objects.count() -            for idx, item in enumerate(model.objects.all()): -                sys.stdout.write("\r{}/{} ".format(idx, total)) -                sys.stdout.flush() -                updated += 1 if item.update_external_id(save=True) else 0 -            print("\rupdated: {}     ".format(updated)) diff --git a/ishtar_common/management/commands/update_search_vectors.py b/ishtar_common/management/commands/update_search_vectors.py deleted file mode 100644 index a07da721e..000000000 --- a/ishtar_common/management/commands/update_search_vectors.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import sys - -from django.core.management.base import BaseCommand -import django.apps - - -class Command(BaseCommand): -    help = "./manage.py update_search_vectors\n\n"\ -           "Update full texte search vectors." - -    def add_arguments(self, parser): -        parser.add_argument( -            '--model', type=str, default='', dest='model', -            help='Specific model to update') -        parser.add_argument( -            '--quiet', dest='quiet', action='store_true', -            help='Quiet output') - -    def handle(self, *args, **options): -        quiet = options['quiet'] -        nb_total = 0 -        for model in django.apps.apps.get_models(): -            if options['model'] and model.__name__ != options['model']: -                continue -            if hasattr(model, "update_search_vector") and \ -                    (getattr(model, "BASE_SEARCH_VECTORS", None) or -                     getattr(model, "INT_SEARCH_VECTORS", None) or -                     getattr(model, "M2M_SEARCH_VECTORS", None) or -                     getattr(model, "PARENT_SEARCH_VECTORS", None)): -                if not quiet: -                    self.stdout.write("\n* update {}".format(model)) -                total = model.objects.count() -                idx = 0 -                for idx, item in enumerate(model.objects.all()): -                    if not quiet: -                        sys.stdout.write("\r{}/{} ".format(idx + 1, total)) -                        sys.stdout.flush() -                    try: -                        item.update_search_vector() -                    except: -                        pass -                nb_total += idx -        if not quiet: -            self.stdout.write("\n") -        self.stdout.write("{} items updated\n".format(nb_total)) diff --git a/ishtar_common/management/commands/update_specific_importers.py b/ishtar_common/management/commands/update_specific_importers.py deleted file mode 100644 index 9a13e3f3e..000000000 --- a/ishtar_common/management/commands/update_specific_importers.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from optparse import make_option - -from django.core.management.base import BaseCommand - -IMPORTERS = [] - -from archaeological_files.data_importer import FileImporterSraPdL -IMPORTERS.append(FileImporterSraPdL) - - -class Command(BaseCommand): -    help = "Update each specific importer" -    option_list = list(BaseCommand.option_list) + [ -        make_option( -            '--force', -            action='store_true', -            dest='force', -            default=False, -            help='Force the deletion of existing importers. ' -                 'ATTENTION: all associated imports and all associated items ' -                 'will be deleted.')] - -    def handle(self, *args, **options): -        for importer in IMPORTERS: -            response = importer()._create_models(force=options['force']) -            if response: -                self.stdout.write("%s configured\n" % importer.__name__) -                self.stdout.flush() | 
