def __init__(self): super(MvnFeedCLI, self).__init__(cli_name=CLI_NAME, config_dir=GLOBAL_CONFIG_DIR, config_env_var_prefix=CLI_ENV_VARIABLE_PREFIX, commands_loader_cls=MvnFeedCommandsLoader, help_cls=MvnFeedHelp) self.args = None load_config() init_logging('mvnfeed.log')
def get_repository(config, name): if config is None: config = load_config() section_name = repo_section_name(name) if not config.has_section(section_name): raise ValueError('No repository found: ' + name) return config[section_name]
def delete_repository(name): """ Deletes a configured Maven repository. """ config = load_config() section_name = repo_section_name(name) if config.has_section(section_name): config.remove_section(section_name) save_config(config)
def view_stagedir(): """ Views the output directory where mvnfeed will be staged. """ config = load_config() if 'general' not in config: return '' return config.get('general', STAGE_DIR_CONFIGNAME)
def get_stagedir(config): """ Returns the value of the stage directory. """ if config is None: config = load_config() if 'general' not in config: return None return config.get('general', STAGE_DIR_CONFIGNAME)
def list_repositories(): """ Lists the configured Maven repositories. """ config = load_config() for section in config.sections(): if section.startswith(REPOSITORY): repo = config[section] print(section[11:]) if URL in repo: print(' url : ' + repo[URL])
def set_stagedir(path): """ Sets the output directory where dependencies will be staged. :param path: path where the downloaded mvnfeed will be staged """ config = load_config() if 'general' not in config: config.add_section('general') config.set('general', STAGE_DIR_CONFIGNAME, path) save_config(config)
def transfer_artifact(name, from_repo, to_repo, transfer_deps=False): """ Transfers a single artifact. :param name: name of the artifact to download, following the group_id:artifact_id:version format :param from_repo: name of the source repository :param to_repo: name of the destination repository :param transfer_deps: True if the dependencies must be transferred """ logging.info('transferring %s', name) config = load_config() from_repository = get_repository(config, from_repo) to_repository = get_repository(config, to_repo) stage_dir = get_stagedir(config) _transfer_single_artifact(name, from_repository, to_repository, stage_dir, transfer_deps)
def add_repository(name, username, url=None): """ Adds an external Maven repository. :param name: internal name of the repository :param username: name of the user for the basic authentication to the repository :param url: url of the repository """ if username is None: raise ValueError('Username must be defined') if url is None: raise ValueError('Url must be defined') password = getpass.getpass() encoded = base64.b64encode((username + ':' + password).encode('utf-8')) authorization = 'Basic ' + encoded.decode('utf-8') config = load_config() config[repo_section_name(name)] = { URL: _default_value(url), AUTHORIZATION: _default_value(authorization) } save_config(config)
def transfer_bulk(filename, from_repo, to_repo, transfer_deps=False): """ Transfers artifacts from a file, one artifact per line. :param filename: name of the file containing the mvnfeed to upload :param from_repo: name of the source repository :param to_repo: name of the destination repository :param transfer_deps: True if the dependencies must be transferred """ logging.info('transferring from file %s', filename) config = load_config() from_repository = get_repository(config, from_repo) to_repository = get_repository(config, to_repo) stage_dir = get_stagedir(config) with open(filename, 'r') as file: lines = file.readlines() for line in lines: line = line.strip().rstrip() if line: _transfer_single_artifact(line, from_repository, to_repository, stage_dir, transfer_deps)