Use logger for Nexus create repo script 66/5666/8
authorJessica Wagantall <jwagantall@linuxfoundation.org>
Fri, 28 Jul 2017 00:19:08 +0000 (17:19 -0700)
committerJessica Wagantall <jwagantall@linuxfoundation.org>
Fri, 4 Aug 2017 19:54:42 +0000 (19:54 +0000)
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 <jwagantall@linuxfoundation.org>
lftools/nexus/cmd.py

index 34e56d0..cddac66 100644 (file)
@@ -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'])