More porting to python3

Travis changed default python to 3.6, which has impact on the way
flake8 checks. So make sure we run fine under flake8 of python 3
This commit is contained in:
Stephan Kulow 2019-04-20 21:16:50 +02:00
parent 0016e77e71
commit 595e84191e
17 changed files with 87 additions and 65 deletions

View File

@ -36,6 +36,12 @@ except ImportError:
# python 2.x # python 2.x
from urllib2 import HTTPError, URLError from urllib2 import HTTPError, URLError
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
from itertools import count from itertools import count
class PackageLookup(object): class PackageLookup(object):
@ -867,7 +873,7 @@ class CommandLineInterface(cmdln.Cmdln):
self.logger.info("sleeping %d minutes. Press enter to check now ..."%interval) self.logger.info("sleeping %d minutes. Press enter to check now ..."%interval)
signal.alarm(interval*60) signal.alarm(interval*60)
try: try:
raw_input() input()
except ExTimeout: except ExTimeout:
pass pass
signal.alarm(0) signal.alarm(0)

View File

@ -29,11 +29,17 @@ http_GET = osc.core.http_GET
http_DELETE = osc.core.http_DELETE http_DELETE = osc.core.http_DELETE
http_POST = osc.core.http_POST http_POST = osc.core.http_POST
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
# http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python # http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
def chunks(l, n): def chunks(l, n):
""" Yield successive n-sized chunks from l. """ Yield successive n-sized chunks from l.
""" """
for i in xrange(0, len(l), n): for i in range(0, len(l), n):
yield l[i:i+n] yield l[i:i+n]
class ToolBase(object): class ToolBase(object):
@ -190,7 +196,7 @@ class CommandLineInterface(cmdln.Cmdln):
logger.info("sleeping %d minutes. Press enter to check now ..."%interval) logger.info("sleeping %d minutes. Press enter to check now ..."%interval)
signal.alarm(interval*60) signal.alarm(interval*60)
try: try:
raw_input() input()
except ExTimeout: except ExTimeout:
pass pass
signal.alarm(0) signal.alarm(0)

View File

@ -138,13 +138,13 @@ class CompareList(object):
return return
# get souce packages from target # get souce packages from target
print 'Gathering the package list from %s' % self.old_prj print('Gathering the package list from %s' % self.old_prj)
source = self.get_source_packages(self.old_prj) source = self.get_source_packages(self.old_prj)
print 'Gathering the package list from %s' % self.new_prj print('Gathering the package list from %s' % self.new_prj)
target = self.get_source_packages(self.new_prj) target = self.get_source_packages(self.new_prj)
removed_packages = self.removed_pkglist(self.old_prj) removed_packages = self.removed_pkglist(self.old_prj)
if self.existin: if self.existin:
print 'Gathering the package list from %s' % self.existin print('Gathering the package list from %s' % self.existin)
existin_packages = self.get_source_packages(self.existin) existin_packages = self.get_source_packages(self.existin)
if not self.removedonly: if not self.removedonly:

View File

@ -88,7 +88,7 @@ class DepTool(cmdln.Cmdln):
if parser.has_option(name, 'priority'): if parser.has_option(name, 'priority'):
repo.priority = parser.getint(name, 'priority') repo.priority = parser.getint(name, 'priority')
logger.debug("add repo %s" % name) logger.debug("add repo %s" % name)
except Exception, e: except Exception as e:
logger.error(e) logger.error(e)
def _add_system_repo(self): def _add_system_repo(self):

View File

@ -67,7 +67,7 @@ logging.basicConfig(level=logging.DEBUG if options.debug
format='%(asctime)s - %(module)s:%(lineno)d - %(levelname)s - %(message)s') format='%(asctime)s - %(module)s:%(lineno)d - %(levelname)s - %(message)s')
if options.dump_config: if options.dump_config:
print yaml.dump(config_defaults, default_flow_style=False) print(yaml.dump(config_defaults, default_flow_style=False))
sys.exit(0) sys.exit(0)
config = _load_config(options.config) config = _load_config(options.config)
@ -145,8 +145,8 @@ msg['Date'] = email.utils.formatdate(localtime=1)
msg['Message-ID'] = email.utils.make_msgid() msg['Message-ID'] = email.utils.make_msgid()
if options.dry: if options.dry:
print "sending ..." print("sending ...")
print msg.as_string() print(msg.as_string())
else: else:
logger.info("announcing version {}".format(version)) logger.info("announcing version {}".format(version))
s = smtplib.SMTP(options.relay) s = smtplib.SMTP(options.relay)

