summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2011-04-07 13:51:24 -0500
committerSol Jerome <sol.jerome@gmail.com>2011-04-07 13:51:24 -0500
commit1d2b0215f5957d4ec0d320984c93328a39d3b08c (patch)
tree34e320967a1503358ad988a10aaf3f52a0a6a99d /src
parent742fc83dcdb82639b97723ce4cbfade75fb1aa71 (diff)
downloadbcfg2-1d2b0215f5957d4ec0d320984c93328a39d3b08c.tar.gz
bcfg2-1d2b0215f5957d4ec0d320984c93328a39d3b08c.tar.bz2
bcfg2-1d2b0215f5957d4ec0d320984c93328a39d3b08c.zip
Client: PY3K + PEP8 fixes
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/Client/Frame.py29
-rw-r--r--src/lib/Client/Tools/Action.py7
-rw-r--r--src/lib/Client/Tools/Pacman.py2
-rw-r--r--src/lib/Client/Tools/YUM24.py54
-rw-r--r--src/lib/Client/Tools/YUMng.py27
-rw-r--r--src/lib/Client/Tools/__init__.py19
6 files changed, 88 insertions, 50 deletions
diff --git a/src/lib/Client/Frame.py b/src/lib/Client/Frame.py
index 545d4b584..f87610dcb 100644
--- a/src/lib/Client/Frame.py
+++ b/src/lib/Client/Frame.py
@@ -8,6 +8,7 @@ import logging
import time
import Bcfg2.Client.Tools
+
def cmpent(ent1, ent2):
"""Sort entries."""
if ent1.tag != ent2.tag:
@@ -15,6 +16,7 @@ def cmpent(ent1, ent2):
else:
return cmp(ent1.get('name'), ent2.get('name'))
+
def promptFilter(prompt, entries):
"""Filter a supplied list based on user input."""
ret = []
@@ -25,7 +27,12 @@ def promptFilter(prompt, entries):
else:
iprompt = prompt % (entry.tag, entry.get('name'))
try:
- if raw_input(iprompt) in ['y', 'Y']:
+ # py3k compatibility
+ try:
+ ans = raw_input(iprompt)
+ except NameError:
+ ans = input(iprompt)
+ if ans in ['y', 'Y']:
ret.append(entry)
except EOFError:
# python 2.4.3 on CentOS doesn't like ^C for some reason
@@ -35,6 +42,7 @@ def promptFilter(prompt, entries):
continue
return ret
+
def matches_entry(entryspec, entry):
# both are (tag, name)
if entryspec == entry:
@@ -52,11 +60,16 @@ def matches_entry(entryspec, entry):
return False
return True
+
def matches_white_list(entry, whitelist):
- return True in [matches_entry(we, (entry.tag, entry.get('name'))) for we in whitelist]
+ return True in [matches_entry(we, (entry.tag, entry.get('name')))
+ for we in whitelist]
+
def passes_black_list(entry, blacklist):
- return True not in [matches_entry(be, (entry.tag, entry.get('name'))) for be in blacklist]
+ return True not in [matches_entry(be, (entry.tag, entry.get('name')))
+ for be in blacklist]
+
class Frame:
"""Frame is the container for all Tool objects and state information."""
@@ -134,8 +147,10 @@ class Frame:
self.logger.error(["%s:%s:%s" % (entry.tag, entry.get('type'), \
entry.get('name')) for entry in problems])
self.logger.error("")
- entries = [(entry.tag, entry.get('name')) for struct in config for entry in struct]
- pkgs = [(entry.get('name'), entry.get('origin')) for struct in config for entry in struct if entry.tag == 'Package']
+ entries = [(entry.tag, entry.get('name'))
+ for struct in config for entry in struct]
+ pkgs = [(entry.get('name'), entry.get('origin'))
+ for struct in config for entry in struct if entry.tag == 'Package']
multi = []
for entry in entries[:]:
if entries.count(entry) > 1:
@@ -151,7 +166,6 @@ class Frame:
self.logger.debug("The following packages are prereqs added by Packages:")
self.logger.debug([pkg[0] for pkg in pkgs if pkg[1] == 'Packages'])
-
def __getattr__(self, name):
if name in ['extra', 'handled', 'modified', '__important__']:
ret = []
@@ -268,7 +282,8 @@ class Frame:
if b_to_remv:
self.logger.info("Not installing entries from Bundle %s" % \
(bundle.get('name')))
- self.logger.info(["%s:%s" % (e.tag, e.get('name')) for e in b_to_remv])
+ self.logger.info(["%s:%s" % (e.tag, e.get('name'))
+ for e in b_to_remv])
[self.whitelist.remove(ent) for ent in b_to_remv]
if self.setup['interactive']:
diff --git a/src/lib/Client/Tools/Action.py b/src/lib/Client/Tools/Action.py
index 452788f94..bc57a0e27 100644
--- a/src/lib/Client/Tools/Action.py
+++ b/src/lib/Client/Tools/Action.py
@@ -31,7 +31,12 @@ class Action(Bcfg2.Client.Tools.Tool):
if self.setup['interactive']:
prompt = ('Run Action %s, %s: (y/N): ' %
(entry.get('name'), entry.get('command')))
- if raw_input(prompt) not in ['y', 'Y']:
+ # py3k compatibility
+ try:
+ ans = raw_input(prompt)
+ except NameError:
+ ans = input(prompt)
+ if ans not in ['y', 'Y']:
return False
if self.setup['servicemode'] == 'build':
if entry.get('build', 'true') == 'false':
diff --git a/src/lib/Client/Tools/Pacman.py b/src/lib/Client/Tools/Pacman.py
index be3fb0c94..082897934 100644
--- a/src/lib/Client/Tools/Pacman.py
+++ b/src/lib/Client/Tools/Pacman.py
@@ -73,7 +73,7 @@ class Pacman(Bcfg2.Client.Tools.PkgTool):
for pkg in packages:
pkgline += " " + pkg.get('name')
- print "packages : " + pkgline
+ self.logger.info("packages : " + pkgline)
try:
self.logger.debug("Running : %s -S %s" % (self.pkgtool, pkgline))
diff --git a/src/lib/Client/Tools/YUM24.py b/src/lib/Client/Tools/YUM24.py
index efe92a059..04d9f5c07 100644
--- a/src/lib/Client/Tools/YUM24.py
+++ b/src/lib/Client/Tools/YUM24.py
@@ -30,6 +30,7 @@ except:
if not hasattr(Bcfg2.Client.Tools.RPMng, 'RPMng'):
raise ImportError
+
def build_yname(pkgname, inst):
"""Build yum appropriate package name."""
ypname = pkgname
@@ -45,6 +46,7 @@ def build_yname(pkgname, inst):
ypname += ".%s" % (inst.get('arch'))
return ypname
+
class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
"""Support for Yum packages."""
pkgtype = 'yum'
@@ -59,7 +61,8 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
__ireq__ = {'Package': ['name']}
#__ireq__ = {'Package': ['name', 'version']}
- __new_req__ = {'Package': ['name'], 'Instance': ['version', 'release', 'arch']}
+ __new_req__ = {'Package': ['name'],
+ 'Instance': ['version', 'release', 'arch']}
__new_ireq__ = {'Package': ['name'], \
'Instance': []}
#__new_ireq__ = {'Package': ['name', 'uri'], \
@@ -68,8 +71,10 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
__gpg_req__ = {'Package': ['name', 'version']}
__gpg_ireq__ = {'Package': ['name', 'version']}
- __new_gpg_req__ = {'Package': ['name'], 'Instance': ['version', 'release']}
- __new_gpg_ireq__ = {'Package': ['name'], 'Instance': ['version', 'release']}
+ __new_gpg_req__ = {'Package': ['name'],
+ 'Instance': ['version', 'release']}
+ __new_gpg_ireq__ = {'Package': ['name'],
+ 'Instance': ['version', 'release']}
conflicts = ['YUMng', 'RPMng']
@@ -101,10 +106,14 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
data = {pkg.arch: (pkg.epoch, pkg.version, pkg.release)}
else:
pname = pkg[0]
- if pkg[1] is None: a = 'noarch'
- else: a = pkg[1]
- if pkg[2] is None: e = '0'
- else: e = pkg[2]
+ if pkg[1] is None:
+ a = 'noarch'
+ else:
+ a = pkg[1]
+ if pkg[2] is None:
+ e = '0'
+ else:
+ e = pkg[2]
data = {a: (e, pkg[3], pkg[4])}
if pname in dest:
dest[pname].update(data)
@@ -137,24 +146,24 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
if entry.get('type', False) == 'yum':
# Check for virtual provides or packages. If we don't have
# this package use Yum to resolve it to a real package name
- knownPkgs = self.yum_installed.keys() + self.yum_avail.keys()
+ knownPkgs = list(self.yum_installed.keys()) + list(self.yum_avail.keys())
if entry.get('name') not in knownPkgs:
# If the package name matches something installed
# or available the that's the correct package.
try:
- pkgDict = dict( [ (i.name, i) for i in \
- self.yb.returnPackagesByDep(entry.get('name')) ] )
+ pkgDict = dict([(i.name, i) for i in \
+ self.yb.returnPackagesByDep(entry.get('name'))])
except yum.Errors.YumBaseError, e:
self.logger.error('Yum Error Depsolving for %s: %s' % \
(entry.get('name'), str(e)))
pkgDict = {}
if len(pkgDict) > 1:
- # What do we do with multiple packages?
+ # What do we do with multiple packages?
s = "YUMng: returnPackagesByDep(%s) returned many packages"
self.logger.info(s % entry.get('name'))
s = "YUMng: matching packages: %s"
- self.logger.info(s % str(pkgDict.keys()))
+ self.logger.info(s % str(list(pkgDict.keys())))
pkgs = set(pkgDict.keys()) & set(self.yum_installed.keys())
if len(pkgs) > 0:
# Virtual packages matches an installed real package
@@ -166,7 +175,7 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
# and Yum should Do The Right Thing on package install
pkg = None
elif len(pkgDict) == 1:
- pkg = pkgDict.values()[0]
+ pkg = list(pkgDict.values())[0]
else: # len(pkgDict) == 0
s = "YUMng: returnPackagesByDep(%s) returned no results"
self.logger.info(s % entry.get('name'))
@@ -252,16 +261,16 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
self.logger.error("GPG key has no simplefile attribute")
continue
key_arg = os.path.join(self.instance_status[inst].get('pkg').get('uri'), \
- inst.get('simplefile'))
+ inst.get('simplefile'))
cmdrc, output = self.cmd.run("rpm --import %s" % key_arg)
if cmdrc != 0:
self.logger.debug("Unable to install %s-%s" % \
- (self.instance_status[inst].get('pkg').get('name'), \
- self.str_evra(inst)))
+ (self.instance_status[inst].get('pkg').get('name'), \
+ self.str_evra(inst)))
else:
self.logger.debug("Installed %s-%s-%s" % \
- (self.instance_status[inst].get('pkg').get('name'), \
- inst.get('version'), inst.get('release')))
+ (self.instance_status[inst].get('pkg').get('name'), \
+ inst.get('version'), inst.get('release')))
self.RefreshPackages()
self.gpg_keyids = self.getinstalledgpg()
pkg = self.instance_status[gpg_keys[0]].get('pkg')
@@ -374,9 +383,9 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
pkg_arg = pkg_arg + '.' + inst.get('arch')
erase_args.append(pkg_arg)
else:
- pkgspec = { 'name':pkg.get('name'),
- 'version':inst.get('version'),
- 'release':inst.get('release')}
+ pkgspec = {'name': pkg.get('name'),
+ 'version': inst.get('version'),
+ 'release': inst.get('release')}
self.logger.info("WARNING: gpg-pubkey package not in configuration %s %s"\
% (pkgspec.get('name'), self.str_evra(pkgspec)))
self.logger.info(" This package will be deleted in a future version of the RPMng driver.")
@@ -395,7 +404,7 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
for inst in pkg:
if pkg.get('name') != 'gpg-pubkey':
pkg_arg = pkg.get('name') + '-'
- if inst.attrib.has_key('epoch'):
+ if 'epoch' in inst.attrib:
pkg_arg = pkg_arg + inst.get('epoch') + ':'
pkg_arg = pkg_arg + inst.get('version') + '-' + inst.get('release')
if 'arch' in inst.attrib:
@@ -416,6 +425,5 @@ class YUM24(Bcfg2.Client.Tools.RPMng.RPMng):
if pkg_modified == True:
self.modified.append(pkg)
-
self.RefreshPackages()
self.extra = self.FindExtraPackages()
diff --git a/src/lib/Client/Tools/YUMng.py b/src/lib/Client/Tools/YUMng.py
index 8db1683e4..c9e7aa15e 100644
--- a/src/lib/Client/Tools/YUMng.py
+++ b/src/lib/Client/Tools/YUMng.py
@@ -300,7 +300,7 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
# Okay deal with a buggy yum multilib and verify
packages = self.yb.rpmdb.searchNevra(name=po.name, epoch=po.epoch,
- ver=po.version, rel=po.release) # find all arches of pkg
+ ver=po.version, rel=po.release) # find all arches of pkg
if len(packages) == 1:
return results # No mathcing multilib packages
@@ -319,13 +319,13 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
v = verify(p)
self.verifyCache[k] = v
- for fn, probs in v.items():
+ for fn, probs in list(v.items()):
# file problems must exist in ALL multilib packages to be real
if fn in files:
common[fn] = common.get(fn, 0) + 1
flag = len(packages) - 1
- for fn, i in common.items():
+ for fn, i in list(common.items()):
if i == flag:
# this fn had verify problems in all but one of the multilib
# packages. That means its correct in the package that's
@@ -512,7 +512,7 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
ignores = [ig.get('name') for ig in entry.findall('Ignore')] + \
[ig.get('name') for ig in inst.findall('Ignore')] + \
self.ignores
- for fn, probs in vResult.items():
+ for fn, probs in list(vResult.items()):
if fn in modlist:
self.logger.debug(" %s in modlist, skipping" % fn)
continue
@@ -537,7 +537,7 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
"these files, revert the changes, or ignore "
"false failures:")
self.logger.debug(" Verify Problems:")
- for fn, probs in stat['verify'].items():
+ for fn, probs in list(stat['verify'].items()):
self.logger.debug(" %s" % fn)
for p in probs:
self.logger.debug(" %s: %s" % p)
@@ -577,7 +577,7 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
extra_entry = Bcfg2.Client.XML.Element('Package', name=name,
type=self.pkgtype)
instances = self._buildInstances(entry)
- _POs = [p for p in POs] # Shallow copy
+ _POs = [p for p in POs] # Shallow copy
# Algorythm is sensitive to duplicates, check for them
checked = []
@@ -588,7 +588,7 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
flag = True
if len(pkgs) > 0:
if pkgs[0] in checked:
- continue # We've already taken care of this Instance
+ continue # We've already taken care of this Instance
else:
checked.append(pkgs[0])
_POs.remove(pkgs[0])
@@ -609,16 +609,17 @@ class YUMng(Bcfg2.Client.Tools.PkgTool):
packages = [e.get('name') for e in self.getSupportedEntries()]
extras = []
- for p in self.installed.keys():
+ for p in list(self.installed.keys()):
if p not in packages:
entry = Bcfg2.Client.XML.Element('Package', name=p,
type=self.pkgtype)
for i in self.installed[p]:
- inst = Bcfg2.Client.XML.SubElement(entry, 'Instance', \
- epoch = i['epoch'],
- version = i['version'],
- release = i['release'],
- arch = i['arch'])
+ inst = Bcfg2.Client.XML.SubElement(entry,
+ 'Instance',
+ epoch=i['epoch'],
+ version=i['version'],
+ release=i['release'],
+ arch=i['arch'])
extras.append(entry)
diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py
index b5120db71..7d8d58957 100644
--- a/src/lib/Client/Tools/__init__.py
+++ b/src/lib/Client/Tools/__init__.py
@@ -57,7 +57,7 @@ class executor:
runpipe = readonlypipe(command, bufsize=16384)
output = []
- try:#macosx doesn't like this
+ try: # macosx doesn't like this
runpipe.fromchild.flush()
except IOError:
pass
@@ -185,7 +185,9 @@ class Tool:
if 'failure' in entry.attrib:
self.logger.error("Entry %s:%s reports bind failure: %s" % \
- (entry.tag, entry.get('name'), entry.get('failure')))
+ (entry.tag,
+ entry.get('name'),
+ entry.get('failure')))
return False
missing = [attr for attr in self.__req__[entry.tag] \
@@ -198,7 +200,8 @@ class Tool:
try:
self.gatherCurrentData(entry)
except:
- self.logger.error("Unexpected error in gatherCurrentData", exc_info=1)
+ self.logger.error("Unexpected error in gatherCurrentData",
+ exc_info=1)
return False
return True
@@ -255,7 +258,8 @@ class PkgTool(Tool):
self.logger.info("Trying single pass package install for pkgtype %s" % \
self.pkgtype)
- data = [tuple([pkg.get(field) for field in self.pkgtool[1][1]]) for pkg in packages]
+ data = [tuple([pkg.get(field) for field in self.pkgtool[1][1]])
+ for pkg in packages]
pkgargs = " ".join([self.pkgtool[1][0] % datum for datum in data])
self.logger.debug("Installing packages: :%s:" % pkgargs)
@@ -358,7 +362,12 @@ class SvcTool(Tool):
else:
if self.setup['interactive']:
prompt = 'Restart service %s?: (y/N): ' % entry.get('name')
- if raw_input(prompt) not in ['y', 'Y']:
+ # py3k compatibility
+ try:
+ ans = raw_input(prompt)
+ except NameError:
+ ans = input(prompt)
+ if ans not in ['y', 'Y']:
continue
rc = self.restart_service(entry)
else: