summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Admin/Reports.py
diff options
context:
space:
mode:
authorJames Yang <jjyang@mcs.anl.gov>2008-07-08 16:23:31 +0000
committerJames Yang <jjyang@mcs.anl.gov>2008-07-08 16:23:31 +0000
commit796e1797d5e0fbaa89816db3bfe52637f02318de (patch)
tree391a828365254f77516b6c633a1f4205738dfdd7 /src/lib/Server/Admin/Reports.py
parent19f3fc3a5ed0bce573696044f7e58d85700dc79f (diff)
downloadbcfg2-796e1797d5e0fbaa89816db3bfe52637f02318de.tar.gz
bcfg2-796e1797d5e0fbaa89816db3bfe52637f02318de.tar.bz2
bcfg2-796e1797d5e0fbaa89816db3bfe52637f02318de.zip
Add new report command-line interface
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4761 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Admin/Reports.py')
-rw-r--r--src/lib/Server/Admin/Reports.py52
1 files changed, 52 insertions, 0 deletions
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
+
+
+