View File

@ -35,13 +35,13 @@ class ChangeLogger(cmdln.Cmdln):
h = None h = None
try: try:
h = self.ts.hdrFromFdno(fd) h = self.ts.hdrFromFdno(fd)
except rpm.error, e: except rpm.error as e:
if str(e) == "public key not available": if str(e) == "public key not available":
print str(e) print(str(e))
if str(e) == "public key not trusted": if str(e) == "public key not trusted":
print str(e) print(str(e))
if str(e) == "error reading package header": if str(e) == "error reading package header":
print str(e) print(str(e))
h = None h = None
return h return h
@ -78,7 +78,7 @@ class ChangeLogger(cmdln.Cmdln):
): ):
srpm = '%s-%s-%s.src.rpm'%('kernel-source', m.group('version'), m.group('release')) srpm = '%s-%s-%s.src.rpm'%('kernel-source', m.group('version'), m.group('release'))
pkgdata[h['name']]['sourcerpm'] = srpm pkgdata[h['name']]['sourcerpm'] = srpm
print "%s -> %s"%(h['sourcerpm'], srpm) print("%s -> %s"%(h['sourcerpm'], srpm))
if srpm in changelogs: if srpm in changelogs:
changelogs[srpm]['packages'].append(h['name']) changelogs[srpm]['packages'].append(h['name'])
@ -204,7 +204,7 @@ class ChangeLogger(cmdln.Cmdln):
p1 = set(v1pkgs.keys()) p1 = set(v1pkgs.keys())
p2 = set(v2pkgs.keys()) p2 = set(v2pkgs.keys())
print "Packages changed:" print('Packages changed:')
group = self._get_packages_grouped(v2pkgs, p1&p2) group = self._get_packages_grouped(v2pkgs, p1&p2)
# pprint(p1&p2) # pprint(p1&p2)
# pprint(group) # pprint(group)
@ -218,7 +218,7 @@ class ChangeLogger(cmdln.Cmdln):
try: try:
t1 = v1changelogs[srpm1]['changelogtime'][0] t1 = v1changelogs[srpm1]['changelogtime'][0]
except IndexError: except IndexError:
print >>sys.stderr, srpm1, "doesn't have a changelog" print("{} doesn't have a changelog".format(srpm1), file=sys.stderr)
continue continue
m = SRPM_RE.match(srpm) m = SRPM_RE.match(srpm)
if m: if m:
@ -226,17 +226,17 @@ class ChangeLogger(cmdln.Cmdln):
else: else:
name = srpm name = srpm
if len(v2changelogs[srpm]['changelogtime']) == 0: if len(v2changelogs[srpm]['changelogtime']) == 0:
print " %s ERROR: no changelog"%name print(' {} ERROR: no changelog'.format(name))
continue continue
if t1 == v2changelogs[srpm]['changelogtime'][0]: if t1 == v2changelogs[srpm]['changelogtime'][0]:
continue # no new changelog entry, probably just rebuilt continue # no new changelog entry, probably just rebuilt
pkgs = sorted(group[srpm]) pkgs = sorted(group[srpm])
details += "\n==== %s ====\n"%name details += "\n==== %s ====\n"%name
if v1pkgs[pkgs[0]]['version'] != v2pkgs[pkgs[0]]['version']: if v1pkgs[pkgs[0]]['version'] != v2pkgs[pkgs[0]]['version']:
print " %s (%s -> %s)"%(name, v1pkgs[pkgs[0]]['version'], v2pkgs[pkgs[0]]['version']) print(" %s (%s -> %s)"%(name, v1pkgs[pkgs[0]]['version'], v2pkgs[pkgs[0]]['version']))
details += "Version update (%s -> %s)\n"%(v1pkgs[pkgs[0]]['version'], v2pkgs[pkgs[0]]['version']) details += "Version update (%s -> %s)\n" % (v1pkgs[pkgs[0]]['version'], v2pkgs[pkgs[0]]['version'])
else: else:
print " %s"%name print(" %s" % name)
if len(pkgs) > 1: if len(pkgs) > 1:
details += "Subpackages: %s\n"%" ".join([p for p in pkgs if p != name]) details += "Subpackages: %s\n"%" ".join([p for p in pkgs if p != name])
for (i2, t2) in enumerate(v2changelogs[srpm]['changelogtime']): for (i2, t2) in enumerate(v2changelogs[srpm]['changelogtime']):
@ -245,8 +245,8 @@ class ChangeLogger(cmdln.Cmdln):
details += "\n" + v2changelogs[srpm]['changelogtext'][i2] details += "\n" + v2changelogs[srpm]['changelogtext'][i2]
details += '\n' details += '\n'
print "\n=== Details ===" print("\n=== Details ===")
print details print(details)
def get_optparser(self): def get_optparser(self):
parser = cmdln.CmdlnOptionParser(self) parser = cmdln.CmdlnOptionParser(self)
@ -266,4 +266,3 @@ class ChangeLogger(cmdln.Cmdln):
if __name__ == "__main__": if __name__ == "__main__":
app = ChangeLogger() app = ChangeLogger()
sys.exit( app.main() ) sys.exit( app.main() )

