Ejemplo n.º 1
0
    def __init__(self):
        config = FileConfig()
        config.load_yaml()
        self.modules_path = config.settings["METASPLOIT"]["MODULE_PATH"]

        db_init = DBInit()
        db_init.create()
        self.msf_dao = MsfDAO(db_init.session)
        self.modules_path_list = []
Ejemplo n.º 2
0
    def __init__(self, section_name: str = 'DB'):
        self.db = None

        config = FileConfig()

        try:
            self.db = connect(host=config.get(f'{section_name}.host'),
                              user=config.get(f'{section_name}.user'),
                              passwd=config.get(f'{section_name}.pass'),
                              database=config.get(f'{section_name}.name'))
        except ProgrammingError as e:
            print(f'[DB] [ERROR] {e.msg}')
            raise e
Ejemplo n.º 3
0
    def __init__(self):
        config = FileConfig()
        config.load_yaml()
        self.github_api = config.settings["GITHUB_TOKEN"]

        db_init = DBInit()
        db_init.create()
        self.msf_dao = MsfDAO(db_init.session)

        self.session = requests_html.HTMLSession()
        self.session.keep_alive = False
        self.headers = {
            'user-agent':
            'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36',
        }
Ejemplo n.º 4
0
    def calculate(penter: Plato,
                  pexit: Plato,
                  denter: StockDataFrame,
                  dexit: StockDataFrame,
                  begin,
                  end,
                  force=None):
        ts = time()
        penter.calculateAll(denter.copy(deep=True))
        pexit.calculateAll(dexit.copy(deep=True))

        statistics = Statistics(begin, end).calculate(penter, pexit)

        del penter.adviseData
        del pexit.adviseData
        del denter
        del dexit

        skip_negative = FileConfig().get('CALC.SKIP_NEGATIVE', True, bool)
        if force == True:
            skip_negative = False

        if skip_negative:
            isPositive = False
            for period in statistics:
                if statistics[period]['total'] > 0:
                    isPositive = True
                    break
        else:
            isPositive = True

        return (penter, pexit, begin, end, statistics if isPositive else None,
                time() - ts)
Ejemplo n.º 5
0
    def include_heuristics(filename, platform, error):
        """Try to find missing includes from error message."""
        include = None
        msg = str(error)
        if "before: " in msg:
            key = msg.rsplit("before: ", 1)[1].strip()
            include = cparser.StructVisitor.all_known_types.get(key, None)
        if include is None:
            return False, None

        # Problem with typedef, TODO: improve this error handling
        if filename == include:
            return False, None

        new_error = create_dissector(filename, platform, folders, [include])
        if new_error != error:
            FileConfig.add_include(filename, include)
            if new_error is None:
                return True, None  # Worked
            return False, new_error  # Try more
        return False, None  # Give up
Ejemplo n.º 6
0
    def include_heuristics(filename, platform, error):
        """Try to find missing includes from error message."""
        include = None
        msg = str(error)
        if 'before: ' in msg:
            key = msg.rsplit('before: ', 1)[1].strip()
            include = cparser.StructVisitor.all_known_types.get(key, None)
        if include is None:
            return False, None

        # Problem with typedef, TODO: improve this error handling
        if filename == include:
            return False, None

        new_error = create_dissector(filename, platform, folders, [include])
        if new_error != error:
            FileConfig.add_include(filename, include)
            if new_error is None:
                return True, None  # Worked
            return False, new_error  # Try more
        return False, None  # Give up
Ejemplo n.º 7
0
    def __init__(self, fast: int, slow: int, signal: int, period: int):
        self.db = None

        config = FileConfig()

        try:
            self.db = connect(host=config.get('DB.host'),
                              user=config.get('DB.user'),
                              passwd=config.get('DB.pass'),
                              database=config.get('DB.name'))
        except ProgrammingError as e:
            print(f'[DB] [ERROR] {e.msg}')
            raise e

        self.fast = fast
        self.slow = slow
        self.signal = signal
        self.period = period

        self.__table = '_'.join(
            map(str, ['a', self.fast, self.signal, self.period]))
        self.__key = '_'.join(
            map(str, [self.fast, self.slow, self.signal, self.period]))
Ejemplo n.º 8
0
def run():
    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)
        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)

        # If CLI was correctly parsed, execute db-migrate.
        Main(config).execute()
    except Exception, e:
        CLI().error_and_exit(str(e))
