From 703fd1a0584288aa10f6661cd22fcf5123ecf6bd Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Fri, 29 Aug 2008 00:36:32 +0000 Subject: Fix bcfg2-reports to use new reporting system schema. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4897 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Reports/reports/models.py | 13 +++++++----- src/sbin/bcfg2-reports | 36 +++++++++++++++++++------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/lib/Server/Reports/reports/models.py b/src/lib/Server/Reports/reports/models.py index 333618a56..a45fb0d30 100644 --- a/src/lib/Server/Reports/reports/models.py +++ b/src/lib/Server/Reports/reports/models.py @@ -29,12 +29,12 @@ TYPE_CHOICES = ( ) class ClientManager(models.Manager): '''extended client manager functions''' - def active(self,timestamp='now'): + def active(self, timestamp='now'): '''returns a set of clients that have been created and have not yet been expired as of optional timestmamp argument. Timestamp should be a string formatted in the fashion: 2006-01-01 00:00:00''' - if timestamp=='now': + if timestamp == 'now': timestamp = datetime.now() else: print timestamp @@ -42,8 +42,11 @@ class ClientManager(models.Manager): timestamp = datetime(*strptime(timestamp, "%Y-%m-%d %H:%M:%S")[0:6]) except ValueError: return self.filter(expiration__lt=timestamp, creation__gt=timestamp); - #this is a really hacky way to return an empty QuerySet - #this should return Client.objects.none() in Django development version. + ''' + - this is a really hacky way to return an empty QuerySet + - this should return Client.objects.none() in Django + development version. + ''' return self.filter(Q(expiration__gt=timestamp) | Q(expiration__isnull=True), creation__lt=timestamp) @@ -130,7 +133,7 @@ class Interaction(models.Model): return 0 def isclean(self): - if (self.bad_items.count() == 0 and self.goodcount == self.totalcount): + if (self.bad().count() == 0 and self.goodcount == self.totalcount): #if (self.state == "good"): return True else: diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports index cd6894e13..b06fcdf37 100755 --- a/src/sbin/bcfg2-reports +++ b/src/sbin/bcfg2-reports @@ -6,7 +6,8 @@ import os, sys try: import Bcfg2.Server.Reports.settings except: - sys.stderr.write("Failed to load configuration settings. is /etc/bcfg2.conf readable?") + sys.stderr.write("Failed to load configuration settings." + "is /etc/bcfg2.conf readable?") sys.exit(1) project_directory = os.path.dirname(Bcfg2.Server.Reports.settings.__file__) @@ -24,7 +25,8 @@ import fileinput def timecompare(client1, client2): '''compares two clients by their timestamps''' - return cmp(client1.current_interaction.timestamp, client2.current_interaction.timestamp) + return cmp(client1.current_interaction.timestamp, \ + client2.current_interaction.timestamp) def namecompare(client1, client2): '''compares two clients by their names''' @@ -59,7 +61,10 @@ def crit_compare(criterion, client1, client2): return 0 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''' + ''' + prints the fields specified in fields of cli, max_name + specifies the column width of the name column + ''' fmt = '' for field in fields: if field == 'name': @@ -89,7 +94,7 @@ def print_fields(fields, cli, max_name, entrydict): def print_entry(item, max_name): fmt = ("%%-%ds " % (max_name)) - fdata = item.kind + ":" + item.name + fdata = item.entry.kind + ":" + item.entry.name display = fmt % (fdata) print display @@ -106,7 +111,8 @@ result = list() entrydict = dict() args = sys.argv[1:] -opts, pargs = getopt(args, 'ab:cde:hs:x:', ['sort=', 'fields=', 'badentry=','extraentry=']) +opts, pargs = getopt(args, 'ab:cde:hs:x:', + ['sort=', 'fields=', 'badentry=', 'extraentry=']) for option in opts: if len(option) > 0: @@ -162,16 +168,16 @@ Options and arguments (and corresponding environment variables): elif singlehost != "": for c_inst in c_list: if singlehost == c_inst.name: - baditems = c_inst.current_interaction.bad_items.all() + baditems = c_inst.current_interaction.bad() if len(baditems) > 0 and ('-b' in args or '-s' in args): print "Bad Entries:" max_name = -1 for item in baditems: - if len(item.name) > max_name: - max_name = len(item.name) + if len(item.entry.name) > max_name: + max_name = len(item.entry.name) for item in baditems: print_entry(item, max_name) - extraitems = c_inst.current_interaction.extra_items.all() + extraitems = c_inst.current_interaction.extra() if len(extraitems) > 0 and ('-e' in args or '-s' in args): print "Extra Entries:" max_name = -1 @@ -209,11 +215,11 @@ else: elif badentry != "": if len(badentry) == 1: - fileread =fileinput.input(badentry[0]) + fileread = fileinput.input(badentry[0]) for line in fileread: badentry = line.strip().split(',') for c_inst in c_list: - baditems = c_inst.current_interaction.bad_items.all() + baditems = c_inst.current_interaction.bad() for item in baditems: if item.name == badentry[1] and item.kind == badentry[0]: result.append(c_inst) @@ -224,18 +230,18 @@ else: break else: for c_inst in c_list: - baditems = c_inst.current_interaction.bad_items.all() + baditems = c_inst.current_interaction.bad() for item in baditems: if item.name == badentry[1] and item.kind == badentry[0]: result.append(c_inst) break elif extraentry != "": if len(extraentry) == 1: - fileread =fileinput.input(extraentry[0]) + fileread = fileinput.input(extraentry[0]) for line in fileread: extraentry = line.strip().split(',') for c_inst in c_list: - extraitems = c_inst.current_interaction.extra_items.all() + extraitems = c_inst.current_interaction.extra() for item in extraitems: if item.name == extraentry[1] and item.kind == extraentry[0]: result.append(c_inst) @@ -246,7 +252,7 @@ else: break else: for c_inst in c_list: - extraitems = c_inst.current_interaction.extra_items.all() + extraitems = c_inst.current_interaction.extra() for item in extraitems: if item.name == extraentry[1] and item.kind == extraentry[0]: result.append(c_inst) -- cgit v1.2.3-1-g7c22