Пример #1
0
def merge_config_files(config_filename: str) -> dict:
    """Return the contents of config_filename or merged contents,
    if there exists a link to another config file in config_filename.
    """
    config_data = load_json_conf(config_filename, key='')
    local_path = config_data.get('LOCAL', None)
    if local_path is not None:
        try:
            local_data = load_json_conf(local_path, key='')
            if local_data is not None:
                merged_configs = merge_nested_dicts(config_data, local_data)
                return merged_configs
        except Exception as err:
            logger.error(f'Could not open file {local_path}: {err}')
    return config_data
Пример #2
0
def create_local_config_base(config_filename: str):
    """Check the existence and create local config file,
    if key 'LOCAL' exists in configuration file (config_filename).

    Local config file is used in development environment to store Django
    related passwords, secrets and all stuff which aren't suitable for versioning.
    """
    with OperationManager('Initializing local config file'):
        if not Path(config_filename).is_file():
            print("File not found: " + config_filename)
            return
        config_data = load_json_conf(config_filename, key='')
        local_path = config_data.get('LOCAL', None)
        if not local_path:
            print("Local config not defined in {}".format(config_filename))
            return
        if Path(local_path).is_file():
            print("Local config file already exists")
            return
        if isinstance(local_path, str):
            try:
                local_conf_dict = filter_nested_dict(config_data, '$')
                with open(local_path, 'w+', encoding='utf-8') as file:
                    json.dump(local_conf_dict, file)
                print('Local config file created')
            except Exception as err:
                print('Problem creating local config file: {}'.format(err))
Пример #3
0
def _load_git_commit_info_json(
        git_version_info_path: str) -> Tuple[str, str, str]:
    """Retrieve git commit information from a JSON file. 
    Fails if the file is not found or properly defined.
    """
    git_version_info = load_json_conf(git_version_info_path)
    return git_version_info["branch"], git_version_info[
        "commit"], git_version_info["repository"]
Пример #4
0
 def test_git_version_table_should_store_commit_after_update_using_json_version_info(
         self):
     git.update_git_version(
         self.engine,
         self.git_table_schema,
         self.git_table,
         repository=None,
         git_version_info_path=self.git_version_info_path)
     git_version_info = load_json_conf(self.git_version_info_path)
     self.assert_git_version_table_results(
         self.get_commit_info_from_git_table(),
         git_version_info["repository"], git_version_info["branch"],
         git_version_info["commit"])
Пример #5
0
 def __init__(self, config_filename: str):
     self.engine = None
     self.config_filename = config_filename
     self.configuration = load_json_conf(config_filename)
     if self.configuration is None:
         raise Exception("No configuration found")
Пример #6
0
# Configure logging for alembic
# Do not disable existing loggers!
# If existing loggers are disabled --> Ahjo's loggers will be disabled after upgrade.
fileConfig(config.config_file_name, disable_existing_loggers=False)
logger = getLogger('alembic.env.py')

# Load project config file (config_development.jsonc)
main_config_path = context.get_x_argument(
    as_dictionary=True).get('main_config')
if main_config_path is None:
    logger.info(
        'No extra alembic argument "-x main_config=config.file" given.')
    main_config_path = input("Module configuration file path: ")
logger.info(f'Main config file: {main_config_path}')

main_config = load_json_conf(main_config_path)
conn_info = create_conn_info(main_config)

version_table_schema = main_config.get("alembic_version_table_schema", "dbo")
version_table = main_config.get("alembic_version_table", "alembic_version")

###################################################################

meta = MetaData(
    naming_convention={
        "ix": "ix_%(column_0_label)s",
        "uq": "uq_%(table_name)s_%(column_0_name)s",
        "ck": "ck_%(table_name)s_%(constraint_name)s",
        "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
        "pk": "pk_%(table_name)s"
    })