示例#1
0
def download_test_file(name, config_dir=None, force=False):
    """Download a test file."""
    config_dir = Path(config_dir or phy_config_dir())
    path = config_dir / 'test_data' / name
    # Ensure the directory exists.
    ensure_dir_exists(path.parent)
    if not force and path.exists():
        return path
    url = _BASE_URL + name
    download_file(url, output_path=path)
    return path
示例#2
0
文件: alf.py 项目: balefebvre/phylib
def _create_if_possible(path, new_path, force=False):
    """Prepare the copy/move/symlink of a file, by making sure the source exists
    while the destination does not."""
    if not Path(path).exists():  # pragma: no cover
        logger.warning("Path %s does not exist, skipping.", path)
        return False
    if Path(new_path).exists() and not force:  # pragma: no cover
        logger.warning("Path %s already exists, skipping.", new_path)
        return False
    ensure_dir_exists(new_path.parent)
    return True
示例#3
0
def load_master_config(config_dir=None):
    """Load a master Config file from the user configuration file (by default, this is
    `~/.phy/phy_config.py`)."""
    config_dir = config_dir or phy_config_dir()
    path = config_dir / 'phy_config.py'
    # Create a default config file if necessary.
    if not path.exists():
        ensure_dir_exists(path.parent)
        logger.debug("Creating default phy config file at `%s`.", path)
        path.write_text(_default_config(config_dir=config_dir))
    assert path.exists()
    return load_config(path)