Exemplo n.º 1
0
def load_stats_data(apps, schema_editor):
    AddrObj = apps.get_model('fias', 'AddrObj')

    if AddrObj.objects.count():
        from fias.importer.version import fetch_version_info
        from fias.importer.commands import load_complete_data
        fetch_version_info(update_all=True)
        load_complete_data(path=None, truncate=True, tables=TABLES_STATS)
Exemplo n.º 2
0
    def handle(self, *args, **options):
        ver = options.pop('version')
        print(args)
        fetch = options.pop('update-version-info')
        if fetch == 'yes':
            fetch_version_info(update_all=True)

        if ver:
            latest_version = Version.objects.all().latest('dumpdate')
            print('Latest version: {0}'.format(latest_version))
            statuses = dict((s.table, s) for s in Status.objects.select_related('ver').all())
            for table in TABLES:
                ver = statuses[table].ver.ver if table in statuses else 0
                print('Table: {0}, version: {1}, actual: {2}'.format(
                    table,
                    ver if ver else 'unknown',
                    'No' if ver < latest_version.ver else 'Yes'
                ))
Exemplo n.º 3
0
    def handle(self, *args, **options):
        ver = options.pop('version')
        print(args)
        fetch = options.pop('update-version-info')
        if fetch == 'yes':
            fetch_version_info(update_all=True)

        if ver:
            latest_version = Version.objects.all().latest('dumpdate')
            print('Latest version: {0}'.format(latest_version))
            statuses = dict(
                (s.table, s)
                for s in Status.objects.select_related('ver').all())
            for table in TABLES:
                ver = statuses[table].ver.ver if table in statuses else 0
                print('Table: {0}, version: {1}, actual: {2}'.format(
                    table, ver if ver else 'unknown',
                    'No' if ver < latest_version.ver else 'Yes'))
Exemplo n.º 4
0
    def handle(self, *args, **options):
        remote = options.pop('remote')
        force = options.pop('force')
        really = options.pop('really')
        update = options.pop('update')
        skip = options.pop('skip')
        weights = options.pop('weights')

        path = options.pop('file') if not remote else None

        if path is None and not remote and not update and not weights:
            self.error(self.usage_str)

        if (path or remote) and Status.objects.count() > 0 and not really:
            self.error('One of the tables contains data. Truncate all FIAS tables manually '
                       'or enter key --really-replace, to clear the table by means of Django ORM')

        truncate = False
        fetch_version_info(update_all=True)

        # Force Russian language for internationalized projects
        if settings.USE_I18N:
            activate('ru')

        if path or remote:
            if force:
                truncate = True
                Status.objects.all().delete()
            load_complete_xml(path=path, truncate=truncate)

        if update:
            print ('Database updating...')
            load_delta_xml(skip=skip)

        if weights:
            print ('Rewriting weights')
            rewrite_weights()
Exemplo n.º 5
0
 def setUp(self):
     fetch_version_info(update_all=True)
     self._archive = Archive(path=test_archive)
Exemplo n.º 6
0
 def setUp(self):
     fetch_version_info(update_all=True)
     self._archive = Archive(path=test_archive)
