summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Reports/importscript.py
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-04 13:15:14 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-06 19:35:21 -0500
commitf124f7f6ee5dc8710ba354e0e978a82245c11fbf (patch)
treeb9c39fa7b1350f58da01a0e06093c38b1a04a99b /src/lib/Server/Reports/importscript.py
parent8f4a2394638912b000682e2211723e4a644915e1 (diff)
downloadbcfg2-f124f7f6ee5dc8710ba354e0e978a82245c11fbf.tar.gz
bcfg2-f124f7f6ee5dc8710ba354e0e978a82245c11fbf.tar.bz2
bcfg2-f124f7f6ee5dc8710ba354e0e978a82245c11fbf.zip
Reports: PY3K + PEP8 fixes
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src/lib/Server/Reports/importscript.py')
-rwxr-xr-xsrc/lib/Server/Reports/importscript.py116
1 files changed, 69 insertions, 47 deletions
diff --git a/src/lib/Server/Reports/importscript.py b/src/lib/Server/Reports/importscript.py
index cdfd8079c..86e176394 100755
--- a/src/lib/Server/Reports/importscript.py
+++ b/src/lib/Server/Reports/importscript.py
@@ -1,8 +1,13 @@
#! /usr/bin/env python
-'''Imports statistics.xml and clients.xml files in to database backend for new statistics engine'''
+"""
+Imports statistics.xml and clients.xml files in to database backend for
+new statistics engine
+"""
__revision__ = '$Revision$'
-import os, sys, binascii
+import binascii
+import os
+import sys
try:
import Bcfg2.Server.Reports.settings
except Exception, e:
@@ -29,16 +34,17 @@ import logging
import Bcfg2.Logger
import platform
+
def build_reason_kwargs(r_ent):
- binary_file=False
+ binary_file = False
if r_ent.get('current_bfile', False):
- binary_file=True
+ binary_file = True
rc_diff = r_ent.get('current_bfile')
- if len(rc_diff) > 1024*1024:
+ if len(rc_diff) > 1024 * 1024:
rc_diff = ''
elif len(rc_diff) == 0:
# No point in flagging binary if we have no data
- binary_file=False
+ binary_file = False
elif r_ent.get('current_bdiff', False):
rc_diff = binascii.a2b_base64(r_ent.get('current_bdiff'))
elif r_ent.get('current_diff', False):
@@ -57,7 +63,7 @@ def build_reason_kwargs(r_ent):
current_to=r_ent.get('current_to', default=""),
version=r_ent.get('version', default=""),
current_version=r_ent.get('current_version', default=""),
- current_exists=r_ent.get('current_exists', default="True").capitalize()=="True",
+ current_exists=r_ent.get('current_exists', default="True").capitalize() == "True",
current_diff=rc_diff,
is_binary=binary_file)
@@ -75,7 +81,7 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
name = node.get('name')
c_inst, created = Client.objects.get_or_create(name=name)
if vlevel > 0:
- logger.info("Client %s added to db" % name)
+ logger.info("Client %s added to db" % name)
clients[name] = c_inst
try:
pingability[name]
@@ -93,24 +99,30 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
continue
else:
newint = Interaction(client=c_inst,
- timestamp = timestamp,
- state = statistics.get('state', default="unknown"),
- repo_rev_code = statistics.get('revision',default="unknown"),
- client_version = statistics.get('client_version',default="unknown"),
- goodcount = statistics.get('good',default="0"),
- totalcount = statistics.get('total',default="0"),
- server = location)
+ timestamp=timestamp,
+ state=statistics.get('state',
+ default="unknown"),
+ repo_rev_code=statistics.get('revision',
+ default="unknown"),
+ client_version=statistics.get('client_version',
+ default="unknown"),
+ goodcount=statistics.get('good',
+ default="0"),
+ totalcount=statistics.get('total',
+ default="0"),
+ server=location)
newint.save()
current_interaction = newint
if vlevel > 0:
- logger.info("Interaction for %s at %s with id %s INSERTED in to db"%(c_inst.id,
+ logger.info("Interaction for %s at %s with id %s INSERTED in to db" % (c_inst.id,
timestamp, current_interaction.id))
-
- counter_fields = { TYPE_CHOICES[0]: 0, TYPE_CHOICES[1]: 0, TYPE_CHOICES[2]: 0 }
+ counter_fields = {TYPE_CHOICES[0]: 0,
+ TYPE_CHOICES[1]: 0,
+ TYPE_CHOICES[2]: 0}
pattern = [('Bad/*', TYPE_CHOICES[0]),
('Extra/*', TYPE_CHOICES[2]),
- ('Modified/*', TYPE_CHOICES[1]),]
+ ('Modified/*', TYPE_CHOICES[1])]
for (xpath, type) in pattern:
for x in statistics.findall(xpath):
counter_fields[type] = counter_fields[type] + 1
@@ -131,12 +143,12 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
except Exception, ex:
logger.error("Failed to create reason for %s: %s" % (x.get('name'), ex))
rr = Reason(current_exists=x.get('current_exists',
- default="True").capitalize()=="True")
+ default="True").capitalize() == "True")
rr.save()
entry, created = Entries.objects.get_or_create(\
name=x.get('name'), kind=x.tag)
-
+
Entries_interactions(entry=entry, reason=rr,
interaction=current_interaction,
type=type[0]).save()
@@ -151,7 +163,7 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
mperfs = []
for times in statistics.findall('OpStamps'):
- for metric, value in times.items():
+ for metric, value in list(times.items()):
mmatch = []
if not quick:
mmatch = Performance.objects.filter(metric=metric, value=value)
@@ -164,7 +176,7 @@ def load_stats(cdata, sdata, vlevel, logger, quick=False, location=''):
mperfs.append(mperf)
current_interaction.performance_items.add(*mperfs)
- for key in pingability.keys():
+ for key in list(pingability.keys()):
if key not in clients:
continue
try:
@@ -191,27 +203,32 @@ if __name__ == '__main__':
clientpath = False
statpath = False
syslog = False
-
+
try:
- opts, args = getopt(argv[1:], "hvudc:s:CS", ["help", "verbose", "updates" ,
- "debug", "clients=", "stats=",
- "config=", "syslog"])
+ opts, args = getopt(argv[1:], "hvudc:s:CS", ["help",
+ "verbose",
+ "updates",
+ "debug",
+ "clients=",
+ "stats=",
+ "config=",
+ "syslog"])
except GetoptError, mesg:
# print help information and exit:
- print "%s\nUsage:\nimportscript.py [-h] [-v] [-u] [-d] [-S] [-C bcfg2 config file] [-c clients-file] [-s statistics-file]" % (mesg)
- raise SystemExit, 2
+ print("%s\nUsage:\nimportscript.py [-h] [-v] [-u] [-d] [-S] [-C bcfg2 config file] [-c clients-file] [-s statistics-file]" % (mesg))
+ raise SystemExit(2)
for o, a in opts:
if o in ("-h", "--help"):
- print "Usage:\nimportscript.py [-h] [-v] -c <clients-file> -s <statistics-file> \n"
- print "h : help; this message"
- print "v : verbose; print messages on record insertion/skip"
- print "u : updates; print status messages as items inserted semi-verbose"
- print "d : debug; print most SQL used to manipulate database"
- print "C : path to bcfg2.conf config file."
- print "c : clients.xml file"
- print "s : statistics.xml file"
- print "S : syslog; output to syslog"
+ print("Usage:\nimportscript.py [-h] [-v] -c <clients-file> -s <statistics-file> \n")
+ print("h : help; this message")
+ print("v : verbose; print messages on record insertion/skip")
+ print("u : updates; print status messages as items inserted semi-verbose")
+ print("d : debug; print most SQL used to manipulate database")
+ print("C : path to bcfg2.conf config file.")
+ print("c : clients.xml file")
+ print("s : statistics.xml file")
+ print("S : syslog; output to syslog")
raise SystemExit
if o in ["-C", "--config"]:
cpath = a
@@ -243,28 +260,33 @@ if __name__ == '__main__':
try:
statpath = "%s/etc/statistics.xml" % cf.get('server', 'repository')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- print "Could not read bcfg2.conf; exiting"
- raise SystemExit, 1
+ print("Could not read bcfg2.conf; exiting")
+ raise SystemExit(1)
try:
statsdata = XML(open(statpath).read())
except (IOError, XMLSyntaxError):
- print("StatReports: Failed to parse %s"%(statpath))
- raise SystemExit, 1
+ print("StatReports: Failed to parse %s" % (statpath))
+ raise SystemExit(1)
if not clientpath:
try:
clientspath = "%s/Metadata/clients.xml" % \
cf.get('server', 'repository')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
- print "Could not read bcfg2.conf; exiting"
- raise SystemExit, 1
+ print("Could not read bcfg2.conf; exiting")
+ raise SystemExit(1)
try:
clientsdata = XML(open(clientspath).read())
except (IOError, XMLSyntaxError):
- print("StatReports: Failed to parse %s"%(clientspath))
- raise SystemExit, 1
+ print("StatReports: Failed to parse %s" % (clientspath))
+ raise SystemExit(1)
q = '-O3' in sys.argv
# Be sure the database is ready for new schema
update_database()
- load_stats(clientsdata, statsdata, verb, logger, quick=q, location=platform.node())
+ load_stats(clientsdata,
+ statsdata,
+ verb,
+ logger,
+ quick=q,
+ location=platform.node())