From 121767472c5a4857454eeee2555c9f01522bf93b Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Wed, 16 Jul 2008 20:09:10 +0000 Subject: code walkthrough results git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4797 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-reports | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src/sbin') diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports index 8321a7493..fa4d13ed7 100755 --- a/src/sbin/bcfg2-reports +++ b/src/sbin/bcfg2-reports @@ -58,22 +58,34 @@ def crit_compare(criterion, client1, client2): return 0 +def print_fields(fields, cli, max_name, entrydict): + fdata = tuple([getattr(cli, field) for field in fields]) + display = fmt % fdata + def print_fields(fields, cli, max_name, entrydict): '''prints the fields specified in fields of cli, max_name specifies the column width of the name column''' - display = "" - if 'name' in fields: - display += cli.name - for i in range(len(cli.name), max_name): - display += " " - if 'time' in fields: - display += " " - display += str(cli.current_interaction.timestamp) - if 'state' in fields: - display += " " - if cli.current_interaction.isclean(): - display += "clean" + fmt = '' + for field in fields: + if field == 'name': + fmt += ("%%-%ds " % (max_name)) + else: + fmt += "%s " + fdata = [] + for field in fields: + if field == 'time': + fdata.append(str(cli.current_interaction.timestamp)) + elif field == 'state': + if cli.current_interaction.isclean(): + fdata.append("clean") + else: + fdata.append("dirty") else: - display += "dirty" + try: + fdata.append(getattr(cli, field)) + except: + fdata.append("N/A") + + display = fmt % tuple(fdata) if len(entrydict) > 0: display += " " display += str(entrydict[cli]) @@ -145,7 +157,7 @@ Options and arguments (and corresponding environment variables): argument ARG1 is given, then KIND,NAME pairs will be read from a file of name ARG1 --fields=ARG1,ARG2,... : only displays the fields ARG1,ARG2,... - (name,time,state)' + (name,time,state) --sort=ARG1,ARG2,... : sorts output on ARG1,ARG2,... (name,time,state)''' elif singlehost != "": for c_inst in c_list: -- cgit v1.2.3-1-g7c22