Ejemplo n.º 9
0
 def __init__(self):
     config = FileConfig()
     config.load_yaml()
     self.modules_path = config.settings["METASPLOIT"]["MODULE_PATH"]
Ejemplo n.º 10
0
    )

    for _type in [ModelBacktest.TYPE_LONG, ModelBacktest.TYPE_SHORT]:
        if statistics[_type] is not None:
            last = ModelBacktest.find_by_params(p_in, p_out, _type)
            if last is None:
                ModelBacktest.create(p_in, p_out, _type, start, end, statistics[_type])
            else:
                ModelBacktest.do_update(last.id, start, end, statistics[_type])
        else:
            print(f'Can not calculate statistics for {[p_in, p_out]}')
    del b
    print(f'{[p_in, p_out]}: {time() - _s}')

if __name__ == '__main__':
    config = FileConfig()

    end = 1537514011#time()
    end -= end%ONE_DAY

    start = end - 180*ONE_DAY

    process_count = config.get('APP.POOL_PROCESSES', 4, int)
    max_tasks = config.get('APP.POOL_TASK_PER_CHILD', 10, int)
    use_pool = config.get('APP.USE_POOL', True, bool)

    start_at = time()

    if use_pool:
        pool = Pool(processes=process_count, maxtasksperchild=max_tasks)
        pool.starmap(processor2, generator(start, end))
Ejemplo n.º 11
0
def run(options):
    """ Initial Module. Treat Parameters and call Main Module for execution """
    try:
        if options.get('simple_virtuoso_migrate_version'):
            msg = ('simple-virtuoso-migrate v%s' %
                                            SIMPLE_VIRTUOSO_MIGRATE_VERSION)
            CLI.info_and_exit(msg)

        if options.get('show_colors'):
            CLI.show_colors()

        # Create config
        if options.get('config_file'):
            config = FileConfig(options.get('config_file'),
                                options.get('environment'))
        else:
            config = Config()

        config.update('schema_version', options.get('schema_version'))
        config.update('show_sparql', options.get('show_sparql'))
        config.update('show_sparql_only', options.get('show_sparql_only'))
        config.update('file_migration', options.get('file_migration'))
        #config.update('add_ttl', options.get('add_ttl'))
        config.update('load_ttl', options.get('load_ttl'))
        config.update('log_dir', options.get('log_dir'))
        config.update('database_user', options.get('database_user'))
        config.update('database_password', options.get('database_password'))
        config.update('host_user', options.get('host_user'))
        config.update('host_password', options.get('host_password'))
        config.update('virtuoso_dirs_allowed',
                      options.get('virtuoso_dirs_allowed'))
        config.update('database_host', options.get('database_host'))
        config.update('database_port', options.get('database_port'))
        config.update('database_endpoint', options.get('database_endpoint'))
        config.update('database_graph', options.get('database_graph'))
        config.update('database_ontology', options.get('database_ontology'))
        if options.get('database_migrations_dir'):
            config.update("database_migrations_dir",
                          Config._parse_migrations_dir(
                                            options.get(
                                                'database_migrations_dir')))

        config.update("database_migrations_dir",
                      config.get("database_migrations_dir")[0])
        config.update('log_level', int(options.get('log_level')))

        # Ask the password for user if configured
        if config.get('database_password') == '<<ask_me>>':
            CLI.msg('\nPlease inform password to connect to virtuoso (DATABASE) "%s@%s"' % (config.get('database_user'),
                                                config.get('database_host')))
            passwd = getpass()
            config.update('database_password', passwd)

        is_local = config.get('database_host', '').lower() in ["localhost",
                                                               "127.0.0.1"]
        if config.get('load_ttl') and\
                config.get('virtuoso_dirs_allowed') is None and\
                not is_local:
            if config.get('host_password') == '<<ask_me>>':
                msg = '\nPlease inform password to connect to virtuoso (HOST) "%s@%s"'
                CLI.msg(msg % (config.get('host_user'),
                               config.get('database_host')))
                passwd = getpass()
                config.update('host_password', passwd)
        # If CLI was correctly parsed, execute db-virtuoso.
        Main(config).execute()
    except KeyboardInterrupt:
        CLI.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        CLI.error_and_exit(unicode(e))
