From 796e1797d5e0fbaa89816db3bfe52637f02318de Mon Sep 17 00:00:00 2001 From: James Yang Date: Tue, 8 Jul 2008 16:23:31 +0000 Subject: Add new report command-line interface git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4761 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Admin/Reports.py | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/lib/Server/Admin/Reports.py (limited to 'src/lib/Server/Admin/Reports.py') diff --git a/src/lib/Server/Admin/Reports.py b/src/lib/Server/Admin/Reports.py new file mode 100644 index 000000000..192afd777 --- /dev/null +++ b/src/lib/Server/Admin/Reports.py @@ -0,0 +1,52 @@ +import os, sys, binascii +try: + import Bcfg2.Server.Reports.settings +except: + 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__) +project_name = os.path.basename(project_directory) +sys.path.append(os.path.join(project_directory, '..')) +project_module = __import__(project_name, '', '', ['']) +sys.path.pop() +# Set DJANGO_SETTINGS_MODULE appropriately. +os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name + +from Bcfg2.Server.Reports.reports.models import Client +import Bcfg2.Server.Admin + +def timecompare(client1, client2): + return cmp(client1.current_interaction.timestamp, \ + client2.current_interaction.timestamp) + +class Reports(Bcfg2.Server.Admin.Mode): + + def __call__(self, args): + Bcfg2.Server.Admin.Mode.__call__(self, args) + if "-h" in args: + print "Usage: " + print self.__shorthelp__ + raise SystemExit(1) + + c_list = Client.objects.all() + + result = list() + + if '-c' in args or '-d' in args: + for c_inst in c_list: + if '-c' in args and c_inst.current_interaction.isclean() or \ + '-d' in args and not \ + c_inst.current_interaction.isclean(): + result.append(c_inst) + else: + result = c_list + + if '-s' in args: + result.sort(timecompare) + + for c_inst in result: + print c_inst, c_inst.current_interaction.timestamp + + + -- cgit v1.2.3-1-g7c22