def main(arguments=None): """ Parse options, gather stats and show the results Takes optional parameter ``arguments`` which can be either command line string or list of options. This is very useful for testing purposes. Function returns a tuple of the form:: ([user_stats], team_stats) with the list of all gathered stats objects. """ try: # Parse options, initialize gathered stats options, header = Options().parse(arguments) gathered_stats = [] # Check for user email addresses (command line or config) emails = options.emails or did.base.Config().email emails = utils.split(emails, separator=re.compile(r"\s*,\s*")) users = [did.base.User(email=email) for email in emails] # Print header and prepare team stats object for data merging utils.eprint(header) team_stats = UserStats(options=options) if options.merge: utils.header("Total Report") utils.item("Users: {0}".format(len(users)), options=options) # Check individual user stats for user in users: if options.merge: utils.item(user, 1, options=options) else: utils.header(user) user_stats = UserStats(user=user, options=options) user_stats.check() team_stats.merge(user_stats) gathered_stats.append(user_stats) # Display merged team report if options.merge or options.total: if options.total: utils.header("Total Report") team_stats.show() # Return all gathered stats objects return gathered_stats, team_stats except did.base.ConfigFileError as error: utils.info( "Create at least a minimum config file {0}:\n{1}".format( did.base.Config.path(), did.base.Config.example().strip() ) ) raise except kerberos.GSSError as error: log.debug(error) raise did.base.ConfigError("Kerberos authentication failed. Try kinit.")
def main(arguments=None): """ Parse options, gather stats and show the results Takes optional parameter ``arguments`` which can be either command line string or list of options. This is very useful for testing purposes. Function returns a tuple of the form:: ([user_stats], team_stats) with the list of all gathered stats objects. """ try: # Parse options, initialize gathered stats options, header = Options().parse(arguments) gathered_stats = [] # Check for user email addresses (command line or config) emails = options.emails or did.base.Config().email emails = utils.split(emails, separator=re.compile(r"\s*,\s*")) users = [did.base.User(email=email) for email in emails] # Print header and prepare team stats object for data merging utils.eprint(header) team_stats = UserStats(options=options) if options.merge: utils.header("Total Report") utils.item("Users: {0}".format(len(users)), options=options) # Check individual user stats for user in users: if options.merge: utils.item(user, 1, options=options) else: utils.header(user) user_stats = UserStats(user=user, options=options) user_stats.check() team_stats.merge(user_stats) gathered_stats.append(user_stats) # Display merged team report if options.merge or options.total: if options.total: utils.header("Total Report") team_stats.show() # Return all gathered stats objects return gathered_stats, team_stats except did.base.ConfigFileError as error: utils.info("Create at least a minimum config file {0}:\n{1}".format( did.base.Config.path(), did.base.Config.example().strip())) raise except kerberos.GSSError as error: log.debug(error) raise did.base.ConfigError( "Kerberos authentication failed. Try kinit.")
def test_info(): from did.utils import info assert info info("something") info("no-new-line", newline=False)