Ejemplo n.º 12
0
def run(options):
    try:
        if options.get('simple_db_migrate_version'):
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            CLI.info_and_exit(msg)

        if options.get('show_colors'):
            CLI.show_colors()

        # Create config
        if options.get('config_file') or os.path.exists('simple-db-migrate.conf'):
            config = FileConfig(options.get('config_file') or 'simple-db-migrate.conf', options.get('environment'))
        else:
            config = Config()

        config.update('schema_version', options.get('schema_version'))
        config.update('show_sql', options.get('show_sql'))
        config.update('show_sql_only', options.get('show_sql_only'))
        config.update('new_migration', options.get('new_migration'))
        config.update('drop_db_first', options.get('drop_db_first'))
        config.update('paused_mode', options.get('paused_mode'))
        config.update('log_dir', options.get('log_dir'))
        config.update('label_version', options.get('label_version'))
        config.update('force_use_files_on_down', options.get('force_use_files_on_down'))
        config.update('force_execute_old_migrations_versions', options.get('force_execute_old_migrations_versions'))
        config.update('utc_timestamp', options.get('utc_timestamp'))
        config.update('database_user', options.get('database_user'))
        config.update('database_password', options.get('database_password'))
        config.update('database_host', options.get('database_host'))
        config.update('database_port', options.get('database_port'))
        config.update('database_name', options.get('database_name'))

        if config.get('database_port', None):
            config.update('database_port', int(config.get('database_port')))

        if options.get('database_migrations_dir'):
            config.update("database_migrations_dir", Config._parse_migrations_dir(options.get('database_migrations_dir')))

        config.update('database_engine', options.get('database_engine'))
        if not config.get('database_engine', None):
            config.update('database_engine', "mysql")

        config.update('database_version_table', options.get('database_version_table'))
        if not config.get('database_version_table', None):
            config.update('database_version_table', "__db_version__")

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

        config.update('log_level', log_level)

        # Ask the password for user if configured
        if config.get('database_password') == '<<ask_me>>':
            if options.get('password'):
                passwd = options.get('password')
            else:
                CLI.msg('\nPlease inform password to connect to database "%s@%s:%s"' % (config.get('database_user'), config.get('database_host'), config.get('database_name')))
                passwd = getpass()
            config.update('database_password', passwd)

        if options.get('info_database'):
            if options.get('info_database').lower() == 'last_label':
                CLI.info_and_exit(Main(config).last_label() or "NONE")
            elif options.get('info_database').lower() == 'labels':
                labels = Main(config).labels()
                CLI.info_and_exit(labels and "\n".join(labels) or "NONE")
            else:
                CLI.error_and_exit("The '%s' is a wrong parameter for info" % options.get('info_database').lower())

        # 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))
Ejemplo n.º 13
0
def parse_headers(headers):
    """Parse 'headers' to create a Wireshark protocol dissector."""
    folders = {os.path.dirname(i) for i in headers}  # Folders to -Include
    failed = []  # Filenames, platforms pairs we have failed to parse so far

    def include_heuristics(filename, platform, error):
        """Try to find missing includes from error message."""
        include = None
        msg = str(error)
        if 'before: ' in msg:
            key = msg.rsplit('before: ', 1)[1].strip()
            include = cparser.StructVisitor.all_known_types.get(key, None)
        if include is None:
            return False, None

        # Problem with typedef, TODO: improve this error handling
        if filename == include:
            return False, None

        new_error = create_dissector(filename, platform, folders, [include])
        if new_error != error:
            FileConfig.add_include(filename, include)
            if new_error is None:
                return True, None  # Worked
            return False, new_error  # Try more
        return False, None  # Give up

    def print_status(tries=[]):
        """Print a status message with how many headers failed to parse."""
        if tries and tries[-1] == 0:
            return
        tries.append(len({i for i, j, k in failed}))
        if tries[-1] == 0:
            msg = 'Successfully parsed all %i' % len(headers)
        else:
            msg = 'Failed to parse %i out of %i' % (tries[-1], len(headers))
        print('[%i] %s header files' % (len(tries), msg))

    def filenames_have_shared_path(f1, f2):
        p1 = os.path.dirname(f1)
        p2 = os.path.dirname(f2)
        c = os.path.commonprefix([p1, p2])
        return c == p1 or c == p2

    print('[0] Attempting to parse %i header files' % len(headers))

    # First try, in the order given through the CLI
    for filename in headers:
        for platform in Options.platforms:
            error = create_dissector(filename, platform, folders)
            if error is not None:
                failed.append([filename, platform, error])
    print_status()

    # Try to include files based on decoding the error messages
    work_list = failed[:]
    for tmp in range(2, 4):
        for i in reversed(range(len(work_list))):
            status, new_error = include_heuristics(*work_list[i])
            if not status and new_error is not None:
                work_list[i][2] = new_error
            else:
                if status:
                    failed.remove(work_list[i])
                work_list.pop(i)
        print_status()

    # Try to include all who worked as it might help
    failed_names = [filename for filename, platform, error in failed]
    includes = [
        f for f in headers
        if f not in failed_names and filenames_have_shared_path(filename, f)
    ]

    for i in reversed(range(len(failed))):
        filename, platform, tmp = failed.pop(i)
        error = create_dissector(filename, platform, folders, includes)
        if error is None:
            # Worked, record it in case anyone else needs this file
            for inc in includes:
                FileConfig.add_include(filename, inc)
            includes.append(filename)
        else:
            failed.append([filename, platform, error])
    print_status()

    # Try to include files based on decoding the error messages
    work_list = failed[:]
    for tmp in range(5, 7):
        for i in reversed(range(len(work_list))):
            status, new_error = include_heuristics(*work_list[i])
            if not status and new_error is not None:
                work_list[i][2] = new_error
            else:
                if status:
                    failed.remove(work_list[i])
                work_list.pop(i)
        print_status()

    # Give up!
    for filename, platform, error in failed:
        print('Skipped "%s":%s as it raised %s' %
              (filename, platform.name, repr(error)))

    return len({i for i, j, k in failed})
