Beispiel #1
0
    def handle(self, **options):
        # ignore_errors = options.get('ignore_errors')
        config = helpers.Config(options)
        backup_file = options.get('backup_file')
        owner = options.get('owner')

        if not backup_file or len(backup_file) == 0:
            raise CommandError("Backup archive '--backup-file' is mandatory")

        if not owner or len(owner) == 0:
            raise CommandError("Owner '--owner' is mandatory")

        message = 'WARNING: The migration may break GeoNode existing Layers. You want to proceed?'
        if helpers.confirm(prompt=message, resp=False):

            """Migrate existing Layers on GeoNode DB"""
            try:
                # Create Target Folder
                restore_folder = os.path.join(tempfile.gettempdir(), 'restore')
                if not os.path.exists(restore_folder):
                    os.makedirs(restore_folder)

                # Extract ZIP Archive to Target Folder
                target_folder = helpers.unzip_file(backup_file, restore_folder)

                # Retrieve the max Primary Key from the DB
                from geonode.base.models import ResourceBase
                try:
                    higher_pk = ResourceBase.objects.all().order_by("-id")[0].pk
                except:
                    higher_pk = 0

                # Restore Fixtures
                for app_name, dump_name in zip(config.app_names, config.dump_names):
                    for mig_name, mangler in zip(config.migrations, config.manglers):
                        if app_name == mig_name:
                            fixture_file = os.path.join(target_folder, dump_name+'.json')

                            print("Deserializing "+fixture_file)
                            mangler = helpers.load_class(mangler)
                            site_url = settings.SITEURL.rstrip('/') if settings.SITEURL.startswith('http') else settings.SITEURL
                            obj = helpers.load_fixture(app_name, fixture_file, mangler=mangler,
                                                       basepk=higher_pk, owner=owner,
                                                       datastore=settings.OGC_SERVER['default']['DATASTORE'],
                                                       siteurl=site_url)

                            from django.core import serializers

                            objects = serializers.deserialize('json', json.dumps(obj), ignorenonexistent=True)
                            for obj in objects:
                                obj.save(using=DEFAULT_DB_ALIAS)

                print("Restore finished. Please find restored files and dumps into: '"+target_folder+"'.")

            except Exception:
                traceback.print_exc()
    def handle(self, **options):
        # ignore_errors = options.get('ignore_errors')
        config = helpers.Config(options)
        backup_file = options.get('backup_file')
        owner = options.get('owner')

        if not backup_file or len(backup_file) == 0:
            raise CommandError("Backup archive '--backup-file' is mandatory")

        if not owner or len(owner) == 0:
            raise CommandError("Owner '--owner' is mandatory")

        message = 'WARNING: The migration may break GeoNode existing Layers. You want to proceed?'
        if helpers.confirm(prompt=message, resp=False):

            """Migrate existing Layers on GeoNode DB"""
            try:
                # Create Target Folder
                restore_folder = os.path.join(tempfile.gettempdir(), 'restore')
                if not os.path.exists(restore_folder):
                    os.makedirs(restore_folder)

                # Extract ZIP Archive to Target Folder
                target_folder = helpers.unzip_file(backup_file, restore_folder)

                # Retrieve the max Primary Key from the DB
                from geonode.base.models import ResourceBase
                try:
                    higher_pk = ResourceBase.objects.all().order_by("-id")[0].pk
                except:
                    higher_pk = 0

                # Restore Fixtures
                for app_name, dump_name in zip(config.app_names, config.dump_names):
                    for mig_name, mangler in zip(config.migrations, config.manglers):
                        if app_name == mig_name:
                            fixture_file = os.path.join(target_folder, dump_name+'.json')

                            print "Deserializing "+fixture_file
                            mangler = helpers.load_class(mangler)

                            obj = helpers.load_fixture(app_name, fixture_file, mangler=mangler,
                                                       basepk=higher_pk, owner=owner,
                                                       datastore=settings.OGC_SERVER['default']['DATASTORE'],
                                                       siteurl=settings.SITEURL)

                            from django.core import serializers

                            objects = serializers.deserialize('json', json.dumps(obj), ignorenonexistent=True)
                            for obj in objects:
                                obj.save(using=DEFAULT_DB_ALIAS)

                print "Restore finished. Please find restored files and dumps into: '"+target_folder+"'."

            except Exception:
                traceback.print_exc()
Beispiel #3
0
def migrate_layers(archive, owner):
    """Migrate existing Layers on GeoNode DB"""
    try:
        # Create Target Folder
        restore_folder = 'restore'
        if not os.path.exists(restore_folder):
            os.makedirs(restore_folder)

        # Extract ZIP Archive to Target Folder
        target_folder = helpers.unzip_file(archive, restore_folder)

        # Retrieve the max Primary Key from the DB
        from geonode.base.models import ResourceBase
        try:
            higher_pk = ResourceBase.objects.all().order_by("-id")[0].pk
        except:
            higher_pk = 0

        # Restore Fixtures
        for app_name, dump_name in zip(helpers.app_names, helpers.dump_names):
            for mig_name, mangler in zip(helpers.migrations, helpers.manglers):
                if app_name == mig_name:
                    fixture_file = os.path.join(target_folder,
                                                dump_name + '.json')

                    print "Deserializing " + fixture_file
                    mangler = helpers.load_class(mangler)

                    obj = helpers.load_fixture(
                        app_name,
                        fixture_file,
                        mangler=mangler,
                        basepk=higher_pk,
                        owner=owner,
                        datastore=settings.OGC_SERVER['default']['DATASTORE'],
                        siteurl=settings.SITEURL)

                    from django.core import serializers

                    objects = serializers.deserialize('json',
                                                      json.dumps(obj),
                                                      ignorenonexistent=True)
                    for obj in objects:
                        obj.save(using=DEFAULT_DB_ALIAS)

    except Exception, err:
        traceback.print_exc()
Beispiel #4
0
def migrate_layers(archive, owner):
   """Migrate existing Layers on GeoNode DB"""
   try:
      # Create Target Folder
      restore_folder = 'restore'
      if not os.path.exists(restore_folder):
         os.makedirs(restore_folder)
      
      # Extract ZIP Archive to Target Folder
      target_folder = helpers.unzip_file(archive, restore_folder)

      # Retrieve the max Primary Key from the DB
      from geonode.base.models import ResourceBase
      try:
         higher_pk = ResourceBase.objects.all().order_by("-id")[0].pk
      except:
         higher_pk = 0

      # Restore Fixtures
      for app_name, dump_name in zip(helpers.app_names, helpers.dump_names):
         for mig_name, mangler in zip(helpers.migrations, helpers.manglers):
            if app_name == mig_name:
               fixture_file = os.path.join(target_folder, dump_name+'.json')
         
               print "Deserializing "+fixture_file
               mangler = helpers.load_class(mangler)

               obj = helpers.load_fixture(app_name, fixture_file, mangler=mangler, basepk=higher_pk, owner=owner, datastore=settings.OGC_SERVER['default']['DATASTORE'], siteurl=settings.SITEURL)

               from django.core import serializers

               objects = serializers.deserialize('json', json.dumps(obj), ignorenonexistent=True)
               for obj in objects:
                  obj.save(using=DEFAULT_DB_ALIAS)

   except Exception, err:
      traceback.print_exc()