View File

@ -266,13 +266,13 @@ class FccSubmitter(object):
logging.info('No build succeeded package in %s'%self.from_prj) logging.info('No build succeeded package in %s'%self.from_prj)
return return
print 'Build succeeded packages:' print('Build succeeded packages:')
print '-------------------------------------' print('-------------------------------------')
for pkg in succeeded_packages: for pkg in succeeded_packages:
print pkg print(pkg)
print '-------------------------------------' print('-------------------------------------')
print "Found {} build succeded packages".format(len(succeeded_packages)) print("Found {} build succeded packages".format(len(succeeded_packages)))
def get_deleted_packages(self, project): def get_deleted_packages(self, project):
query = 'states=accepted&types=delete&project={}&view=collection' query = 'states=accepted&types=delete&project={}&view=collection'
@ -403,9 +403,9 @@ class FccSubmitter(object):
print("Multi-specfile packages:") print("Multi-specfile packages:")
if ms_packages: if ms_packages:
for pkg in ms_packages: for pkg in ms_packages:
print pkg print(pkg)
else: else:
print 'None' print('None')
@ -415,7 +415,7 @@ def main(args):
osc.conf.config['debug'] = args.debug osc.conf.config['debug'] = args.debug
if args.freeze: if args.freeze:
print "freezing {}".format(FCC) print('freezing {}'.format(FCC))
freezer = FccFreezer() freezer = FccFreezer()
freezer.freeze() freezer.freeze()
else: else:

View File

@ -26,6 +26,12 @@ from osclib.core import package_list
from osclib.git import CACHE_DIR from osclib.git import CACHE_DIR
from osclib.git import sync from osclib.git import sync
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
# Issue summary can contain unicode characters and therefore a string containing # Issue summary can contain unicode characters and therefore a string containing
# either summary or one in which ISSUE_SUMMARY is then placed must be unicode. # either summary or one in which ISSUE_SUMMARY is then placed must be unicode.
# For example, translation-update-upstream contains bsc#877707 which has a # For example, translation-update-upstream contains bsc#877707 which has a
@ -106,7 +112,7 @@ def prompt_continue(change_count):
else: else:
print('No changes for which to create bug, continue? [y/b/s/n/?] (y): ', end='') print('No changes for which to create bug, continue? [y/b/s/n/?] (y): ', end='')
response = raw_input().lower() response = input().lower()
if response == '?': if response == '?':
print('b = break; file bug if applicable, record in db, and stop\ns = skip package') print('b = break; file bug if applicable, record in db, and stop\ns = skip package')
elif response in allowed: elif response in allowed:

View File

@ -7,6 +7,12 @@ from osclib.cache_manager import CacheManager
import subprocess import subprocess
import sys import sys
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
CACHE_DIR = CacheManager.directory('k8s-secret') CACHE_DIR = CacheManager.directory('k8s-secret')
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
@ -15,10 +21,10 @@ def secret_create(cache_file):
environment = {'OSCRC': cache_file} environment = {'OSCRC': cache_file}
print('Username: ', end='') print('Username: ', end='')
environment['OBS_USER'] = raw_input() environment['OBS_USER'] = input()
print('Password: ', end='') print('Password: ', end='')
environment['OBS_PASS'] = raw_input() environment['OBS_PASS'] = input()
osc_init = os.path.join(SCRIPT_PATH, 'dist/ci/osc-init') osc_init = os.path.join(SCRIPT_PATH, 'dist/ci/osc-init')
subprocess.Popen([osc_init], env=environment).wait() subprocess.Popen([osc_init], env=environment).wait()
@ -37,7 +43,7 @@ def main(args):
print(f.read()) print(f.read())
print('Apply secret for {} [y/n] (y): '.format(args.prefix), end='') print('Apply secret for {} [y/n] (y): '.format(args.prefix), end='')
response = raw_input().lower() response = input().lower()
if response != '' and response != 'y': if response != '' and response != 'y':
return return