Ejemplo n.º 14
0
parser = argparse.ArgumentParser(description='Start Flypi Server.')
parser.add_argument(
    '--config',
    '-c',
    default=None,
    help=
    'Configuration file to change parameters (default: server_port on 8080, MongoDB connection on localhost:27017)'
)

args = parser.parse_args()

config = Config()
try:
    if args.config is not None:
        config = FileConfig(args.config)
except:
    print "Failed parsing config file, please check that file is accessible and well formatted."
    exit()

app = Bottle()


@app.route('/image/<file_name>')
def img_live(file_name):
    return static_file(file_name, root=lora.ssdv_path)


@app.route('/images/last')
def img_live():
    last_filename = ""
Ejemplo n.º 15
0
from config import FileConfig
from json import dumps
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, Float, Text, String, create_engine
from sqlalchemy.orm import sessionmaker, scoped_session

config = FileConfig()

Base = declarative_base()

class Backtest(Base):

    __tablename__ = 'main_backtest'
    __table_args__ = {'extend_existing': True}

    id = Column(Integer, primary_key=True)

    active = Column(Integer)

    buy_fast = Column(Integer)
    buy_slow = Column(Integer)
    buy_signal = Column(Integer)
    buy_period = Column(Integer)

    sell_fast = Column(Integer)
    sell_slow = Column(Integer)
    sell_signal = Column(Integer)
    sell_period = Column(Integer)

    ts_start = Column(Integer)
    ts_end = Column(Integer)
Ejemplo n.º 16
0
def get_calculating():
    return list(map(int, files_list(join(basedir, 'btrun'))))


def touch(fname, times=None):
    fhandle = open(fname, 'a')
    try:
        utime(fname, times)
    finally:
        fhandle.close()


if __name__ == '__main__':
    calculating = get_calculating()
    max_running = FileConfig().get('APP.POOL_PROCESSES', 4, int)

    bt = None

    if len(calculating) < max_running:
        bt = Backtest.findOneToProcess(calculating)
    else:
        print('Server is busy now')
        exit(0)

    if bt is None:
        print('No backtest found')
        exit(0)

    fname = join(basedir, 'btrun', str(bt.id))
Ejemplo n.º 17
0
service_bannerlist = []

exclude_portlist = []
tmp_modulelist = []

manual_explist = []

port_info_list = []

catch_dup_sessionlist = []
shell_notice_list = []
alr_tested_module_list = []
working_exploit_list = []

# PATH
config = FileConfig()
config.load_yaml()
msgrpc_pass = config.settings["METASPLOIT"]["MSGRPC_PASS"]

penta_path = pathlib.Path(__file__).resolve().parent.parent.parent
data_path = penta_path / "data"
msf_path = data_path / "msf"
msf_db_path = msf_path / "module_list.db"
msf_port_db = msf_path / "port_db.sqlite"

log_directory = penta_path / "logs"
debug_file = log_directory / "test"

