Beispiel #1
0
def backupdb(settings, args):
    """
    Stores a backup copy of the SQlite3 database. Returns 0 on success, else 1.
    """
    ensure_settings(settings, args)

    from django.db import connection, transaction

    @transaction.commit_manually
    def do_backup(src_path, dest_path):
        # perform a simple file-copy backup of the database
        # first we need a shared lock on the database, issuing a select()
        # will do this for us
        cursor = connection.cursor()
        cursor.execute("SELECT count(*) from sqlite_master")
        # now copy the file
        try:
            shutil.copy(src_path, dest_path)
        except IOError:
            raise Exception("Database backup failed.")
        # and release the lock again
        transaction.commit()

    database_path = get_database_path_from_settings()
    if database_path:
        do_backup(database_path, args.path)
        print('Database %s successfully stored at %s.' %
              (database_path, args.path))
        return_value = 0
    else:
        print('Error: Default database is not SQLite3. Only SQLite3 databases '
              'can currently be backuped.')
        return_value = 1
    return return_value
Beispiel #2
0
    def handle(self, *args, **options):
        path = options.get('path')

        @transaction.atomic
        def do_backup(src_path, dest_path):
            # perform a simple file-copy backup of the database
            # first we need a shared lock on the database, issuing a select()
            # will do this for us
            cursor = connection.cursor()
            cursor.execute("SELECT count(*) from sqlite_master")
            # now copy the file
            try:
                shutil.copy(src_path, dest_path)
            except IOError:
                # TODO: use the IOError message as message for the user
                raise CommandError("Database backup failed.")

        database_path = get_database_path_from_settings()
        if database_path:
            do_backup(database_path, path)
            self.stdout.write('Database %s successfully stored at %s.' % (database_path, path))
        else:
            raise CommandError(
                'Default database is not SQLite3. Only SQLite3 databases'
                'can currently be backuped.')
Beispiel #3
0
def backupdb(settings, args):
    """
    Stores a backup copy of the SQlite3 database. Returns 0 on success, else 1.
    """
    ensure_settings(settings, args)

    from django.db import connection, transaction

    @transaction.commit_manually
    def do_backup(src_path, dest_path):
        # perform a simple file-copy backup of the database
        # first we need a shared lock on the database, issuing a select()
        # will do this for us
        cursor = connection.cursor()
        cursor.execute("SELECT count(*) from sqlite_master")
        # now copy the file
        try:
            shutil.copy(src_path, dest_path)
        except IOError:
            raise Exception("Database backup failed.")
        # and release the lock again
        transaction.commit()

    database_path = get_database_path_from_settings()
    if database_path:
        do_backup(database_path, args.path)
        print('Database %s successfully stored at %s.' % (database_path, args.path))
        return_value = 0
    else:
        print('Error: Default database is not SQLite3. Only SQLite3 databases '
              'can currently be backuped.')
        return_value = 1
    return return_value
Beispiel #4
0
    def handle_noargs(self, **options):
        path = options.get('path')

        @transaction.atomic
        def do_backup(src_path, dest_path):
            # perform a simple file-copy backup of the database
            # first we need a shared lock on the database, issuing a select()
            # will do this for us
            cursor = connection.cursor()
            cursor.execute("SELECT count(*) from sqlite_master")
            # now copy the file
            try:
                shutil.copy(src_path, dest_path)
            except IOError:
                # TODO: use the IOError message as message for the user
                raise CommandError("Database backup failed.")

        database_path = get_database_path_from_settings()
        if database_path:
            do_backup(database_path, path)
            self.stdout.write('Database %s successfully stored at %s.' %
                              (database_path, path))
        else:
            raise CommandError(
                'Default database is not SQLite3. Only SQLite3 databases'
                'can currently be backuped.')
Beispiel #5
0
def syncdb(settings, args):
    """
    Run syncdb to create or update the database.
    """
    ensure_settings(settings, args)
    # TODO: Check use of filesystem2unicode here.
    path = filesystem2unicode(os.path.dirname(get_database_path_from_settings()))
    if not os.path.exists(path):
        os.makedirs(path)
    execute_from_command_line(["", "syncdb", "--noinput"])
    return 0