View File

@ -58,9 +58,9 @@ class LegalAuto(ReviewBot.ReviewBot):
def retried_GET(self, url): def retried_GET(self, url):
try: try:
return http_GET(url) return http_GET(url)
except HTTPError, e: except HTTPError as e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
print 'Retrying {}'.format(url) print('Retrying {}'.format(url))
time.sleep(1) time.sleep(1)
return self.retried_GET(url) return self.retried_GET(url)
raise e raise e
@ -109,7 +109,7 @@ class LegalAuto(ReviewBot.ReviewBot):
url = osc.core.makeurl(self.legaldb, ['package', str(pack)]) url = osc.core.makeurl(self.legaldb, ['package', str(pack)])
report = REQ.get(url, headers=self.legaldb_headers).json() report = REQ.get(url, headers=self.legaldb_headers).json()
if report.get('priority', 0) != self.request_priority(): if report.get('priority', 0) != self.request_priority():
print "Update priority %d" % self.request_priority() print('Update priority {}'.format(self.request_priority()))
url = osc.core.makeurl( url = osc.core.makeurl(
self.legaldb, ['package', str(pack)], {'priority': self.request_priority()}) self.legaldb, ['package', str(pack)], {'priority': self.request_priority()})
REQ.patch(url, headers=self.legaldb_headers) REQ.patch(url, headers=self.legaldb_headers)
@ -249,7 +249,7 @@ class LegalAuto(ReviewBot.ReviewBot):
if match and match.group(1) == package: if match and match.group(1) == package:
lpackage = package lpackage = package
if package != lpackage: if package != lpackage:
print "SKIP", package, "it links to", lpackage print("SKIP", package, "it links to", lpackage)
skip = True skip = True
break break
if skip: if skip:
@ -291,7 +291,7 @@ class LegalAuto(ReviewBot.ReviewBot):
return None return None
if not 'saved' in obj: if not 'saved' in obj:
return None return None
print "PKG", tproject, sproject, package, revision, obj['saved']['id'] print("PKG", tproject, sproject, package, revision, obj['saved']['id'])
self.pkg_cache[hkey] = obj['saved']['id'] self.pkg_cache[hkey] = obj['saved']['id']
return self.pkg_cache[hkey] return self.pkg_cache[hkey]

View File

@ -15,24 +15,24 @@ def do_cycle(self, subcmd, opts, *args):
""" """
if len(args) == 0: if len(args) == 0:
print ("No packages were specified, no chain to draw") print("No packages were specified, no chain to draw")
apiurl = self.get_api_url() apiurl = self.get_api_url()
print ("digraph depgraph {") print("digraph depgraph {")
args = [pkg.strip() for pkglist in args for pkg in pkglist.split(',') if pkg.strip()] args = [pkg.strip() for pkglist in args for pkg in pkglist.split(',') if pkg.strip()]
for pkgname in args: for pkgname in args:
try: try:
deps = ET.fromstring(get_dependson(apiurl, opts.project, opts.repository, opts.arch, [pkgname])) deps = ET.fromstring(get_dependson(apiurl, opts.project, opts.repository, opts.arch, [pkgname]))
pkg = deps.find('package') pkg = deps.find('package')
print ("\"%s\"" % pkgname) print("\"%s\"" % pkgname)
for deps in pkg.findall('pkgdep'): for deps in pkg.findall('pkgdep'):
if deps.text in args: if deps.text in args:
print ("\"%s\" -> \"%s\"" % (deps.text, pkgname)) print("\"%s\" -> \"%s\"" % (deps.text, pkgname))
except: except:
# Ignore packages that do not exist # Ignore packages that do not exist
print ("[color=red]") print("[color=red]")
continue continue
print ("}") print("}")

View File

