Skip to content

Commit

Permalink
pychecker related fixes, including unused imports, and removal of use…
Browse files Browse the repository at this point in the history
… of deprecated methods from the string module
  • Loading branch information
James Bowes committed Dec 5, 2006
1 parent 4d217a1 commit 7bea941
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 119 deletions.
6 changes: 3 additions & 3 deletions bin/yum-updatesd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python
import sys
try:
import yum
import yum
except ImportError:
print >> sys.stderr, """\
print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
Expand All @@ -21,7 +21,7 @@
http:https://wiki.linux.duke.edu/YumFaq
""" % (sys.exc_value, sys.version)
sys.exit(1)
sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
Expand Down
6 changes: 3 additions & 3 deletions bin/yum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python
import sys
try:
import yum
import yum
except ImportError:
print >> sys.stderr, """\
print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
Expand All @@ -21,7 +21,7 @@
http:https://wiki.linux.duke.edu/YumFaq
""" % (sys.exc_value, sys.version)
sys.exit(1)
sys.exit(1)

sys.path.insert(0, '/usr/share/yum-cli')
try:
Expand Down
2 changes: 1 addition & 1 deletion callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def callback(self, what, bytes, total, h, user):
try:
process = self.myprocess[txmbr.output_state]
processed = self.mypostprocess[txmbr.output_state]
except KeyError, e:
except KeyError:
pass

if self.output:
Expand Down
90 changes: 49 additions & 41 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import shell
import yum
import yum.Errors
import yum.logginglevels
import yum.misc
import yum.plugins
from yum.constants import TS_OBSOLETED
import rpmUtils.arch
from yum.packages import parsePackages, YumLocalPackage
from yum import logginglevels
from yum import plugins
from i18n import _
import callback
import signal
Expand All @@ -55,6 +55,7 @@ def __init__(self):
# handle sigquit early on
signal.signal(signal.SIGQUIT, sigquit)
yum.YumBase.__init__(self)
output.YumOutput.__init__(self)
logging.basicConfig()
self.logger = logging.getLogger("yum.cli")
self.verbose_logger = logging.getLogger("yum.verbose.cli")
Expand Down Expand Up @@ -90,18 +91,19 @@ def doRepoSetup(self, thisrepo=None, dosack=1):
and sets up the basics of the repository"""

if self.pkgSack and thisrepo is None:
self.verbose_logger.log(logginglevels.DEBUG_4,
self.verbose_logger.log(yum.logginglevels.DEBUG_4,
'skipping reposetup, pkgsack exists')
return

self.verbose_logger.log(logginglevels.INFO_2, 'Setting up repositories')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Setting up repositories')

# Call parent class to do the bulk of work
# (this also ensures that reposetup plugin hook is called)
yum.YumBase.doRepoSetup(self, thisrepo=thisrepo)

if dosack: # so we can make the dirs and grab the repomd.xml but not import the md
self.verbose_logger.log(logginglevels.INFO_2,
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Reading repository metadata in from local files')
self.doSackSetup(thisrepo=thisrepo)

Expand All @@ -120,7 +122,7 @@ def repo_optcb(optobj, opt, value, parser):
dest = eval('parser.values.%s' % optobj.dest)
dest.append((opt, value))

self.optparser = YumOptionParser(base=self,
self.optparser = YumOptionParser(
usage='yum [options] < %s >' % (', '.join(self.yum_cli_commands)))

self.optparser.add_option("-t", "--tolerant", dest="tolerant",
Expand Down Expand Up @@ -197,7 +199,7 @@ def repo_optcb(optobj, opt, value, parser):
try:
self.doConfigSetup(opts.conffile, root,
init_plugins=not opts.noplugins,
plugin_types=(plugins.TYPE_CORE,plugins.TYPE_INTERACTIVE,),
plugin_types=(yum.plugins.TYPE_CORE, yum.plugins.TYPE_INTERACTIVE),
optparser=self.optparser,
debuglevel=opts.debuglevel,
errorlevel=opts.errorlevel)
Expand Down Expand Up @@ -292,7 +294,7 @@ def repo_optcb(optobj, opt, value, parser):
# run the sleep - if it's unchanged then it won't matter
time.sleep(sleeptime)

def parseCommands(self, mycommands=[]):
def parseCommands(self):
"""reads self.cmds and parses them out to make sure that the requested
base command + argument makes any sense at all"""

Expand Down Expand Up @@ -358,7 +360,8 @@ def doTransaction(self):
RUNNING the transaction"""

