summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2009-04-23 16:33:20 +0000
committerSol Jerome <solj@ices.utexas.edu>2009-04-23 16:33:20 +0000
commit1a90ceb3e02e50a54bc0267571e0f4554201b579 (patch)
treeedd3944fe64408295901fc8b7c340d0c659fc627 /src/lib
parent4869aaf3a4cbf1034ff3c457c546aa82999fda65 (diff)
downloadbcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.tar.gz
bcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.tar.bz2
bcfg2-1a90ceb3e02e50a54bc0267571e0f4554201b579.zip
More python 2to3 updates along with pylint/code cleanups
Signed-off-by: Sol Jerome <solj@ices.utexas.edu> git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5173 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Daemon.py11
-rw-r--r--src/lib/Logger.py31
-rw-r--r--src/lib/Options.py20
3 files changed, 39 insertions, 23 deletions
diff --git a/src/lib/Daemon.py b/src/lib/Daemon.py
index bdce2c179..8798c7461 100644
--- a/src/lib/Daemon.py
+++ b/src/lib/Daemon.py
@@ -1,7 +1,8 @@
'''Bcfg2 daemon support'''
__revision__ = '$Revision$'
-import os, sys
+import os
+import sys
def daemonize(filename):
'''Do the double fork/setsession dance'''
@@ -15,9 +16,9 @@ def daemonize(filename):
# If we got this far without exceptions, there is another instance
# running. Exit gracefully.
- print "PID File (%s) exists and listed PID (%d) is active." % \
- (filename, oldpid)
- raise SystemExit, 1
+ print("PID File (%s) exists and listed PID (%d) is active." % \
+ (filename, oldpid))
+ raise SystemExit(1)
except OSError:
pidfile.close()
except (IOError, ValueError):
@@ -35,7 +36,7 @@ def daemonize(filename):
pidfile.write("%i" % pid)
pidfile.close()
except:
- print "Failed to write pid file %s" % filename
+ print("Failed to write pid file %s" % filename)
os._exit(0)
os.chdir("/")
os.umask(0)
diff --git a/src/lib/Logger.py b/src/lib/Logger.py
index bb3c703a6..129d10314 100644
--- a/src/lib/Logger.py
+++ b/src/lib/Logger.py
@@ -1,13 +1,21 @@
'''Bcfg2 logging support'''
__revision__ = '$Revision$'
-import copy, fcntl, logging, logging.handlers, math, socket, struct, sys, termios, types
+import copy
+import fcntl
+import logging
+import logging.handlers
+import math
+import socket
+import struct
+import sys
+import termios
-logging.raiseExceptions=0
+logging.raiseExceptions = 0
def print_attributes(attrib):
''' Add the attributes for an element'''
- return ' '.join(['%s="%s"' % data for data in attrib.iteritems()])
+ return ' '.join(['%s="%s"' % data for data in list(attrib.items())])
def print_text(text):
''' Add text to the output (which will need normalising '''
@@ -54,15 +62,15 @@ class TermiosFormatter(logging.Formatter):
'''format a record for display'''
returns = []
line_len = self.width
- if type(record.msg) in types.StringTypes:
+ if isinstance(record.msg, str):
for line in record.msg.split('\n'):
if len(line) <= line_len:
returns.append(line)
else:
inner_lines = int(math.floor(float(len(line)) / line_len))+1
- for i in xrange(inner_lines):
+ for i in range(inner_lines):
returns.append("%s" % (line[i*line_len:(i+1)*line_len]))
- elif type(record.msg) == types.ListType:
+ elif isinstance(record.msg, list):
if not record.msg:
return ''
record.msg.sort()
@@ -70,7 +78,7 @@ class TermiosFormatter(logging.Formatter):
columnWidth = max([len(item) for item in record.msg])
columns = int(math.floor(float(msgwidth) / (columnWidth+2)))
lines = int(math.ceil(float(len(record.msg)) / columns))
- for lineNumber in xrange(lines):
+ for lineNumber in range(lines):
indices = [idx for idx in [(colNum * lines) + lineNumber
for colNum in range(columns)] if idx < len(record.msg)]
format = (len(indices) * (" %%-%ds " % columnWidth))
@@ -84,7 +92,10 @@ class TermiosFormatter(logging.Formatter):
return '\n'.join(returns)
class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
- '''This handler fragments messages into chunks smaller than 250 characters'''
+ '''
+ This handler fragments messages into
+ chunks smaller than 250 characters
+ '''
def __init__(self, procname, path, facility):
self.procname = procname
@@ -116,7 +127,7 @@ class FragmentingSysLogHandler(logging.handlers.SysLogHandler):
except socket.error:
while True:
try:
- if isinstance(self.address, types.TupleType):
+ if isinstance(self.address, tuple):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
else:
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
@@ -150,7 +161,7 @@ def setup_logging(procname, to_console=True, to_syslog=True, syslog_facility='da
except socket.error:
logging.root.error("failed to activate syslogging")
except:
- print "Failed to activate syslogging"
+ print("Failed to activate syslogging")
if not to_file == None:
filelog = logging.FileHandler(to_file)
filelog.setLevel(logging.DEBUG)
diff --git a/src/lib/Options.py b/src/lib/Options.py
index c1c6d9df8..a3bf90604 100644
--- a/src/lib/Options.py
+++ b/src/lib/Options.py
@@ -123,20 +123,20 @@ class OptionSet(dict):
self.hm = self.buildHelpMessage()
def buildGetopt(self):
- return ''.join([opt.buildGetopt() for opt in self.values()])
+ return ''.join([opt.buildGetopt() for opt in list(self.values())])
def buildLongGetopt(self):
- return [opt.buildLongGetopt() for opt in self.values() if opt.long]
+ return [opt.buildLongGetopt() for opt in list(self.values()) if opt.long]
def buildHelpMessage(self):
if hasattr(self, 'hm'):
return self.hm
- return ' '.join([opt.buildHelpMessage() for opt in self.values()])
+ return ' '.join([opt.buildHelpMessage() for opt in list(self.values())])
def helpExit(self, msg='', code=1):
if msg:
- print msg
- print "Usage:\n %s" % self.buildHelpMessage()
+ print(msg)
+ print("Usage:\n %s" % self.buildHelpMessage())
raise SystemExit(code)
def parse(self, argv, do_getopt=True):
@@ -151,7 +151,7 @@ class OptionSet(dict):
if '-h' in argv:
self.helpExit('', 0)
self['args'] = args
- for key in self.keys():
+ for key in list(self.keys()):
if key == 'args':
continue
option = self[key]
@@ -268,13 +268,17 @@ ENCODING = Option('Encoding of cfg files', default=sys.getdefaultencoding(), cmd
OMIT_LOCK_CHECK = Option('Omit lock check', default=False, cmd='-O')
-LOGGING_FILE_PATH = Option('Set path of file log', default=None, cmd='-o', odesc='<path>', cf=('logging', 'path'))
+LOGGING_FILE_PATH = Option('Set path of file log', default=None,
+ cmd='-o', odesc='<path>', cf=('logging', 'path'))
CLIENT_SERVICE_MODE = Option('Set client service mode', default='default',
cmd='-s', odesc='<default|disabled|build>')
class OptionParser(OptionSet):
- '''OptionParser bootstraps option parsing, getting the value of the config file'''
+ '''
+ OptionParser bootstraps option parsing,
+ getting the value of the config file
+ '''
def __init__(self, args):
self.Bootstrap = OptionSet([('configfile', CFILE)])
self.Bootstrap.parse(sys.argv[1:], do_getopt=False)