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
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
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)