From 54a6bc3fb7a81db84e258a4710976cf7ec4e7080 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Thu, 27 Jul 2017 17:19:08 -0700 Subject: [PATCH] Use logger for Nexus create repo script Nexus create repo needs to output what it's doing into a log file. Use the generic logger to obtain that output. JIRA: RELENG-253 Change-Id: I1705b52761f79a1331032175c49484c9a75f9810 Signed-off-by: Jessica Wagantall --- lftools/nexus/cmd.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lftools/nexus/cmd.py b/lftools/nexus/cmd.py index 34e56d04..cddac66a 100644 --- a/lftools/nexus/cmd.py +++ b/lftools/nexus/cmd.py @@ -9,12 +9,16 @@ # http://www.eclipse.org/legal/epl-v10.html ############################################################################## """Contains functions for various Nexus tasks.""" + +import logging import sys import yaml from lftools.nexus import Nexus +log = logging.getLogger(__name__) + def reorder_staged_repos(settings_file): """Reorder staging repositories in Nexus. @@ -91,29 +95,33 @@ def create_repos(config_file, settings_file): for priv in privs_set: try: privs[priv] = _nexus.get_priv(name, priv) + log.info('Creating {} privileges.'.format(priv)) except LookupError as e: privs[priv] = _nexus.create_priv(name, target_id, priv) # Create Role try: role_id = _nexus.get_role(name) + log.info('Creating {} role.'.format(role_id)) except LookupError as e: role_id = _nexus.create_role(name, privs) # Create user try: _nexus.get_user(name) + log.info('Creating {} user.'.format(name)) except LookupError as e: _nexus.create_user(name, email, role_id, password, extra_privs) def build_repo(repo, repoId, config, base_groupId): - print('Building for %s.%s' % (base_groupId, repo)) + log.info('-> Building for {}.{} in Nexus'.format(base_groupId, repo)) groupId = '%s.%s' % (base_groupId, repo) target1 = '^/%s/.*' % groupId.replace('.', '[/\.]') target2 = '^/%s[\.].*' % groupId.replace('.', '[/\.]') if 'extra_privs' in config: extra_privs = config['extra_privs'] + log.info('Privileges for this repo:' + ', '.join(extra_privs)) else: extra_privs = [] @@ -124,6 +132,8 @@ def create_repos(config_file, settings_file): config['password'], extra_privs) + log.info('-> Finished successfully for {}.{}!!\n'.format(base_groupId, repo)) + if 'repositories' in config: for sub_repo in config['repositories']: sub_repo_id = '%s-%s' % (repoId, sub_repo) @@ -133,5 +143,6 @@ def create_repos(config_file, settings_file): config['repositories'][sub_repo], groupId) + log.warning('Nexus repo creation started. Aborting now could leave tasks undone!') for repo in config['repositories']: build_repo(repo, repo, config['repositories'][repo], config['base_groupId']) -- 2.16.6