@ -39,6 +39,12 @@ from osclib.request_splitter import RequestSplitter
from osclib.supersede_command import SupersedeCommand from osclib.supersede_command import SupersedeCommand
from osclib.prio_command import PrioCommand from osclib.prio_command import PrioCommand
try:
import __builtin__
input = getattr(__builtin__, 'raw_input')
except (ImportError, AttributeError):
pass
def _print_version(self): def _print_version(self):
from osclib.common import VERSION from osclib.common import VERSION
@ -632,7 +638,7 @@ def do_staging(self, subcmd, opts, *args):
if opts.non_interactive: if opts.non_interactive:
print('y') print('y')
else: else:
response = raw_input().lower() response = input().lower()
if response != '' and response != 'y': if response != '' and response != 'y':
print('Quit') print('Quit')
return return

View File

@ -99,7 +99,7 @@ class StagingHelper(object):
"""Main method""" """Main method"""
rebuild_data = self.api.pseudometa_file_load('support_pkg_rebuild') rebuild_data = self.api.pseudometa_file_load('support_pkg_rebuild')
if rebuild_data is None: if rebuild_data is None:
print "There is no support_pkg_rebuild file!" print("There is no support_pkg_rebuild file!")
return return
logging.info('Gathering support package list from %s' % self.project) logging.info('Gathering support package list from %s' % self.project)

View File

@ -7,15 +7,6 @@ from obs import OBS
from osclib.conf import Config from osclib.conf import Config
from osclib.stagingapi import StagingAPI from osclib.stagingapi import StagingAPI
PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
else:
string_types = basestring,
class TestApiCalls(unittest.TestCase): class TestApiCalls(unittest.TestCase):
""" """
Tests for various api calls to ensure we return expected content Tests for various api calls to ensure we return expected content

View File

@ -19,8 +19,8 @@ class TestComment(unittest.TestCase):
} }
def test_truncate(self): def test_truncate(self):
comment = "string of text" comment = 'string of text'
for i in xrange(len(comment) + 1): for i in range(len(comment) + 1):
truncated = self.api.truncate(comment, length=i) truncated = self.api.truncate(comment, length=i)
print(truncated) print(truncated)
self.assertEqual(len(truncated), i) self.assertEqual(len(truncated), i)
@ -47,7 +47,7 @@ handle
</pre> </pre>
""".strip() """.strip()
for i in xrange(len(comment) + len('...\n</pre>')): for i in range(len(comment) + len('...\n</pre>')):
truncated = self.api.truncate(comment, length=i) truncated = self.api.truncate(comment, length=i)
print('=' * 80) print('=' * 80)
print(truncated) print(truncated)

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os import os
import shutil import shutil
import unittest import unittest
@ -14,7 +16,7 @@ class TestPkgCache(unittest.TestCase):
self.cache = PkgCache('/tmp/cache', force_clean=True) self.cache = PkgCache('/tmp/cache', force_clean=True)
for fn in ('file_a', 'file_b', 'file_c'): for fn in ('file_a', 'file_b', 'file_c'):
with open(os.path.join('/tmp', fn), 'w') as f: with open(os.path.join('/tmp', fn), 'w') as f:
print >>f, fn print(fn, file=f)
def tearDown(self): def tearDown(self):
"""Clean the environment.""" """Clean the environment."""

View File

@ -37,7 +37,7 @@ http_GET = osc.core.http_GET
def chunks(l, n): def chunks(l, n):
""" Yield successive n-sized chunks from l. """ Yield successive n-sized chunks from l.
""" """
for i in xrange(0, len(l), n): for i in range(0, len(l), n):
yield l[i:i+n] yield l[i:i+n]
class UpdateCrawler(object): class UpdateCrawler(object):
@ -87,7 +87,7 @@ class UpdateCrawler(object):
return http_GET(url) return http_GET(url)
except HTTPError as e: except HTTPError as e:
if 500 <= e.code <= 599: if 500 <= e.code <= 599:
print 'Retrying {}'.format(url) print('Retrying {}'.format(url))
time.sleep(1) time.sleep(1)
return self.retried_GET(url) return self.retried_GET(url)
raise e raise e
@ -169,7 +169,7 @@ class UpdateCrawler(object):
def _submitrequest(self, src_project, src_package, rev, dst_project, def _submitrequest(self, src_project, src_package, rev, dst_project,
dst_package, msg): dst_package, msg):
res = 0 res = 0
print "creating submit request", src_project, src_package, rev, dst_project, dst_package print("creating submit request", src_project, src_package, rev, dst_project, dst_package)
if not self.dryrun: if not self.dryrun:
res = osc.core.create_submit_request(self.apiurl, res = osc.core.create_submit_request(self.apiurl,
src_project, src_project,