Use alternative Python 2/3 'print' compatibility hack; drop rlprint, rename rlwarn to warn.
git-svn-id: svn+ssh://rpmlint.zarb.org/home/projects/rpmlint/svn/trunk@1686 9bc8b190-ac0f-0410-8968-dc7d1f502856
This commit is contained in:
parent
1c3dcdd6c6
commit
f848345066
|
@ -11,7 +11,6 @@
|
|||
import textwrap
|
||||
|
||||
import Config
|
||||
import Pkg
|
||||
try:
|
||||
import Testing
|
||||
except ImportError:
|
||||
|
@ -61,7 +60,7 @@ def _print(msgtype, pkg, reason, details):
|
|||
if threshold >= 0:
|
||||
_diagnostic.append(s + "\n")
|
||||
else:
|
||||
Pkg.rlprint(s)
|
||||
print (s)
|
||||
if Config.info:
|
||||
printDescriptions(reason)
|
||||
return True
|
||||
|
@ -72,8 +71,8 @@ def printDescriptions(reason):
|
|||
try:
|
||||
d = _details[reason]
|
||||
if d and d != '' and d != "\n":
|
||||
Pkg.rlprint(textwrap.fill(d, 78))
|
||||
Pkg.rlprint("")
|
||||
print (textwrap.fill(d, 78))
|
||||
print ("")
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
@ -96,7 +95,7 @@ def printAllReasons():
|
|||
if len(last_reason):
|
||||
printDescriptions(last_reason)
|
||||
last_reason = reason
|
||||
Pkg.rlprint(diag)
|
||||
print (diag)
|
||||
if Config.info and len(last_reason):
|
||||
printDescriptions(last_reason)
|
||||
_diagnostic = list()
|
||||
|
|
34
Pkg.py
34
Pkg.py
|
@ -27,22 +27,15 @@ except:
|
|||
_magic = None
|
||||
import rpm
|
||||
|
||||
# Python 2/3 compatibility/convenience wrappers for printing to stdout/stderr
|
||||
# with less concerns of UnicodeErrors.
|
||||
import Filter
|
||||
|
||||
# Python 2/3 compatibility/convenience wrapper for printing to stderr with
|
||||
# less concerns of UnicodeErrors than plain sys.stderr.write.
|
||||
if sys.version_info[0] > 2:
|
||||
exec('''
|
||||
def rlprint(s):
|
||||
print(s)
|
||||
def rlwarn(s):
|
||||
print(s, file=sys.stderr)
|
||||
''')
|
||||
# Blows up with Python < 3 without the exec() hack
|
||||
exec('def warn(s): print (s, file=sys.stderr)')
|
||||
else:
|
||||
exec('''
|
||||
def rlprint(s):
|
||||
print s
|
||||
def rlwarn(s):
|
||||
print >> sys.stderr, s
|
||||
''')
|
||||
def warn(s): print >> sys.stderr, s
|
||||
|
||||
|
||||
# utilities
|
||||
|
@ -380,7 +373,7 @@ class Pkg:
|
|||
def _extract(self):
|
||||
s = os.stat(self.dirname)
|
||||
if not stat.S_ISDIR(s[stat.ST_MODE]):
|
||||
rlwarn('Unable to access dir %s' % self.dirname)
|
||||
warn('Unable to access dir %s' % self.dirname)
|
||||
return None
|
||||
else:
|
||||
self.dirname = tempfile.mkdtemp(
|
||||
|
@ -414,7 +407,6 @@ class Pkg:
|
|||
ret.append(str(lineno))
|
||||
break
|
||||
except Exception, e:
|
||||
import Filter
|
||||
Filter.printWarning(self, 'read-error', filename, e)
|
||||
finally:
|
||||
if in_file:
|
||||
|
@ -704,11 +696,11 @@ class PkgFile(object):
|
|||
if __name__ == '__main__':
|
||||
for p in sys.argv[1:]:
|
||||
pkg = Pkg(sys.argv[1], tempfile.gettempdir())
|
||||
rlprint('Requires: %s' % pkg.requires())
|
||||
rlprint('Prereq: %s' % pkg.prereq())
|
||||
rlprint('Conflicts: %s' % pkg.conflicts())
|
||||
rlprint('Provides: %s' % pkg.provides())
|
||||
rlprint('Obsoletes: %s' % pkg.obsoletes())
|
||||
print ('Requires: %s' % pkg.requires())
|
||||
print ('Prereq: %s' % pkg.prereq())
|
||||
print ('Conflicts: %s' % pkg.conflicts())
|
||||
print ('Provides: %s' % pkg.provides())
|
||||
print ('Obsoletes: %s' % pkg.obsoletes())
|
||||
pkg.cleanup()
|
||||
|
||||
# Pkg.py ends here
|
||||
|
|
|
@ -32,7 +32,7 @@ class SignatureCheck(AbstractCheck.AbstractCheck):
|
|||
if kres:
|
||||
printError(pkg, "unknown-key", kres.group(1))
|
||||
else:
|
||||
Pkg.rlwarn("Error checking signature of %s: %s" % (pkg.filename, res[1]))
|
||||
Pkg.warn("Error checking signature of %s: %s" % (pkg.filename, res[1]))
|
||||
else:
|
||||
if not SignatureCheck.pgp_regex.search(res[1]):
|
||||
printError(pkg, "no-signature")
|
||||
|
|
8
rpmdiff
8
rpmdiff
|
@ -83,7 +83,7 @@ class Rpmdiff:
|
|||
old = self.__load_pkg(old).header
|
||||
new = self.__load_pkg(new).header
|
||||
except KeyError, e:
|
||||
Pkg.rlwarn(str(e))
|
||||
Pkg.warn(str(e))
|
||||
sys.exit(2)
|
||||
|
||||
# Compare single tags
|
||||
|
@ -239,7 +239,7 @@ class Rpmdiff:
|
|||
return result
|
||||
|
||||
def _usage(exit=1):
|
||||
Pkg.rlprint('''Usage: %s [<options>] <old package> <new package>
|
||||
print ('''Usage: %s [<options>] <old package> <new package>
|
||||
Options:
|
||||
-h, --help Output this message and exit
|
||||
-i, --ignore File property to ignore when calculating differences (may be
|
||||
|
@ -256,7 +256,7 @@ def main():
|
|||
opts, args = getopt.getopt(sys.argv[1:],
|
||||
"hti:", ["help", "ignore-times", "ignore="])
|
||||
except getopt.GetoptError, e:
|
||||
Pkg.rlwarn("Error: %s" % e)
|
||||
Pkg.warn("Error: %s" % e)
|
||||
_usage()
|
||||
|
||||
for option, argument in opts:
|
||||
|
@ -274,7 +274,7 @@ def main():
|
|||
d = Rpmdiff(args[0], args[1], ignore=ignore_tags)
|
||||
textdiff = d.textdiff()
|
||||
if textdiff:
|
||||
Pkg.rlprint(textdiff)
|
||||
print (textdiff)
|
||||
sys.exit(int(d.differs()))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
36
rpmlint.py
36
rpmlint.py
|
@ -38,7 +38,7 @@ _default_user_conf = '%s/rpmlint' % \
|
|||
|
||||
# Print usage information
|
||||
def usage(name):
|
||||
Pkg.rlprint('''usage: %s [<options>] <rpm files|installed packages|specfiles|dirs>
|
||||
print ('''usage: %s [<options>] <rpm files|installed packages|specfiles|dirs>
|
||||
options:
|
||||
\t[-i|--info]
|
||||
\t[-I <messageid,messageid,...>]
|
||||
|
@ -56,7 +56,7 @@ def usage(name):
|
|||
|
||||
# Print version information
|
||||
def printVersion():
|
||||
Pkg.rlprint('rpmlint version %s Copyright (C) 1999-2007 Frederic Lepied, Mandriva' % version)
|
||||
print ('rpmlint version %s Copyright (C) 1999-2007 Frederic Lepied, Mandriva' % version)
|
||||
|
||||
def loadCheck(name):
|
||||
'''Load a (check) module by its name, unless it is already loaded.'''
|
||||
|
@ -121,9 +121,8 @@ def main():
|
|||
except OSError:
|
||||
ipkgs = Pkg.getInstalledPkgs(arg)
|
||||
if not ipkgs:
|
||||
Pkg.rlwarn(
|
||||
'(none): E: no installed packages by name %s'
|
||||
% arg)
|
||||
Pkg.warn(
|
||||
'(none): E: no installed packages by name %s' % arg)
|
||||
else:
|
||||
ipkgs.sort(key = lambda x: locale.strxfrm(
|
||||
x.header.sprintf("%{NAME}.%{ARCH}")))
|
||||
|
@ -131,14 +130,13 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
if isfile:
|
||||
arg = os.path.abspath(arg)
|
||||
Pkg.rlwarn(
|
||||
Pkg.warn(
|
||||
'(none): E: interrupted, exiting while reading %s' % arg)
|
||||
sys.exit(2)
|
||||
except Exception, e:
|
||||
if isfile:
|
||||
arg = os.path.abspath(arg)
|
||||
Pkg.rlwarn(
|
||||
'(none): E: error while reading %s: %s' % (arg, e))
|
||||
Pkg.warn('(none): E: error while reading %s: %s' % (arg, e))
|
||||
pkgs = []
|
||||
continue
|
||||
|
||||
|
@ -166,23 +164,21 @@ def main():
|
|||
specfiles_checked += 1
|
||||
|
||||
except KeyboardInterrupt:
|
||||
Pkg.rlwarn(
|
||||
'(none): E: interrupted, exiting while ' +
|
||||
'reading %s' % fname)
|
||||
Pkg.warn('(none): E: interrupted, exiting while ' +
|
||||
'reading %s' % fname)
|
||||
sys.exit(2)
|
||||
except Exception, e:
|
||||
Pkg.rlwarn(
|
||||
Pkg.warn(
|
||||
'(none): E: while reading %s: %s' % (fname, e))
|
||||
continue
|
||||
except Exception, e:
|
||||
Pkg.rlwarn(
|
||||
Pkg.warn(
|
||||
'(none): E: error while reading dir %s: %s' % (dname, e))
|
||||
continue
|
||||
|
||||
if printAllReasons():
|
||||
Pkg.rlwarn(
|
||||
'(none): E: badness %d exceeds threshold %d, aborting.' %
|
||||
(badnessScore(), badnessThreshold()))
|
||||
Pkg.warn('(none): E: badness %d exceeds threshold %d, aborting.' %
|
||||
(badnessScore(), badnessThreshold()))
|
||||
sys.exit(66)
|
||||
|
||||
finally:
|
||||
|
@ -205,7 +201,7 @@ def runChecks(pkg):
|
|||
if check:
|
||||
check.check(pkg)
|
||||
else:
|
||||
Pkg.rlwarn('(none): W: unknown check %s, skipping' % name)
|
||||
Pkg.warn('(none): W: unknown check %s, skipping' % name)
|
||||
finally:
|
||||
pkg.cleanup()
|
||||
|
||||
|
@ -232,7 +228,7 @@ try:
|
|||
'option=',
|
||||
])
|
||||
except getopt.error, e:
|
||||
Pkg.rlwarn("%s: %s" % (sys.argv[0], e))
|
||||
Pkg.warn("%s: %s" % (sys.argv[0], e))
|
||||
usage(sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -257,7 +253,7 @@ for f in configs:
|
|||
except IOError:
|
||||
pass
|
||||
except Exception, E:
|
||||
Pkg.rlwarn('(none): W: error loading %s, skipping: %s' % (f, E))
|
||||
Pkg.warn('(none): W: error loading %s, skipping: %s' % (f, E))
|
||||
# pychecker fix
|
||||
del f
|
||||
|
||||
|
@ -306,7 +302,7 @@ try:
|
|||
except IOError:
|
||||
pass
|
||||
except Exception,E:
|
||||
Pkg.rlwarn('(none): W: error loading %s, skipping: %s' % (conf_file, E))
|
||||
Pkg.warn('(none): W: error loading %s, skipping: %s' % (conf_file, E))
|
||||
|
||||
# apply config overrides
|
||||
for key, value in config_overrides.items():
|
||||
|
|
Loading…
Reference in New Issue