# Building timestamped filename
date_and_time = time.strftime("%m") + time.strftime("%d") + time.strftime(
    "%y") + '_' + time.strftime("%H") + time.strftime("%M") + time.strftime(
Ejemplo n.º 18
0
def run(options):
    """ Initial Module. Treat Parameters and call Main Module for execution """
    try:
        if options.get("simple_virtuoso_migrate_version"):
            msg = "simple-virtuoso-migrate v%s" % SIMPLE_VIRTUOSO_MIGRATE_VERSION
            CLI.info_and_exit(msg)

        if options.get("show_colors"):
            CLI.show_colors()

        # Create config
        if options.get("config_file"):
            config = FileConfig(options.get("config_file"), options.get("environment"))
        else:
            config = Config()

        config.update("schema_version", options.get("schema_version"))
        config.update("show_sparql", options.get("show_sparql"))
        config.update("show_sparql_only", options.get("show_sparql_only"))
        config.update("file_migration", options.get("file_migration"))
        # config.update('add_ttl', options.get('add_ttl'))
        config.update("load_ttl", options.get("load_ttl"))
        config.update("log_dir", options.get("log_dir"))
        config.update("database_user", options.get("database_user"))
        config.update("database_password", options.get("database_password"))
        config.update("host_user", options.get("host_user"))
        config.update("host_password", options.get("host_password"))
        config.update("virtuoso_dirs_allowed", options.get("virtuoso_dirs_allowed"))
        config.update("database_host", options.get("database_host"))
        config.update("database_port", options.get("database_port"))
        config.update("database_endpoint", options.get("database_endpoint"))
        config.update("database_graph", options.get("database_graph"))
        config.update("database_ontology", options.get("database_ontology"))
        if options.get("database_migrations_dir"):
            config.update(
                "database_migrations_dir", Config._parse_migrations_dir(options.get("database_migrations_dir"))
            )

        config.update("database_migrations_dir", config.get("database_migrations_dir")[0])
        config.update("log_level", int(options.get("log_level")))

        # Ask the password for user if configured
        if config.get("database_password") == "<<ask_me>>":
            CLI.msg(
                '\nPlease inform password to connect to\
                virtuoso (DATABASE) "%s@%s"'
                % (config.get("database_user"), config.get("database_host"))
            )
            passwd = getpass()
            config.update("database_password", passwd)

        is_local = config.get("database_host", "").lower() in ["localhost", "127.0.0.1"]
        # import pdb; pdb.set_trace()
        if config.get("load_ttl") and config.get("virtuoso_dirs_allowed") is None and not is_local:
            if config.get("host_password") == "<<ask_me>>":
                CLI.msg(
                    '\nPlease inform password to connect to\
                virtuoso (HOST) "%s@%s"'
                    % (config.get("host_user"), config.get("database_host"))
                )
                passwd = getpass()
                config.update("host_password", passwd)
        # If CLI was correctly parsed, execute db-virtuoso.
        Main(config).execute()
    except KeyboardInterrupt:
        CLI.info_and_exit("\nExecution interrupted by user...")
    except Exception, e:
        CLI.error_and_exit(unicode(e))
Ejemplo n.º 19
0
def parse_headers(headers):
    """Parse 'headers' to create a Wireshark protocol dissector."""
    folders = {os.path.dirname(i) for i in headers}  # Folders to -Include
    failed = []  # Filenames, platforms pairs we have failed to parse so far

    def include_heuristics(filename, platform, error):
        """Try to find missing includes from error message."""
        include = None
        msg = str(error)
        if "before: " in msg:
            key = msg.rsplit("before: ", 1)[1].strip()
            include = cparser.StructVisitor.all_known_types.get(key, None)
        if include is None:
            return False, None

        # Problem with typedef, TODO: improve this error handling
        if filename == include:
            return False, None

        new_error = create_dissector(filename, platform, folders, [include])
        if new_error != error:
            FileConfig.add_include(filename, include)
            if new_error is None:
                return True, None  # Worked
            return False, new_error  # Try more
        return False, None  # Give up

    def print_status(tries=[]):
        """Print a status message with how many headers failed to parse."""
        if tries and tries[-1] == 0:
            return
        tries.append(len({i for i, j, k in failed}))
        if tries[-1] == 0:
            msg = "Successfully parsed all %i" % len(headers)
        else:
            msg = "Failed to parse %i out of %i" % (tries[-1], len(headers))
        print("[%i] %s header files" % (len(tries), msg))

    def filenames_have_shared_path(f1, f2):
        p1 = os.path.dirname(f1)
        p2 = os.path.dirname(f2)
        c = os.path.commonprefix([p1, p2])
        return c == p1 or c == p2

    print("[0] Attempting to parse %i header files" % len(headers))

    # First try, in the order given through the CLI
    for filename in headers:
        for platform in Options.platforms:
            error = create_dissector(filename, platform, folders)
            if error is not None:
                failed.append([filename, platform, error])
    print_status()

    # Try to include files based on decoding the error messages
    work_list = failed[:]
    for tmp in range(2, 4):
        for i in reversed(range(len(work_list))):
            status, new_error = include_heuristics(*work_list[i])
            if not status and new_error is not None:
                work_list[i][2] = new_error
            else:
                if status:
                    failed.remove(work_list[i])
                work_list.pop(i)
        print_status()

    # Try to include all who worked as it might help
    failed_names = [filename for filename, platform, error in failed]
    includes = [f for f in headers if f not in failed_names and filenames_have_shared_path(filename, f)]

    for i in reversed(range(len(failed))):
        filename, platform, tmp = failed.pop(i)
        error = create_dissector(filename, platform, folders, includes)
        if error is None:
            # Worked, record it in case anyone else needs this file
            for inc in includes:
                FileConfig.add_include(filename, inc)
            includes.append(filename)
        else:
            failed.append([filename, platform, error])
    print_status()

    # Try to include files based on decoding the error messages
    work_list = failed[:]
    for tmp in range(5, 7):
        for i in reversed(range(len(work_list))):
            status, new_error = include_heuristics(*work_list[i])
            if not status and new_error is not None:
                work_list[i][2] = new_error
            else:
                if status:
                    failed.remove(work_list[i])
                work_list.pop(i)
        print_status()

    # Give up!
    for filename, platform, error in failed:
        print('Skipped "%s":%s as it raised %s' % (filename, platform.name, repr(error)))

    return len({i for i, j, k in failed})
Ejemplo n.º 20
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)
        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)
        
        # 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>>':
            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))
