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
def start(settings, args): """ Starts OpenSlides: Runs syncdb and runs runserver (tornado webserver). """ ensure_settings(settings, args) syncdb(settings, args) args.start_browser = not args.no_browser runserver(settings, args)
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
def createsuperuser(settings, args): """ Creates or resets the admin user. Returns 0 to show success. """ ensure_settings(settings, args) # can't be imported in global scope as it already requires # the settings module during import from openslides.participant.api import create_or_reset_admin_user if create_or_reset_admin_user(): print('Admin user successfully created.') else: print('Admin user successfully reset.') return 0
def createsuperuser(settings, args): """ Creates or resets the admin user. Returns 0 to show success. """ ensure_settings(settings, args) # can't be imported in global scope as it already requires # the settings module during import from openslides.users.api import create_or_reset_admin_user if create_or_reset_admin_user(): print('Admin user successfully created.') else: print('Admin user successfully reset.') return 0
def runserver(settings, args): """ Runs tornado webserver. Runs the function start_browser if the respective argument is given. """ ensure_settings(settings, args) port = get_port(address=args.address, port=args.port) if args.start_browser: browser_url = get_browser_url(address=args.address, port=port) start_browser(browser_url) # Now the settings is available and the function can be imported. from openslides.utils.tornado_webserver import run_tornado run_tornado(args.address, port, not args.no_reload)
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
def runserver(settings, args): """ Runs tornado webserver. Runs the function start_browser if the respective argument is given. """ ensure_settings(settings, args) port = get_port(address=args.address, port=args.port) if args.start_browser: browser_url = get_browser_url(address=args.address, port=port) start_browser(browser_url) # Now the settings is available and the function can be imported. from openslides.utils.tornado_webserver import run_tornado run_tornado(args.address, port)
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
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
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
def django_command_line_utility(settings, args): """ Runs Django's command line utility. Returns 0 on success, else 1. """ if 'runserver' in args.django_args: command = 'runserver' elif 'syncdb' in args.django_args: command = 'syncdb' elif 'createsuperuser' in args.django_args: command = 'createsuperuser' else: command = None if command: print("Error: The command '%s' is disabled in OpenSlides for use via Django's " "command line utility." % command) return_value = 1 else: ensure_settings(settings, args) execute_from_command_line(args.django_args) return_value = 0 return return_value
def django_command_line_utility(settings, args): """ Runs Django's command line utility. Returns 0 on success, else 1. """ if 'runserver' in args.django_args: command = 'runserver' elif 'syncdb' in args.django_args: command = 'syncdb' elif 'createsuperuser' in args.django_args: command = 'createsuperuser' else: command = None if command: print( "Error: The command '%s' is disabled in OpenSlides for use via Django's " "command line utility." % command) return_value = 1 else: ensure_settings(settings, args) execute_from_command_line(args.django_args) return_value = 0 return return_value