Ejemplo n.º 1
0
def _write_config_file(file_path):
    """
    Write a default config file to the specified location.

    Returns:
        SafeConfigParser: Instace written to file.
    """

    # [FIXME]
    # This may be usefull to turn into a proper command, so users can restore to
    # factory settings easily.

    def get_db_path():
        return os.path.join(str(AppDirs.user_data_dir), 'hamster_cli.sqlite')

    def get_tmp_file_path():
        return os.path.join(str(AppDirs.user_data_dir), 'hamster_cli.fact')

    config = SafeConfigParser()

    # Backend
    config.add_section('Backend')
    config.set('Backend', 'store', 'sqlalchemy')
    config.set('Backend', 'daystart', '00:00:00')
    config.set('Backend', 'fact_min_delta', '60')
    config.set('Backend', 'db_engine', 'sqlite')
    config.set('Backend', 'db_host', '')
    config.set('Backend', 'db_port', '')
    config.set('Backend', 'db_name', '')
    config.set('Backend', 'db_path', get_db_path())
    config.set('Backend', 'db_user', '')
    config.set('Backend', 'db_password', '')

    # Client
    config.add_section('Client')
    config.set('Client', 'unsorted_localized', 'Unsorted')
    config.set('Client', 'log_level', 'debug')
    config.set('Client', 'log_console', 'False')
    config.set('Client', 'log_filename', 'hamster_cli.log')

    configfile_path = os.path.dirname(file_path)
    if not os.path.lexists(configfile_path):
        os.makedirs(configfile_path)
    with open(file_path, 'w') as fobj:
        config.write(fobj)

    return config
Ejemplo n.º 2
0
def _write_config_file(file_path):
    """
    Write a default config file to the specified location.

    Returns:
        SafeConfigParser: Instace written to file.
    """
    # [FIXME]
    # This may be usefull to turn into a proper command, so users can restore to
    # factory settings easily.

    def get_db_path():
        return os.path.join(str(AppDirs.user_data_dir), 'hamster_cli.sqlite')

    def get_tmp_file_path():
        return os.path.join(str(AppDirs.user_data_dir), 'hamster_cli.fact')

    config = SafeConfigParser()

    # Backend
    config.add_section('Backend')
    config.set('Backend', 'store', 'sqlalchemy')
    config.set('Backend', 'daystart', '00:00:00')
    config.set('Backend', 'fact_min_delta', '60')
    config.set('Backend', 'db_engine', 'sqlite')
    config.set('Backend', 'db_host', '')
    config.set('Backend', 'db_port', '')
    config.set('Backend', 'db_name', '')
    config.set('Backend', 'db_path', get_db_path())
    config.set('Backend', 'db_user', '')
    config.set('Backend', 'db_password', '')

    # Client
    config.add_section('Client')
    config.set('Client', 'unsorted_localized', 'Unsorted')
    config.set('Client', 'log_level', 'debug')
    config.set('Client', 'log_console', 'False')
    config.set('Client', 'log_filename', 'hamster_cli.log')

    configfile_path = os.path.dirname(file_path)
    if not os.path.lexists(configfile_path):
        os.makedirs(configfile_path)
    with open(file_path, 'w') as fobj:
        config.write(fobj)

    return config