# output what will be done:
self.verbose_logger.log(logginglevels.INFO_1, self.listTransaction())
self.verbose_logger.log(yum.logginglevels.INFO_1,
self.listTransaction())

# Check which packages have to be downloaded
downloadpkgs = []
Expand Down Expand Up @@ -386,7 +389,8 @@ def doTransaction(self):
self.verbose_logger.info('Exiting on user Command')
return 1

self.verbose_logger.log(logginglevels.INFO_2, 'Downloading Packages:')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Downloading Packages:')
problems = self.downloadPkgs(downloadpkgs)

if len(problems.keys()) > 0:
Expand All @@ -402,7 +406,8 @@ def doTransaction(self):
if self.gpgsigcheck(downloadpkgs) != 0:
return 1

self.verbose_logger.log(logginglevels.INFO_2, 'Running Transaction Test')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Running Transaction Test')
tsConf = {}
for feature in ['diskspacecheck']: # more to come, I'm sure
tsConf[feature] = getattr(self.conf, feature)
Expand All @@ -418,14 +423,16 @@ def doTransaction(self):
tserrors = self.ts.test(testcb, conf=tsConf)
del testcb

self.verbose_logger.log(logginglevels.INFO_2, 'Finished Transaction Test')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Finished Transaction Test')
if len(tserrors) > 0:
errstring = 'Transaction Check Error: '
for descr in tserrors:
errstring += ' %s\n' % descr

raise yum.Errors.YumBaseError, errstring
self.verbose_logger.log(logginglevels.INFO_2, 'Transaction Test Succeeded')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Transaction Test Succeeded')
del self.ts

# unset the sigquit handler
Expand All @@ -445,11 +452,12 @@ def doTransaction(self):
cb = callback.RPMInstallCallback(output=output)
cb.tsInfo = self.tsInfo

self.verbose_logger.log(logginglevels.INFO_2, 'Running Transaction')
self.verbose_logger.log(yum.logginglevels.INFO_2, 'Running Transaction')
self.runTransaction(cb=cb)

# close things
self.verbose_logger.log(logginglevels.INFO_1, self.postTransactionOutput())
self.verbose_logger.log(yum.logginglevels.INFO_1,
self.postTransactionOutput())

# put back the sigquit handler
signal.signal(signal.SIGQUIT, sigquit)
Expand Down Expand Up @@ -507,7 +515,7 @@ def installPkgs(self, userlist):
toBeInstalled = {} # keyed on name
passToUpdate = [] # list of pkgtups to pass along to updatecheck

