diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2011-04-13 12:15:07 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2011-04-13 12:15:07 -0500 |
commit | d893117dde07ca3afcc4739245e3670178e1da08 (patch) | |
tree | 1b9bea3b05db06e74384dab5be6712e3eab55884 /src/sbin/bcfg2-reports | |
parent | 8c1a8e6af30ca282027565097ffa1cc907f7be16 (diff) | |
download | bcfg2-d893117dde07ca3afcc4739245e3670178e1da08.tar.gz bcfg2-d893117dde07ca3afcc4739245e3670178e1da08.tar.bz2 bcfg2-d893117dde07ca3afcc4739245e3670178e1da08.zip |
src/sbin: PY3K + PEP8 fixes
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/sbin/bcfg2-reports')
-rwxr-xr-x | src/sbin/bcfg2-reports | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports index 559e9fb43..c6cc766c6 100755 --- a/src/sbin/bcfg2-reports +++ b/src/sbin/bcfg2-reports @@ -26,15 +26,18 @@ from getopt import getopt import datetime import fileinput + def timecompare(client1, client2): """Compares two clients by their timestamps.""" return cmp(client1.current_interaction.timestamp, \ client2.current_interaction.timestamp) + def namecompare(client1, client2): """Compares two clients by their names.""" return cmp(client1.name, client2.name) + def statecompare(client1, client2): """Compares two clients by their states.""" clean1 = client1.current_interaction.isclean() @@ -47,6 +50,7 @@ def statecompare(client1, client2): else: return 0 + def crit_compare(criterion, client1, client2): """Compares two clients by the criteria provided in criterion.""" for crit in criterion: @@ -57,12 +61,13 @@ def crit_compare(criterion, client1, client2): comp = statecompare(client1, client2) elif crit == 'time': comp = timecompare(client1, client2) - + if comp != 0: return comp - + return 0 + def print_fields(fields, cli, max_name, entrydict): """ Prints the fields specified in fields of cli, max_name @@ -93,14 +98,15 @@ def print_fields(fields, cli, max_name, entrydict): if len(entrydict) > 0: display += " " display += str(entrydict[cli]) - print display + print(display) + def print_entry(item, max_name): fmt = ("%%-%ds " % (max_name)) fdata = item.entry.kind + ":" + item.entry.name display = fmt % (fdata) - print display - + print(display) + fields = "" sort = "" badentry = "" @@ -137,14 +143,14 @@ if expire != "": if expire == c_inst.name: if c_inst.expiration == None: c_inst.expiration = datetime.datetime.now() - print "Host expired." + print("Host expired.") else: c_inst.expiration = None - print "Host un-expired." + print("Host un-expired.") c_inst.save() elif '-h' in args: - print """Usage: bcfg2-reports [option] ... + print("""Usage: bcfg2-reports [option] ... Options and arguments (and corresponding environment variables): -a : shows all hosts, including expired hosts @@ -170,13 +176,13 @@ Options and arguments (and corresponding environment variables): (name,time,state) --sort=ARG1,ARG2,... : sorts output on ARG1,ARG2,... (name,time,state) --stale : shows hosts which haven't run in the last 24 hours -""" +""") elif singlehost != "": for c_inst in c_list: if singlehost == c_inst.name: baditems = c_inst.current_interaction.bad() if len(baditems) > 0 and ('-b' in args or '-s' in args): - print "Bad Entries:" + print("Bad Entries:") max_name = -1 for item in baditems: if len(item.entry.name) > max_name: @@ -185,14 +191,14 @@ elif singlehost != "": print_entry(item, max_name) extraitems = c_inst.current_interaction.extra() if len(extraitems) > 0 and ('-e' in args or '-s' in args): - print "Extra Entries:" + print("Extra Entries:") max_name = -1 for item in extraitems: if len(item.entry.name) > max_name: max_name = len(item.entry.name) for item in extraitems: print_entry(item, max_name) - + else: if fields == "": @@ -208,19 +214,19 @@ else: if extraentry != "": extraentry = extraentry.split(',') - + # stale hosts if '--stale' in args: for c_inst in c_list: if c_inst.current_interaction.isstale(): result.append(c_inst) # clean hosts - elif '-c' in args: + elif '-c' in args: for c_inst in c_list: if c_inst.current_interaction.isclean(): result.append(c_inst) # dirty hosts - elif '-d' in args: + elif '-d' in args: for c_inst in c_list: if not c_inst.current_interaction.isclean(): result.append(c_inst) @@ -281,7 +287,7 @@ else: if sort != "": result.sort(lambda x, y: crit_compare(sort, x, y)) - + if fields != "": for c_inst in result: if '-a' in args or c_inst.expiration == None: |