From 2db3ccc883b8f1778a540063da1d38b8db741088 Mon Sep 17 00:00:00 2001 From: Sinisa Veseli <sveseli@aps.anl.gov> Date: Thu, 13 Oct 2016 19:19:38 +0000 Subject: [PATCH] additional options for running under cron --- .../aps_user_db/cli/updateUserFromApsDbCli.py | 2 +- .../aps_user_db/cli/updateUsersFromApsDbCli.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/python/dm/aps_user_db/cli/updateUserFromApsDbCli.py b/src/python/dm/aps_user_db/cli/updateUserFromApsDbCli.py index bf7327db..e73a99bb 100755 --- a/src/python/dm/aps_user_db/cli/updateUserFromApsDbCli.py +++ b/src/python/dm/aps_user_db/cli/updateUserFromApsDbCli.py @@ -33,7 +33,7 @@ class UpdateUserFromApsDbCli(DmCli): dm-update-user-from-aps-db --badge=BADGE --config-file=CONFIGFILE Description: - Updates user in DM LDAP and database using information from APS DB. + Updates single user in DM LDAP using information from APS DB. This command will not update DM DB. """) ConfigurationManager.getInstance().setConfigFile(self.options.configFile) LoggingManager.getInstance().configure() diff --git a/src/python/dm/aps_user_db/cli/updateUsersFromApsDbCli.py b/src/python/dm/aps_user_db/cli/updateUsersFromApsDbCli.py index 991823ba..995dae63 100755 --- a/src/python/dm/aps_user_db/cli/updateUsersFromApsDbCli.py +++ b/src/python/dm/aps_user_db/cli/updateUsersFromApsDbCli.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import datetime +import time import os from dm.common.exceptions.invalidRequest import InvalidRequest from dm.common.exceptions.invalidArgument import InvalidArgument @@ -19,6 +20,7 @@ class UpdateUsersFromApsDbCli(DmCli): self.addOption('', '--config-file', dest='configFile', help='Utility configuration file.') self.addOption('', '--without-dm-db', dest='withoutDmDb', action='store_true', default=False, help='Do not use DM DB for synchronizing user information.') self.addOption('', '--use-dm-rest-api', dest='useDmRestApi', action='store_true', default=False, help='Use DM REST API for accessing user information. This option does not have any effect if --without-dm-db is set.') + self.addOption('', '--quiet', dest='quiet', action='store_true', default=False, help='Do not print any output to console.') def checkArgs(self): configFile = self.options.configFile @@ -32,10 +34,12 @@ class UpdateUsersFromApsDbCli(DmCli): dm-update-users-from-aps-db --config-file=CONFIGFILE [--without-dm-db] [--use-dm-rest-api] + [--quiet] Description: Updates all users in DM LDAP and database using information from APS DB. This command by default uses DM DB to determine whether or not user needs to be created or updated. If the --without-dm-db flag is set, DM DB will not be used nor it will be updated. """) + startTime = time.time() ConfigurationManager.getInstance().setConfigFile(self.options.configFile) LoggingManager.getInstance().configure() self.checkArgs() @@ -189,14 +193,19 @@ Description: # User is up to date continue + endTime = time.time() + runTime = endTime - startTime + self.logger.debug('Number of new DM users: %s' % (nCreatedUsers)) self.logger.debug('Number of updated DM users: %s' % (nUpdatedUsers)) self.logger.debug('Number of update errors: %s' % (nErrors)) - self.logger.debug('Completed sync process') + self.logger.debug('Completed sync process in %.3f seconds' % runTime) - print('Number of new DM users: %s' % (nCreatedUsers)) - print('Number of updated DM users: %s' % (nUpdatedUsers)) - print('Number of update errors: %s' % (nErrors)) + if not self.options.quiet: + print('Number of new DM users: %s' % (nCreatedUsers)) + print('Number of updated DM users: %s' % (nUpdatedUsers)) + print('Number of update errors: %s' % (nErrors)) + print('Sync process runtime: %.3f seconds' % (runTime)) ####################################################################### # Run command. -- GitLab