self.verbose_logger.log(logginglevels.INFO_2,
self.verbose_logger.log(yum.logginglevels.INFO_2,
_('Parsing package install arguments'))
for arg in userlist:
if os.path.exists(arg) and arg.endswith('.rpm'): # this is hurky, deal w/it
Expand Down Expand Up @@ -541,7 +549,7 @@ def installPkgs(self, userlist):
# ones that we obviously can't use
for pkg in installable:
if self.rpmdb.installed(po=pkg):
self.verbose_logger.log(logginglevels.DEBUG_3,
self.verbose_logger.log(yum.logginglevels.DEBUG_3,
'Package %s is already installed, skipping', pkg)
continue

Expand All @@ -552,7 +560,7 @@ def installPkgs(self, userlist):
if rpmUtils.arch.isMultiLibArch(instpo.arch) == rpmUtils.arch.isMultiLibArch(pkg.arch):
comparable.append(instpo)
else:
self.verbose_logger.log(logginglevels.DEBUG_3,
self.verbose_logger.log(yum.logginglevels.DEBUG_3,
'Discarding non-comparable pkg %s.%s', instpo.name, instpo.arch)
continue

Expand All @@ -577,7 +585,7 @@ def installPkgs(self, userlist):
if not toBeInstalled.has_key(pkg.name): toBeInstalled[pkg.name] = []
toBeInstalled[pkg.name].append(pkg)
else: # we've not got any installed that match n or n+a
self.verbose_logger.log(logginglevels.DEBUG_1, 'No other %s installed, adding to list for potential install', pkg.name)
self.verbose_logger.log(yum.logginglevels.DEBUG_1, 'No other %s installed, adding to list for potential install', pkg.name)
if not toBeInstalled.has_key(pkg.name): toBeInstalled[pkg.name] = []
toBeInstalled[pkg.name].append(pkg)

Expand Down Expand Up @@ -621,7 +629,6 @@ def updatePkgs(self, userlist, quiet=0):

oldcount = len(self.tsInfo)
self.doRepoSetup()
avail = self.pkgSack.simplePkgList()
self.doRpmDBSetup()
installed = self.rpmdb.simplePkgList()
self.doUpdateSetup()
Expand All @@ -642,7 +649,7 @@ def updatePkgs(self, userlist, quiet=0):
txmbrs = self.tsInfo.getMembers(pkgtup=old)

if txmbrs and txmbrs[0].output_state == TS_OBSOLETED:
self.verbose_logger.log(logginglevels.DEBUG_2, 'Not Updating Package that is already obsoleted: %s.%s %s:%s-%s', old)
self.verbose_logger.log(yum.logginglevels.DEBUG_2, 'Not Updating Package that is already obsoleted: %s.%s %s:%s-%s', old)
else:
updating_pkg = self.getPackageObject(new)
updated_pkg = self.rpmdb.searchPkgTuple(old)[0]
Expand Down Expand Up @@ -753,11 +760,11 @@ def localInstall(self, filelist, updateonly=0):
for pkg in filelist:
try:
po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
except yum.Errors.MiscError, e:
except yum.Errors.MiscError:
self.logger.critical('Cannot open file: %s. Skipping.', pkg)
continue
self.verbose_logger.log(logginglevels.INFO_2, 'Examining %s: %s',
po.localpath, po)
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Examining %s: %s', po.localpath, po)

# everything installed that matches the name
installedByKey = self.rpmdb.searchNevra(name=po.name)
Expand Down Expand Up @@ -798,8 +805,8 @@ def localInstall(self, filelist, updateonly=0):
self.verbose_logger.debug('Excluding %s', po)
continue

self.verbose_logger.log(logginglevels.INFO_2, 'Marking %s to be installed',
po.localpath)
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Marking %s to be installed', po.localpath)
self.localPackages.append(po)
self.install(po=po)

Expand All @@ -808,13 +815,13 @@ def localInstall(self, filelist, updateonly=0):
self.verbose_logger.debug('Excluding %s', po)
continue

self.verbose_logger.log(logginglevels.INFO_2,
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Marking %s as an update to %s', po.localpath, oldpo)
self.localPackages.append(po)
self.tsInfo.addUpdate(po, oldpo)

for po in donothingpkgs:
self.verbose_logger.log(logginglevels.INFO_2,
self.verbose_logger.log(yum.logginglevels.INFO_2,
'%s: does not update installed package.', po.localpath)

if len(self.tsInfo) > oldcount:
Expand Down Expand Up @@ -851,7 +858,7 @@ def returnPkgLists(self, extcmds):

def _shrinklist(lst, args):
if len(lst) > 0 and len(args) > 0:
self.verbose_logger.log(logginglevels.DEBUG_1,
self.verbose_logger.log(yum.logginglevels.DEBUG_1,
'Matching packages for package list to user args')
exactmatch, matched, unmatched = yum.packages.parsePackages(lst, args)
return yum.misc.unique(matched + exactmatch)
Expand Down Expand Up @@ -929,7 +936,7 @@ def resolveDepCli(self, args):
for arg in args:
try:
pkg = self.returnPackageByDep(arg)
except yum.Errors.YumBaseError, e:
except yum.Errors.YumBaseError:
self.logger.critical(_('No Package Found for %s'), arg)
else:
msg = '%s:%s-%s-%s.%s' % (pkg.epoch, pkg.name, pkg.version, pkg.release, pkg.arch)
Expand All @@ -942,7 +949,8 @@ def cleanCli(self, userlist):
pkgresults = hdrresults = xmlresults = dbresults = []

if 'all' in userlist:
self.verbose_logger.log(logginglevels.INFO_2, 'Cleaning up Everything')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Cleaning up Everything')
pkgcode, pkgresults = self.cleanPackages()
hdrcode, hdrresults = self.cleanHeaders()
xmlcode, xmlresults = self.cleanMetadata()
Expand Down Expand Up @@ -975,7 +983,7 @@ def cleanCli(self, userlist):
code = hdrcode + pkgcode + xmlcode + dbcode
results = hdrresults + pkgresults + xmlresults + dbresults
for msg in results:
self.verbose_logger.log(logginglevels.INFO_2, msg)
self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
return code, []

def returnGroupLists(self, userlist):
Expand All @@ -989,15 +997,17 @@ def returnGroupLists(self, userlist):
installed, available = self.doGroupLists(uservisible=uservisible)

if len(installed) > 0:
self.verbose_logger.log(logginglevels.INFO_2, 'Installed Groups:')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Installed Groups:')
for group in installed:
self.verbose_logger.log(logginglevels.INFO_2, ' %s',
self.verbose_logger.log(yum.logginglevels.INFO_2, ' %s',
group.name)

if len(available) > 0:
self.verbose_logger.log(logginglevels.INFO_2, 'Available Groups:')
self.verbose_logger.log(yum.logginglevels.INFO_2,
'Available Groups:')
for group in available:
self.verbose_logger.log(logginglevels.INFO_2, ' %s',
self.verbose_logger.log(yum.logginglevels.INFO_2, ' %s',
group.name)


Expand Down Expand Up @@ -1028,7 +1038,7 @@ def installGroups(self, grouplist):

try:
txmbrs = self.selectGroup(group.groupid)
except yum.Errors.GroupsError, e:
except yum.Errors.GroupsError:
self.logger.critical(_('Warning: Group %s does not exist.'), group_string)
continue
else:
Expand All @@ -1043,12 +1053,10 @@ def removeGroups(self, grouplist):
"""Remove only packages of the named group(s). Do not recurse."""

pkgs_used = []

erasesbygroup = []
for group_string in grouplist:
try:
txmbrs = self.groupRemove(group_string)
except yum.Errors.GroupsError, e:
except yum.Errors.GroupsError:
self.logger.critical('No group named %s exists', group_string)
continue
else:
Expand Down Expand Up @@ -1096,7 +1104,7 @@ class YumOptionParser(OptionParser):
"yum way".
'''

def __init__(self, base, **kwargs):
def __init__(self, **kwargs):
OptionParser.__init__(self, **kwargs)
self.logger = logging.getLogger("yum.cli")

Expand Down
2 changes: 0 additions & 2 deletions output.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Copyright 2005 Duke University

import os
import os.path
import sys
import time
import logging
Expand Down
2 changes: 1 addition & 1 deletion progress_meter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _do_update(self, read):
else:
rtime = self.format_time(self.project(etime, read))
try: frac = float(read)/self.length
except ZeroDivisionError, e: frac = 1.0
except ZeroDivisionError: frac = 1.0
if frac > 1.0: frac = 1.0
bar = '='*int(25 * frac)
out = '\r%-25.25s %3i%% |%-25.25s| %5sB %8s ETA ' % \
Expand Down

0 comments on commit 7bea941

Please sign in to comment.