Exemple #1
0
def run():
    cli = CLI()
    try:
        (options, args) = cli.parse()

        if options.simple_db_migrate_version:
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            cli.info_and_exit(msg)

        if options.show_colors:
            CLI.show_colors()

        # Create config
        config = FileConfig(options.config_file, options.environment)
        config.put('schema_version', options.schema_version)
        config.put('show_sql', options.show_sql)
        config.put('show_sql_only', options.show_sql_only)
        config.put('new_migration', options.new_migration)
        config.put('drop_db_first', options.drop_db_first)
        config.put('paused_mode', options.paused_mode)
        config.put('log_dir', options.log_dir)
        config.put('label_version', options.label_version)
        config.put('force_use_files_on_down', options.force_use_files_on_down)
        config.put('force_execute_old_migrations_versions',
                   options.force_execute_old_migrations_versions)

        # paused mode forces log_level to 2
        log_level = int(options.log_level)
        if options.paused_mode:
            log_level = 2

        config.put('log_level', log_level)

        # Ask the password for user if configured
        if config.get('db_password') == '<<ask_me>>':
            if options.password:
                passwd = options.password
            else:
                cli.msg(
                    '\nPlease inform password to connect to database "%s@%s:%s"'
                    % (config.get('db_user'), config.get('db_host'),
                       config.get('db_name')))
                passwd = getpass()
            config.remove('db_password')
            config.put('db_password', passwd)

        # If CLI was correctly parsed, execute db-migrate.
        Main(config).execute()
    except KeyboardInterrupt:
        cli.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        cli.error_and_exit(str(e))
Exemple #2
0
def run():
    cli = CLI()
    try:
        (options, args) = cli.parse()

        if options.simple_db_migrate_version:
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            cli.info_and_exit(msg)

        if options.show_colors:
            CLI.show_colors()

        # Create config
        config = FileConfig(options.config_file, options.environment)
        config.put('schema_version', options.schema_version)
        config.put('show_sql', options.show_sql)
        config.put('show_sql_only', options.show_sql_only)
        config.put('new_migration', options.new_migration)
        config.put('drop_db_first', options.drop_db_first)
        config.put('paused_mode', options.paused_mode)
        config.put('log_dir', options.log_dir)
        config.put('label_version', options.label_version)
        config.put('force_use_files_on_down', options.force_use_files_on_down)
        config.put('force_execute_old_migrations_versions', options.force_execute_old_migrations_versions)

        # paused mode forces log_level to 2
        log_level = int(options.log_level)
        if options.paused_mode:
            log_level = 2

        config.put('log_level', log_level)

        # Ask the password for user if configured
        if config.get('db_password') == '<<ask_me>>':
            if options.password:
                passwd = options.password
            else:
                cli.msg('\nPlease inform password to connect to database "%s@%s:%s"' % (config.get('db_user'), config.get('db_host'), config.get('db_name')))
                passwd = getpass()
            config.remove('db_password')
            config.put('db_password', passwd)

        # If CLI was correctly parsed, execute db-migrate.
        Main(config).execute()
    except KeyboardInterrupt:
        cli.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        cli.error_and_exit(str(e))
Exemple #3
0
def run():
    cli = CLI()
    try:
        (options, args) = cli.parse()

        if options.torneira_version:
            msg = "torneira v%s" % torneira.__version__
            cli.info_and_exit(msg)

        if options.show_colors:
            CLI.show_colors()

        Main().excecute()

    except KeyboardInterrupt:
        cli.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        cli.error_and_exit(str(e))
Exemple #4
0
def run():
    cli = CLI()
    (options, args) = cli.parse()

    if options.enable_colors:
        cli.enable_colors()

    try:
        main = Main(cli, options, args)
        if options.print_version:
            main.print_version()
        else:
            main.start()
    except KeyboardInterrupt:
        cli.print_info("\nExecution interrupted by user")
        sys.exit(2)

    sys.exit(0)
Exemple #5
0
def run():
    cli = CLI()
    (options, args) = cli.parse()

    if options.enable_colors:
        cli.enable_colors()

    try:
        main = Main(cli, options, args)
        if options.print_version:
            main.print_version()
        else:
            main.start()
    except KeyboardInterrupt:
        cli.print_info("\nExecution interrupted by user")
        sys.exit(2)

    sys.exit(0)
Exemple #6
0
class Main(object):
    def __init__(self):
        self.cli = CLI()

    def start(self, options, args):

        # set path
        sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(options.settings_file)), ".."))
        sys.path.insert(0, os.path.dirname(os.path.abspath(options.settings_file)))

        # set setting
        exec("import %s as settings" % os.path.splitext(os.path.basename(options.settings_file))[0])
        torneira.settings = settings

        from torneira.core.server import TorneiraServer

        server = TorneiraServer(
            pidfile=options.pidfile,
            port=options.port,
            media_dir=os.path.abspath(options.media_dir),
            xheaders=options.xheaders,
        )

        if options.daemon:
            if args[0] == "start":
                server.start()

            elif args[0] == "stop":
                server.stop()

            elif args[0] == "restart":
                server.restart()
        else:
            server.run()

    def excecute(self):

        (options, args) = self.cli.parse()

        if args and args[0] in ("start", "stop", "restart"):
            try:
                self.start(options, args)
            except Exception, e:
                traceback.print_exc(file=sys.stderr)
def run_from_argv(args=None):
    (options, _) = CLI.parse(args)
    run(options.__dict__)
def run_from_argv(args=sys.argv[1:]):
    if not args:
        args = ["-h"]
    (options, _) = CLI.parse(args)
    run(options.__dict__)
def run_from_argv(args=None):
    (options, _) = CLI.parse(args)
    run(options.__dict__)