Ejemplo n.º 21
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))
Ejemplo n.º 22
0
def run(options):
    try:
        if options.get('simple_db_migrate_version'):
            msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
            CLI.info_and_exit(msg)

        if options.get('show_colors'):
            CLI.show_colors()

        # Create config
        if options.get('config_file'):
            config = FileConfig(options.get('config_file'), options.get('environment'))
        else:
            config = Config()

        config.update('schema_version', options.get('schema_version'))
        config.update('show_sql', options.get('show_sql'))
        config.update('show_sql_only', options.get('show_sql_only'))
        config.update('new_migration', options.get('new_migration'))
        config.update('drop_db_first', options.get('drop_db_first'))
        config.update('paused_mode', options.get('paused_mode'))
        config.update('log_dir', options.get('log_dir'))
        config.update('label_version', options.get('label_version'))
        config.update('force_use_files_on_down', options.get('force_use_files_on_down'))
        config.update('force_execute_old_migrations_versions', options.get('force_execute_old_migrations_versions'))
        config.update('utc_timestamp', options.get('utc_timestamp'))
        config.update('database_user', options.get('database_user'))
        config.update('database_password', options.get('database_password'))
        config.update('database_host', options.get('database_host'))
        config.update('database_name', options.get('database_name'))
        if options.get('database_migrations_dir'):
            config.update("database_migrations_dir", Config._parse_migrations_dir(options.get('database_migrations_dir')))

        config.update('database_engine', options.get('database_engine'))
        if not config.get('database_engine', None):
            config.update('database_engine', "mysql")

        config.update('database_version_table', options.get('database_version_table'))
        if not config.get('database_version_table', None):
            config.update('database_version_table', "__db_version__")

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

        config.update('log_level', log_level)

        # Ask the password for user if configured
        if config.get('database_password') == '<<ask_me>>':
            if options.get('password'):
                passwd = options.get('password')
            else:
                CLI.msg('\nPlease inform password to connect to database "%s@%s:%s"' % (config.get('database_user'), config.get('database_host'), config.get('database_name')))
                passwd = getpass()
            config.update('database_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))
Ejemplo n.º 23
0
 def __init__(self):
     config = FileConfig()
     config.load_yaml()
     self.shodan_key_string = config.settings["SHODAN_API_KEY"]
     self.shodan_api = shodan.Shodan(self.shodan_key_string)