Exemplo n.º 7
0
    def handle(self, *args, **options):
        from fias.importer.timer import Timer
        Timer.init()

        src = options.pop('src')
        remote = False
        if src and src.lower() == 'auto':
            src = None
            remote = True

        truncate = options.pop('truncate')
        doit = options.pop('doit')

        update = options.pop('update')
        skip = options.pop('skip')

        weights = options.pop('weights')

        if not any([src, remote, update, weights]):
            self.error(self.usage_str)

        tempdir = options.pop('tempdir')
        if tempdir:
            if not os.path.exists(tempdir):
                self.error('Directory `{0}` does not exists.'.format(tempdir))
            elif not os.path.isdir(tempdir):
                self.error('Path `{0}` is not a directory.'.format(tempdir))
            elif not os.access(tempdir, os.W_OK):
                self.error('Directory `{0}` is not writeable'.format(tempdir))

        # TODO: какая-то нелогичная логика получилась. Надо бы поправить.
        if (src or remote) and Status.objects.count() > 0 and not doit:
            self.error(
                'One of the tables contains data. Truncate all FIAS tables manually '
                'or enter key --i-know-what-i-do, to clear the table by means of Django ORM'
            )

        fetch = options.pop('update-version-info')
        if fetch == 'yes':
            fetch_version_info(update_all=True)

        # Force Russian language for internationalized projects
        if settings.USE_I18N:
            activate('ru')

        fmt = options.pop('format')
        limit = int(options.pop('limit'))
        tables = options.pop('tables')
        tables = set(tables.split(',')) if tables else set()

        keep_indexes = options.pop('keep_indexes')

        if not tables.issubset(set(TABLES)):
            diff = ', '.join(tables.difference(TABLES))
            self.error(
                'Tables `{0}` are not listed in the FIAS_TABLES and can not be processed'
                .format(diff))
        tables = tuple(x for x in TABLES if x in list(tables))

        if src or remote:

            try:
                load_complete_data(
                    path=src,
                    data_format=fmt,
                    truncate=truncate,
                    limit=limit,
                    tables=tables,
                    keep_indexes=keep_indexes,
                    tempdir=tempdir,
                )
            except TableListLoadingError as e:
                self.error(str(e))

        if update:

            try:
                auto_update_data(skip=skip,
                                 data_format=fmt,
                                 limit=limit,
                                 tables=tables,
                                 tempdir=tempdir)
            except TableListLoadingError as e:
                self.error(str(e))

        if weights:
            rewrite_weights()
Exemplo n.º 8
0
    def handle(self, *args, **options):
        from fias.importer.timer import Timer
        Timer.init()

        src = options.pop('src')
        remote = False
        if src and src.lower() == 'auto':
            src = None
            remote = True

        truncate = options.pop('truncate')
        doit = options.pop('doit')

        update = options.pop('update')
        skip = options.pop('skip')

        weights = options.pop('weights')

        if not any([src, remote, update, weights]):
            self.error(self.usage_str)

        tempdir = options.pop('tempdir')
        if tempdir:
            if not os.path.exists(tempdir):
                self.error('Directory `{0}` does not exists.'.format(tempdir))
            elif not os.path.isdir(tempdir):
                self.error('Path `{0}` is not a directory.'.format(tempdir))
            elif not os.access(tempdir, os.W_OK):
                self.error('Directory `{0}` is not writeable'.format(tempdir))

        # TODO: какая-то нелогичная логика получилась. Надо бы поправить.
        if (src or remote) and Status.objects.count() > 0 and not doit:
            self.error('One of the tables contains data. Truncate all FIAS tables manually '
                       'or enter key --i-know-what-i-do, to clear the table by means of Django ORM')

        fetch = options.pop('update-version-info')
        if fetch == 'yes':
            fetch_version_info(update_all=True)

        # Force Russian language for internationalized projects
        if settings.USE_I18N:
            activate('ru')

        fmt = options.pop('format')
        limit = int(options.pop('limit'))
        tables = options.pop('tables')
        tables = set(tables.split(',')) if tables else set()

        keep_indexes = options.pop('keep_indexes')

        if not tables.issubset(set(TABLES)):
            diff = ', '.join(tables.difference(TABLES))
            self.error('Tables `{0}` are not listed in the FIAS_TABLES and can not be processed'.format(diff))
        tables = tuple(x for x in TABLES if x in list(tables))

        if src or remote:

            try:
                load_complete_data(
                    path=src, data_format=fmt, truncate=truncate,
                    limit=limit, tables=tables, keep_indexes=keep_indexes,
                    tempdir=tempdir,
                )
            except TableListLoadingError as e:
                self.error(str(e))

        if update:

            try:
                auto_update_data(skip=skip, data_format=fmt, limit=limit, tables=tables, tempdir=tempdir)
            except TableListLoadingError as e:
                self.error(str(e))

        if weights:
            rewrite_weights()
def load_stats_data(apps, schema_editor):
    AddrObj = apps.get_model('fias', 'AddrObj')

    if AddrObj.objects.count():
        fetch_version_info(update_all=True)
        load_complete_data(path=None, truncate=True, tables=TABLES_STATS)