Beispiel #6
0
def deletedb(settings, args):
    """
    Deletes the sqlite3 database. Returns 0 on success, else 1.
    """
    ensure_settings(settings, args)
    database_path = get_database_path_from_settings()
    if database_path and os.path.exists(database_path):
        os.remove(database_path)
        print('SQLite3 database file %s successfully deleted.' % database_path)
        return_value = 0
    else:
        print('SQLite3 database file %s does not exist.' % database_path)
        return_value = 1
    return return_value
Beispiel #7
0
def syncdb(settings, args):
    """
    Run syncdb to create or update the database.
    """
    ensure_settings(settings, args)
    # TODO: Check use of filesystem2unicode here.
    db_file = get_database_path_from_settings()
    db_dir = filesystem2unicode(os.path.dirname(db_file))
    if not os.path.exists(db_dir):
        os.makedirs(db_dir)
    if not os.path.exists(db_file):
        print('Clearing old search index...')
        execute_from_command_line(["", "clear_index", "--noinput"])
    execute_from_command_line(["", "syncdb", "--noinput"])
    return 0
Beispiel #8
0
def deletedb(settings, args):
    """
    Deletes the sqlite3 database. Returns 0 on success, else 1.
    """
    ensure_settings(settings, args)
    database_path = get_database_path_from_settings()
    if database_path and os.path.exists(database_path):
        os.remove(database_path)
        print('SQLite3 database file %s successfully deleted.' % database_path)
        execute_from_command_line(["", "clear_index", "--noinput"])
        print('Whoosh search index successfully cleared.')
        return_value = 0
    else:
        print('SQLite3 database file %s does not exist.' % database_path)
        return_value = 1
    return return_value
Beispiel #9
0
def deletedb(settings, args):
    """
    Deletes the sqlite3 database. Returns 0 on success, else 1.
    """
    ensure_settings(settings, args)
    database_path = get_database_path_from_settings()
    if database_path and os.path.exists(database_path):
        os.remove(database_path)
        print('SQLite3 database file %s successfully deleted.' % database_path)
        execute_from_command_line(["", "clear_index", "--noinput"])
        print('Whoosh search index successfully cleared.')
        return_value = 0
    else:
        print('SQLite3 database file %s does not exist.' % database_path)
        return_value = 1
    return return_value
Beispiel #10
0
def syncdb(settings, args):
    """
    Run syncdb to create or update the database.
    """
    ensure_settings(settings, args)
    db_file = get_database_path_from_settings()
    if db_file is not None:
        db_dir = os.path.dirname(db_file)
        if not os.path.exists(db_dir):
            os.makedirs(db_dir)
        if not os.path.exists(db_file):
            print('Clearing old search index...')
            execute_from_command_line(["", "clear_index", "--noinput"])
    execute_from_command_line(["", "syncdb", "--noinput"])
    if args.language:
        translate_customizable_strings(args.language)
    return 0
Beispiel #11
0
def syncdb(settings, args):
    """
    Run syncdb to create or update the database.
    """
    ensure_settings(settings, args)
    db_file = get_database_path_from_settings()
    if db_file is not None:
        db_dir = os.path.dirname(db_file)
        if not os.path.exists(db_dir):
            os.makedirs(db_dir)
        if not os.path.exists(db_file):
            print('Clearing old search index...')
            execute_from_command_line(["", "clear_index", "--noinput"])
    execute_from_command_line(["", "syncdb", "--noinput"])
    if args.language:
        translate_customizable_strings(args.language)
    return 0
Beispiel #12
0
 def test_get_database_path_from_settings_memory(self):
     self.assertEqual(get_database_path_from_settings(), ':memory:')
Beispiel #13
0
 def test_get_database_path_from_settings_memory(self):
     self.assertEqual(get_database_path_from_settings(), ':memory:')