summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Client/Frame.py59
-rw-r--r--src/lib/Client/Tools/Encap.py8
-rw-r--r--src/lib/Client/Tools/POSIX.py73
-rw-r--r--src/lib/Client/Tools/RPMng.py43
-rw-r--r--src/lib/Client/Tools/RcUpdate.py22
-rw-r--r--src/lib/Client/Tools/YUMng.py15
-rw-r--r--src/lib/Client/Tools/__init__.py14
-rwxr-xr-xsrc/lib/Client/Tools/rpmtools.py72
-rw-r--r--src/lib/Client/XML.py6
9 files changed, 175 insertions, 137 deletions
diff --git a/src/lib/Client/Frame.py b/src/lib/Client/Frame.py
index dca4516f6..9be8a2343 100644
--- a/src/lib/Client/Frame.py
+++ b/src/lib/Client/Frame.py
@@ -4,7 +4,8 @@ installs entries, and generates statistics
"""
__revision__ = '$Revision$'
-import logging, time, types
+import logging
+import time
import Bcfg2.Client.Tools
def cmpent(ent1, ent2):
@@ -27,6 +28,7 @@ def promptFilter(prompt, entries):
if raw_input(iprompt) in ['y', 'Y']:
ret.append(entry)
except:
+ print("Error while reading input")
continue
return ret
@@ -56,13 +58,13 @@ class Frame:
self.logger = logging.getLogger("Bcfg2.Client.Frame")
for driver in drivers[:]:
if driver not in Bcfg2.Client.Tools.drivers and \
- isinstance(driver, types.StringType):
+ isinstance(driver, str):
self.logger.error("Tool driver %s is not available" % driver)
drivers.remove(driver)
tclass = {}
for tool in drivers:
- if not isinstance(tool, types.StringType):
+ if not isinstance(tool, str):
tclass[time.time()] = tool
tool_class = "Bcfg2.Client.Tools.%s" % tool
try:
@@ -75,7 +77,7 @@ class Frame:
self.logger.error("Tool %s unexpectedly failed to load" % tool,
exc_info=1)
- for tool in tclass.values():
+ for tool in list(tclass.values()):
try:
self.tools.append(tool(self.logger, setup, config))
except Bcfg2.Client.Tools.toolInstantiationError:
@@ -135,10 +137,14 @@ class Frame:
return ret
elif name in self.__dict__:
return self.__dict__[name]
- raise AttributeError, name
+ raise AttributeError(name)
def Inventory(self):
- '''Verify all entries, find extra entries, and build up workqueues'''
+ '''
+ Verify all entries,
+ find extra entries,
+ and build up workqueues
+ '''
# initialize all states
for struct in self.config.getchildren():
for entry in struct.getchildren():
@@ -157,13 +163,17 @@ class Frame:
if self.setup['remove'] == 'all':
self.removal = self.extra
elif self.setup['remove'] == 'services':
- self.removal = [entry for entry in self.extra if entry.tag == 'Service']
+ self.removal = [entry for entry in self.extra \
+ if entry.tag == 'Service']
elif self.setup['remove'] == 'packages':
- self.removal = [entry for entry in self.extra if entry.tag == 'Package']
+ self.removal = [entry for entry in self.extra \
+ if entry.tag == 'Package']
- candidates = [entry for entry in self.states if not self.states[entry]]
- self.whitelist = [entry for entry in self.states if not self.states[entry]]
- # Need to process decision stuff early, so that dryrun mode works with it
+ candidates = [entry for entry in self.states \
+ if not self.states[entry]]
+ self.whitelist = [entry for entry in self.states \
+ if not self.states[entry]]
+ # Need to process decision stuff early so that dryrun mode works with it
if self.setup['decision'] == 'whitelist':
dwl = self.setup['decision_list']
w_to_rem = [e for e in self.whitelist \
@@ -171,7 +181,8 @@ class Frame:
if w_to_rem:
self.logger.info("In whitelist mode: suppressing installation of:")
self.logger.info(["%s:%s" % (e.tag, e.get('name')) for e in w_to_rem])
- self.whitelist = [x for x in self.whitelist if x not in w_to_rem]
+ self.whitelist = [x for x in self.whitelist \
+ if x not in w_to_rem]
elif self.setup['decision'] == 'blacklist':
b_to_rem = [e for e in self.whitelist \
@@ -304,12 +315,12 @@ class Frame:
def CondDisplayState(self, phase):
'''Conditionally print tracing information'''
self.logger.info('\nPhase: %s' % phase)
- self.logger.info('Correct entries:\t%d' % self.states.values().count(True))
- self.logger.info('Incorrect entries:\t%d' % self.states.values().count(False))
- if phase == 'final' and self.states.values().count(False):
+ self.logger.info('Correct entries:\t%d' % list(self.states.values()).count(True))
+ self.logger.info('Incorrect entries:\t%d' % list(self.states.values()).count(False))
+ if phase == 'final' and list(self.states.values()).count(False):
self.logger.info(["%s:%s" % (entry.tag, entry.get('name')) for \
entry in self.states if not self.states[entry]])
- self.logger.info('Total managed entries:\t%d' % len(self.states.values()))
+ self.logger.info('Total managed entries:\t%d' % len(list(self.states.values())))
self.logger.info('Unmanaged entries:\t%d' % len(self.extra))
if phase == 'final' and self.setup['extra']:
self.logger.info(["%s:%s" % (entry.tag, entry.get('name')) \
@@ -317,7 +328,7 @@ class Frame:
self.logger.info("")
- if ((self.states.values().count(False) == 0) and not self.extra):
+ if ((list(self.states.values()).count(False) == 0) and not self.extra):
self.logger.info('All entries correct.')
def ReInventory(self):
@@ -345,13 +356,15 @@ class Frame:
def GenerateStats(self):
'''Generate XML summary of execution statistics'''
feedback = Bcfg2.Client.XML.Element("upload-statistics")
- stats = Bcfg2.Client.XML.SubElement(feedback, \
- 'Statistics', total=str(len(self.states)),
- client_version=__revision__, version='2.0',
+ stats = Bcfg2.Client.XML.SubElement(feedback,
+ 'Statistics',
+ total=str(len(self.states)),
+ client_version=__revision__,
+ version='2.0',
revision=self.config.get('revision', '-1'))
- good = len([key for key, val in self.states.iteritems() if val])
+ good = len([key for key, val in list(self.states.items()) if val])
stats.set('good', str(good))
- if len([key for key, val in self.states.iteritems() if not val]) == 0:
+ if len([key for key, val in list(self.states.items()) if not val]) == 0:
stats.set('state', 'clean')
else:
stats.set('state', 'dirty')
@@ -368,7 +381,7 @@ class Frame:
timeinfo = Bcfg2.Client.XML.Element("OpStamps")
feedback.append(stats)
- for (event, timestamp) in self.times.iteritems():
+ for (event, timestamp) in list(self.times.items()):
timeinfo.set(event, str(timestamp))
stats.append(timeinfo)
return feedback
diff --git a/src/lib/Client/Tools/Encap.py b/src/lib/Client/Tools/Encap.py
index 520689da2..d547dee98 100644
--- a/src/lib/Client/Tools/Encap.py
+++ b/src/lib/Client/Tools/Encap.py
@@ -2,7 +2,9 @@
__revision__ = '$Revision$'
-import Bcfg2.Client.Tools, glob, re
+import glob
+import re
+import Bcfg2.Client.Tools
class Encap(Bcfg2.Client.Tools.PkgTool):
'''Support for Encap packages'''
@@ -25,9 +27,9 @@ class Encap(Bcfg2.Client.Tools.PkgTool):
if match:
self.installed[match.group('name')] = match.group('version')
else:
- print "Failed to split name %s" % pkg
+ print("Failed to split name %s" % pkg)
self.logger.debug("Encap.py: RefreshPackages: self.installed.keys() are:")
- self.logger.debug("%s" % self.installed.keys())
+ self.logger.debug("%s" % list(self.installed.keys()))
def VerifyPackage(self, entry, _):
'''Verify Package status for entry'''
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index 17bb0a4f4..1c7899ac8 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -4,20 +4,28 @@ __revision__ = '$Revision$'
from stat import S_ISVTX, S_ISGID, S_ISUID, S_IXUSR, S_IWUSR, S_IRUSR, S_IXGRP
from stat import S_IWGRP, S_IRGRP, S_IXOTH, S_IWOTH, S_IROTH, ST_MODE, S_ISDIR
from stat import S_IFREG, ST_UID, ST_GID, S_ISREG, S_IFDIR, S_ISLNK, ST_MTIME
-
-import binascii, difflib, grp, os, pwd, string, logging, time
+import binascii
+import difflib
+import grp
+import logging
+import os
+import pwd
+import string
+import time
import Bcfg2.Client.Tools
def calcPerms(initial, perms):
'''This compares ondisk permissions with specified ones'''
- pdisp = [{1:S_ISVTX, 2:S_ISGID, 4:S_ISUID}, {1:S_IXUSR, 2:S_IWUSR, 4:S_IRUSR},
- {1:S_IXGRP, 2:S_IWGRP, 4:S_IRGRP}, {1:S_IXOTH, 2:S_IWOTH, 4:S_IROTH}]
+ pdisp = [{1:S_ISVTX, 2:S_ISGID, 4:S_ISUID},
+ {1:S_IXUSR, 2:S_IWUSR, 4:S_IRUSR},
+ {1:S_IXGRP, 2:S_IWGRP, 4:S_IRGRP},
+ {1:S_IXOTH, 2:S_IWOTH, 4:S_IROTH}]
tempperms = initial
if len(perms) == 3:
perms = '0%s' % (perms)
pdigits = [int(perms[digit]) for digit in range(4)]
for index in range(4):
- for (num, perm) in pdisp[index].iteritems():
+ for (num, perm) in list(pdisp[index].items()):
if pdigits[index] & num:
tempperms |= perm
return tempperms
@@ -25,7 +33,10 @@ def calcPerms(initial, perms):
log = logging.getLogger('posix')
def normUid(entry):
- '''This takes a user name or uid and returns the corresponding uid or False'''
+ '''
+ This takes a user name or uid and
+ returns the corresponding uid or False
+ '''
try:
try:
return int(entry.get('owner'))
@@ -36,7 +47,10 @@ def normUid(entry):
return False
def normGid(entry):
- '''This takes a group name or gid and returns the corresponding gid or False'''
+ '''
+ This takes a group name or gid and
+ returns the corresponding gid or False
+ '''
try:
try:
return int(entry.get('group'))
@@ -62,8 +76,8 @@ def isString(strng):
class POSIX(Bcfg2.Client.Tools.Tool):
'''POSIX File support code'''
name = 'POSIX'
- __handles__ = [('ConfigFile', None), ('Directory', None), ('Permissions', None), \
- ('SymLink', None)]
+ __handles__ = [('ConfigFile', None), ('Directory', None),
+ ('Permissions', None), ('SymLink', None)]
__req__ = {'ConfigFile': ['name', 'owner', 'group', 'perms'],
'Directory': ['name', 'owner', 'group', 'perms'],
'Permissions': ['name', 'owner', 'group', 'perms'],
@@ -134,7 +148,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
owner = str(ondisk[ST_UID])
group = str(ondisk[ST_GID])
except (OSError, KeyError):
- self.logger.error('User/Group resolution failed for path %s' % (entry.get('name')))
+ self.logger.error('User/Group resolution failed for path %s' % \
+ entry.get('name'))
owner = 'root'
group = '0'
finfo = os.stat(entry.get('name'))
@@ -158,7 +173,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
ex_ents = [e for e in entries if e not in modlist]
if ex_ents:
pruneTrue = False
- self.logger.debug("Directory %s contains extra entries:" % entry.get('name'))
+ self.logger.debug("Directory %s contains extra entries:" % \
+ entry.get('name'))
self.logger.debug(ex_ents)
nqtext = entry.get('qtext', '') + '\n'
nqtext += "Directory %s contains extra entries:" % entry.get('name')
@@ -171,7 +187,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
if not pTrue:
if owner != str(normUid(entry)):
entry.set('current_owner', owner)
- self.logger.debug("%s %s ownership wrong" % (entry.tag, entry.get('name')))
+ self.logger.debug("%s %s ownership wrong" % \
+ (entry.tag, entry.get('name')))
nqtext = entry.get('qtext', '') + '\n'
nqtext += "%s owner wrong. is %s should be %s" % \
(entry.get('name'), owner, entry.get('owner'))
@@ -213,7 +230,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
try:
fmode = os.lstat(entry.get('name'))
if not S_ISDIR(fmode[ST_MODE]):
- self.logger.debug("Found a non-directory entry at %s" % (entry.get('name')))
+ self.logger.debug("Found a non-directory entry at %s" % \
+ (entry.get('name')))
try:
os.unlink(entry.get('name'))
exists = False
@@ -221,7 +239,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
self.logger.info("Failed to unlink %s" % (entry.get('name')))
return False
else:
- self.logger.debug("Found a pre-existing directory at %s" % (entry.get('name')))
+ self.logger.debug("Found a pre-existing directory at %s" % \
+ (entry.get('name')))
exists = True
except OSError:
# stat failed
@@ -234,7 +253,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
os.stat(parent)
except:
self.logger.debug('Creating parent path for directory %s' % (entry.get('name')))
- for idx in xrange(len(parent.split('/')[:-1])):
+ for idx in range(len(parent.split('/')[:-1])):
current = '/'+'/'.join(parent.split('/')[1:2+idx])
try:
sloc = os.stat(current)
@@ -254,7 +273,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
try:
os.mkdir(entry.get('name'))
except OSError:
- self.logger.error('Failed to create directory %s' % (entry.get('name')))
+ self.logger.error('Failed to create directory %s' % \
+ (entry.get('name')))
return False
if entry.get('prune', 'false') == 'true' and entry.get("qtest"):
for pname in entry.get("qtest").split(":"):
@@ -280,7 +300,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
os.chmod(entry.get('name'), calcPerms(S_IFDIR, entry.get('perms')))
return True
except (OSError, KeyError):
- self.logger.error('Permission fixup failed for %s' % (entry.get('name')))
+ self.logger.error('Permission fixup failed for %s' % \
+ (entry.get('name')))
return False
def gatherCurrentData(self, entry):
@@ -316,7 +337,8 @@ class POSIX(Bcfg2.Client.Tools.Tool):
tempdata = ''
else:
if entry.text == None:
- self.logger.error("Cannot verify incomplete ConfigFile %s" % (entry.get('name')))
+ self.logger.error("Cannot verify incomplete ConfigFile %s" % \
+ (entry.get('name')))
return False
tempdata = entry.text
if type(tempdata) == unicode:
@@ -324,10 +346,11 @@ class POSIX(Bcfg2.Client.Tools.Tool):
try:
content = open(entry.get('name')).read()
except IOError, error:
- self.logger.error("Failed to read %s: %s" % (error.filename, error.strerror))
+ self.logger.error("Failed to read %s: %s" % \
+ (error.filename, error.strerror))
return False
- # comparison should be done with fingerprints or md5sum so it would be faster
- # for big binary files
+ # comparison should be done with fingerprints or
+ # md5sum so it would be faster for big binary files
contentStatus = content == tempdata
if not contentStatus:
if tbin or not isString(content):
@@ -343,10 +366,12 @@ class POSIX(Bcfg2.Client.Tools.Tool):
now = time.time()
rawdiff.append(x)
if now - start > 5 and not longtime:
- self.logger.info("Diff of %s taking a long time" % (entry.get('name')))
+ self.logger.info("Diff of %s taking a long time" % \
+ (entry.get('name')))
longtime = True
elif now - start > 30:
- self.logger.error("Diff of %s took too long; giving up" % (entry.get('name')))
+ self.logger.error("Diff of %s took too long; giving up" % \
+ (entry.get('name')))
do_diff = False
break
if do_diff:
@@ -450,5 +475,5 @@ class POSIX(Bcfg2.Client.Tools.Tool):
if err.errno == 13:
self.logger.info("Failed to open %s for writing" % (entry.get('name')))
else:
- print err
+ print(err)
return False
diff --git a/src/lib/Client/Tools/RPMng.py b/src/lib/Client/Tools/RPMng.py
index a0d1e8190..4025a2cbb 100644
--- a/src/lib/Client/Tools/RPMng.py
+++ b/src/lib/Client/Tools/RPMng.py
@@ -8,11 +8,6 @@ import rpm
import rpmtools
import Bcfg2.Client.Tools
-try:
- set
-except NameError:
- from sets import Set as set
-
class RPMng(Bcfg2.Client.Tools.PkgTool):
'''Support for RPM packages'''
name = 'RPMng'
@@ -59,7 +54,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
self.installOnlyPkgs = ['kernel', 'kernel-bigmem', 'kernel-enterprise', 'kernel-smp',
'kernel-modules', 'kernel-debug', 'kernel-unsupported',
'kernel-source', 'kernel-devel', 'kernel-default',
- 'kernel-largesmp-devel', 'kernel-largesmp', 'kernel-xen',
+ 'kernel-largesmp-devel', 'kernel-largesmp', 'kernel-xen',
'gpg-pubkey']
if 'gpg-pubkey' not in self.installOnlyPkgs:
self.installOnlyPkgs.append('gpg-pubkey')
@@ -131,11 +126,11 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
e.g.
- self.installed['foo'] = [ {'name':'foo', 'epoch':None,
- 'version':'1', 'release':2,
+ self.installed['foo'] = [ {'name':'foo', 'epoch':None,
+ 'version':'1', 'release':2,
'arch':'i386'},
- {'name':'foo', 'epoch':None,
- 'version':'1', 'release':2,
+ {'name':'foo', 'epoch':None,
+ 'version':'1', 'release':2,
'arch':'x86_64'} ]
'''
self.installed = {}
@@ -146,8 +141,8 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
for nevra in rpmtools.rpmpackagelist(refresh_ts):
self.installed.setdefault(nevra['name'], []).append(nevra)
if self.setup['debug']:
- print "The following package instances are installed:"
- for name, instances in self.installed.iteritems():
+ print("The following package instances are installed:")
+ for name, instances in list(self.installed.items()):
self.logger.debug(" " + name)
for inst in instances:
self.logger.debug(" %s" %self.str_evra(inst))
@@ -171,7 +166,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
'verify_fail': True|False,
'pkg': <Package Element Object>,
'modlist': [ <filename>, ... ],
- 'verify' : [ <rpm --verify results> ]
+ 'verify' : [ <rpm --verify results> ]
}, ......
}
@@ -184,7 +179,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
if instances == []:
# We have an old style no Instance entry. Convert it to new style.
instance = Bcfg2.Client.XML.SubElement(entry, 'Package')
- for attrib in entry.attrib.keys():
+ for attrib in list(entry.attrib.keys()):
instance.attrib[attrib] = entry.attrib[attrib]
if self.pkg_checks == 'true' and entry.get('pkg_checks', 'true') == 'true':
if 'any' in [entry.get('version'), pinned_version]:
@@ -216,7 +211,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
self.instance_status[inst]['version_fail'] = False
if inst.tag == 'Package' and len(self.installed[entry.get('name')]) > 1:
self.logger.error("WARNING: Multiple instances of package %s are installed." % \
- (entry.get('name')))
+ (entry.get('name')))
for pkg in self.installed[entry.get('name')]:
if inst.get('version') == 'any' or self.pkg_vr_equal(inst, pkg) \
or self.inst_evra_equal(inst, pkg):
@@ -358,7 +353,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
if instance_fail == True:
self.logger.debug("*** Instance %s failed RPM verification ***" % \
- self.str_evra(inst))
+ self.str_evra(inst))
qtext_versions = qtext_versions + 'R(%s) ' % self.str_evra(inst)
self.modlists[entry] = modlist
@@ -417,7 +412,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
if bcfg2_versions != '':
entry.set('version', bcfg2_versions)
entry.set('qtext', "Install Package %s Instance(s) %s? (y/N) " % \
- (entry.get('name'), qtext_versions))
+ (entry.get('name'), qtext_versions))
return False
return True
@@ -508,8 +503,8 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
fix = True
else:
self.logger.debug('Installed Action for %s %s is to not install' % \
- (inst_status.get('pkg').get('name'),
- self.str_evra(instance)))
+ (inst_status.get('pkg').get('name'),
+ self.str_evra(instance)))
elif inst_status.get('version_fail', False) == True:
if instance.get('version_fail_action', 'upgrade') == "upgrade" and \
@@ -517,8 +512,8 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
fix = True
else:
self.logger.debug('Version Fail Action for %s %s is to not upgrade' % \
- (inst_status.get('pkg').get('name'),
- self.str_evra(instance)))
+ (inst_status.get('pkg').get('name'),
+ self.str_evra(instance)))
elif inst_status.get('verify_fail', False) == True and self.name == "RPMng":
# yum can't reinstall packages so only do this for rpm.
@@ -858,7 +853,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
packages = [entry.get('name') for entry in self.getSupportedEntries()]
extras = []
- for (name, instances) in self.installed.iteritems():
+ for (name, instances) in list(self.installed.items()):
if name not in packages:
extra_entry = Bcfg2.Client.XML.Element('Package', name=name, type=self.pkgtype)
for installed_inst in instances:
@@ -896,7 +891,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
if not_found == True:
# Extra package.
self.logger.info("Extra InstallOnlyPackage %s %s." % \
- (name, self.str_evra(installed_inst)))
+ (name, self.str_evra(installed_inst)))
tmp_entry = Bcfg2.Client.XML.SubElement(extra_entry, 'Instance', \
version = installed_inst.get('version'), \
release = installed_inst.get('release'))
@@ -915,7 +910,7 @@ class RPMng(Bcfg2.Client.Tools.PkgTool):
break
if not_found:
self.logger.info("Extra Normal Package Instance %s %s" % \
- (name, self.str_evra(installed_inst)))
+ (name, self.str_evra(installed_inst)))
tmp_entry = Bcfg2.Client.XML.SubElement(extra_entry, 'Instance', \
version = installed_inst.get('version'), \
release = installed_inst.get('release'))
diff --git a/src/lib/Client/Tools/RcUpdate.py b/src/lib/Client/Tools/RcUpdate.py
index c230544fe..88423925b 100644
--- a/src/lib/Client/Tools/RcUpdate.py
+++ b/src/lib/Client/Tools/RcUpdate.py
@@ -1,7 +1,9 @@
'''This is rc-update support'''
-__revision__ = '$Revision$'
+__revision__ = '$Revision: 4991 $'
-import Bcfg2.Client.Tools, Bcfg2.Client.XML, commands, os
+import os
+import Bcfg2.Client.Tools
+import Bcfg2.Client.XML
class RcUpdate(Bcfg2.Client.Tools.SvcTool):
'''RcUpdate support for Bcfg2'''
@@ -15,17 +17,9 @@ class RcUpdate(Bcfg2.Client.Tools.SvcTool):
Verify Service status for entry.
Assumes we run in the "default" runlevel.
'''
- # mrj - i think this should be:
- # rc = self.cmd.run('/bin/rc-status | \
- # grep %s | \
- # grep started"' % entry.attrib['name'])
- #
- # ...but as i can't figure out a way to
- # test that right now, i'll do the one
- # that works in python's interactive interpreter.
- rc = commands.getoutput('/bin/rc-status -s | grep %s | grep started' % \
- entry.get('name'))
- status = len(rc) > 0
+ rc, output = self.cmd.run('/bin/rc-status | grep %s | grep started' % \
+ entry.attrib['name'])
+ status = rc > 0
if not status:
# service is off
@@ -59,7 +53,7 @@ class RcUpdate(Bcfg2.Client.Tools.SvcTool):
def FindExtra(self):
'''Locate extra rc-update Services'''
allsrv = [line.split()[0] for line in \
- self.cmd.run("/bin/rc-status -s | grep started")[1]]
+ self.cmd.run("/bin/rc-status | grep started")[1]]
self.logger.debug('Found active services:')
self.logger.debug(allsrv)
specified = [srv.get('name') for srv in self.getSupportedEntries()]
diff --git a/src/lib/Client/Tools/YUMng.py b/src/lib/Client/Tools/YUMng.py
index 23ec4fb8d..61233b0df 100644
--- a/src/lib/Client/Tools/YUMng.py
+++ b/src/lib/Client/Tools/YUMng.py
@@ -1,16 +1,13 @@
'''This provides bcfg2 support for yum'''
__revision__ = '$Revision: $'
+import ConfigParser
+import copy
+import os.path
+import sys
+import yum
import Bcfg2.Client.XML
import Bcfg2.Client.Tools.RPMng
-import ConfigParser, sys, os.path, copy
-
-import yum
-
-try:
- set
-except NameError:
- from sets import Set as set
YAD = True
CP = ConfigParser.ConfigParser()
@@ -81,7 +78,7 @@ class YUMng(Bcfg2.Client.Tools.RPMng.RPMng):
if entry.get('name') in self.yum_avail:
# installed but out of date
data.update(self.yum_avail[entry.get('name')])
- for (arch, (epoch, vers, rel)) in data.iteritems():
+ for (arch, (epoch, vers, rel)) in list(data.items()):
Bcfg2.Client.XML.SubElement(entry, "Instance",
name=entry.get('name'),
version=vers, arch=arch,
diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py
index e5dedf3aa..e03ceab3a 100644
--- a/src/lib/Client/Tools/__init__.py
+++ b/src/lib/Client/Tools/__init__.py
@@ -183,7 +183,10 @@ class Tool:
return True
class PkgTool(Tool):
- '''PkgTool provides a one-pass install with fallback for use with packaging systems'''
+ '''
+ PkgTool provides a one-pass install with
+ fallback for use with packaging systems
+ '''
pkgtool = ('echo %s', ('%s', ['name']))
pkgtype = 'echo'
name = 'PkgTool'
@@ -200,7 +203,10 @@ class PkgTool(Tool):
return False
def Install(self, packages, states):
- '''Run a one-pass install, followed by single pkg installs in case of failure'''
+ '''
+ Run a one-pass install, followed by
+ single pkg installs in case of failure
+ '''
self.logger.info("Trying single pass package install for pkgtype %s" % \
self.pkgtype)
@@ -215,7 +221,7 @@ class PkgTool(Tool):
self.logger.info("Single Pass Succeded")
# set all package states to true and flush workqueues
pkgnames = [pkg.get('name') for pkg in packages]
- for entry in [entry for entry in states.keys()
+ for entry in [entry for entry in list(states.keys())
if entry.tag == 'Package'
and entry.get('type') == self.pkgtype
and entry.get('name') in pkgnames]:
@@ -256,7 +262,7 @@ class PkgTool(Tool):
def FindExtraPackages(self):
'''Find extra packages'''
packages = [entry.get('name') for entry in self.getSupportedEntries()]
- extras = [data for data in self.installed.iteritems() \
+ extras = [data for data in list(self.installed.items()) \
if data[0] not in packages]
return [Bcfg2.Client.XML.Element('Package', name=name, \
type=self.pkgtype, version=version) \
diff --git a/src/lib/Client/Tools/rpmtools.py b/src/lib/Client/Tools/rpmtools.py
index 8e3473239..d399e316c 100755
--- a/src/lib/Client/Tools/rpmtools.py
+++ b/src/lib/Client/Tools/rpmtools.py
@@ -20,8 +20,14 @@
"""
__revision__ = '$Revision$'
-import rpm, optparse, pwd, grp
-import sys, os, md5, stat
+import grp
+import md5
+import optparse
+import os
+import pwd
+import rpm
+import stat
+import sys
# Determine what prelink tools we have available.
# The isprelink module is a python extension that examines the ELF headers
@@ -190,7 +196,7 @@ def getindexbykeyword(index_ts, **kwargs):
else:
del(kwargs['epoch'])
- keywords = [ key for key in kwargs.keys() \
+ keywords = [ key for key in list(kwargs.keys()) \
if key in ('name', 'epoch', 'version', 'release', 'arch')]
keywords_len = len(keywords)
for hdr in index_mi:
@@ -228,7 +234,7 @@ def getheadersbykeyword(header_ts, **kwargs):
else:
del(kwargs['epoch'])
- keywords = [ key for key in kwargs.keys() \
+ keywords = [ key for key in list(kwargs.keys()) \
if key in ('name', 'epoch', 'version', 'release', 'arch')]
keywords_len = len(keywords)
for hdr in header_mi:
@@ -340,68 +346,68 @@ def debug_verify_flags(vflags):
Decodes the verify flags bits.
"""
if vflags & RPMVERIFY_MD5:
- print 'RPMVERIFY_MD5'
+ print('RPMVERIFY_MD5')
if vflags & RPMVERIFY_FILESIZE:
- print 'RPMVERIFY_FILESIZE'
+ print('RPMVERIFY_FILESIZE')
if vflags & RPMVERIFY_LINKTO:
- print 'RPMVERIFY_LINKTO'
+ print('RPMVERIFY_LINKTO')
if vflags & RPMVERIFY_USER:
- print 'RPMVERIFY_USER'
+ print('RPMVERIFY_USER')
if vflags & RPMVERIFY_GROUP:
- print 'RPMVERIFY_GROUP'
+ print('RPMVERIFY_GROUP')
if vflags & RPMVERIFY_MTIME:
- print 'RPMVERIFY_MTIME'
+ print('RPMVERIFY_MTIME')
if vflags & RPMVERIFY_MODE:
- print 'RPMVERIFY_MODE'
+ print('RPMVERIFY_MODE')
if vflags & RPMVERIFY_RDEV:
- print 'RPMVERIFY_RDEV'
+ print('RPMVERIFY_RDEV')
if vflags & RPMVERIFY_CONTEXTS:
- print 'RPMVERIFY_CONTEXTS'
+ print('RPMVERIFY_CONTEXTS')
if vflags & RPMVERIFY_READLINKFAIL:
- print 'RPMVERIFY_READLINKFAIL'
+ print('RPMVERIFY_READLINKFAIL')
if vflags & RPMVERIFY_READFAIL:
- print 'RPMVERIFY_READFAIL'
+ print('RPMVERIFY_READFAIL')
if vflags & RPMVERIFY_LSTATFAIL:
- print 'RPMVERIFY_LSTATFAIL'
+ print('RPMVERIFY_LSTATFAIL')
if vflags & RPMVERIFY_LGETFILECONFAIL:
- print 'RPMVERIFY_LGETFILECONFAIL'
+ print('RPMVERIFY_LGETFILECONFAIL')
def debug_file_flags(fflags):
"""
Decodes the file flags bits.
"""
if fflags & rpm.RPMFILE_CONFIG:
- print 'rpm.RPMFILE_CONFIG'
+ print('rpm.RPMFILE_CONFIG')
if fflags & rpm.RPMFILE_DOC:
- print 'rpm.RPMFILE_DOC'
+ print('rpm.RPMFILE_DOC')
if fflags & rpm.RPMFILE_ICON:
- print 'rpm.RPMFILE_ICON'
+ print('rpm.RPMFILE_ICON')
if fflags & rpm.RPMFILE_MISSINGOK:
- print 'rpm.RPMFILE_MISSINGOK'
+ print('rpm.RPMFILE_MISSINGOK')
if fflags & rpm.RPMFILE_NOREPLACE:
- print 'rpm.RPMFILE_NOREPLACE'
+ print('rpm.RPMFILE_NOREPLACE')
if fflags & rpm.RPMFILE_GHOST:
- print 'rpm.RPMFILE_GHOST'
+ print('rpm.RPMFILE_GHOST')
if fflags & rpm.RPMFILE_LICENSE:
- print 'rpm.RPMFILE_LICENSE'
+ print('rpm.RPMFILE_LICENSE')
if fflags & rpm.RPMFILE_README:
- print 'rpm.RPMFILE_README'
+ print('rpm.RPMFILE_README')
if fflags & rpm.RPMFILE_EXCLUDE:
- print 'rpm.RPMFILE_EXLUDE'
+ print('rpm.RPMFILE_EXLUDE')
if fflags & rpm.RPMFILE_UNPATCHED:
- print 'rpm.RPMFILE_UNPATCHED'
+ print('rpm.RPMFILE_UNPATCHED')
if fflags & rpm.RPMFILE_PUBKEY:
- print 'rpm.RPMFILE_PUBKEY'
+ print('rpm.RPMFILE_PUBKEY')
def rpm_verify_file(fileinfo, rpmlinktos, omitmask):
"""
@@ -789,7 +795,7 @@ class Rpmtscallback(object):
pass
#print 'rpm.RPMCALLBACK_UNKNOWN'
else:
- print 'ERROR - Fell through callBack'
+ print('ERROR - Fell through callBack')
#print reason, amount, total, key, client_data
@@ -816,7 +822,7 @@ def rpm_erase(erase_pkgspecs, erase_flags):
idx_list = getindexbykeyword(erase_ts, **pkgspec)
if len(idx_list) > 1 and not 'allmatches' in erase_flags:
#pass
- print 'ERROR - Multiple package match for erase', pkgspec
+ print('ERROR - Multiple package match for erase', pkgspec)
else:
for idx in idx_list:
erase_ts.addErase(idx)
@@ -898,7 +904,7 @@ def display_verify_file(file_results):
else:
result_string = result_string + '.'
- print result_string + ' ' + filetype + ' ' + filename
+ print(result_string + ' ' + filetype + ' ' + filename)
sys.stdout.flush()
#===============================================================================
@@ -1091,10 +1097,10 @@ if __name__ == "__main__":
elif options.list:
for p in rpmpackagelist(main_ts):
- print p
+ print(p)
elif options.erase:
if options.name:
rpm_erase([cmdline_pkgspec], rpm_options)
else:
- print 'You must specify the "--name" option'
+ print('You must specify the "--name" option')
diff --git a/src/lib/Client/XML.py b/src/lib/Client/XML.py
index 8de3b3a7e..42b1017ac 100644
--- a/src/lib/Client/XML.py
+++ b/src/lib/Client/XML.py
@@ -30,8 +30,8 @@ except ImportError:
return elementtree.ElementTree.tostring(e)
except ImportError:
- print "Failed to load lxml, xml.etree and elementtree.ElementTree"
- print "Cannot continue"
- raise SystemExit, 1
+ print("Failed to load lxml, xml.etree and elementtree.ElementTree")
+ print("Cannot continue")
+ raise SystemExit(1)
len([Element, SubElement, XML, tostring, ParseError])