1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-23 22:58:53 +02:00

python3 compatibility: dict

this patch
 1.) removes the iteritems/itervalues, which were dropped in py3
     items/values are used instead
 2.) add an extra list() in a cases the list-based access is needed
     (included appending, indexing and so)
 3.) changes a sorting idiom in few places
     instead of
     foo = dict.keys()
     foo.sort()
     for i in foo:

     there is a recommended

     for i in sorted(dict.keys()):
 4.) in one occassion it removes a if dict.has_key() by simpler
   dict.get(key, default)
This commit is contained in:
Michal Vyskocil
2013-04-09 11:25:19 +02:00
committed by Adrian Schröter
parent c5a235ed78
commit d3648be24b
6 changed files with 22 additions and 30 deletions

View File

@@ -331,7 +331,7 @@ def get_prefer_pkgs(dirs, wanted_arch, type):
packageQueries.add(packageQuery) packageQueries.add(packageQuery)
prefer_pkgs = dict((name, packageQuery.path()) prefer_pkgs = dict((name, packageQuery.path())
for name, packageQuery in packageQueries.iteritems()) for name, packageQuery in packageQueries.items())
depfile = create_deps(packageQueries.values()) depfile = create_deps(packageQueries.values())
cpio = cpio.CpioWrite() cpio = cpio.CpioWrite()
@@ -631,7 +631,7 @@ def main(apiurl, opts, argv):
else: else:
raise raise
bi = Buildinfo(bi_filename, apiurl, build_type, prefer_pkgs.keys()) bi = Buildinfo(bi_filename, apiurl, build_type, list(prefer_pkgs.keys()))
if bi.debuginfo and not (opts.disable_debuginfo or '--debug' in buildargs): if bi.debuginfo and not (opts.disable_debuginfo or '--debug' in buildargs):
buildargs.append('--debug') buildargs.append('--debug')
@@ -660,7 +660,7 @@ def main(apiurl, opts, argv):
rpmlist_prefers = [] rpmlist_prefers = []
if prefer_pkgs: if prefer_pkgs:
print 'Evaluating preferred packages' print 'Evaluating preferred packages'
for name, path in prefer_pkgs.iteritems(): for name, path in prefer_pkgs.tems():
if bi.has_dep(name): if bi.has_dep(name):
# We remove a preferred package from the buildinfo, so that the # We remove a preferred package from the buildinfo, so that the
# fetcher doesn't take care about them. # fetcher doesn't take care about them.
@@ -804,7 +804,7 @@ def main(apiurl, opts, argv):
else: else:
os.symlink(sffn, tffn) os.symlink(sffn, tffn)
if prefer_pkgs: if prefer_pkgs:
for name, path in prefer_pkgs.iteritems(): for name, path in prefer_pkgs.items():
if name == filename: if name == filename:
print "Using prefered package: " + path + "/" + filename print "Using prefered package: " + path + "/" + filename
os.unlink(tffn) os.unlink(tffn)

View File

@@ -707,10 +707,8 @@ class RawCmdln(cmd.Cmd):
for attr in self.get_names(): for attr in self.get_names():
if attr.startswith("do_"): if attr.startswith("do_"):
cmdnames[attr[3:]] = True cmdnames[attr[3:]] = True
cmdnames = cmdnames.keys()
cmdnames.sort()
linedata = [] linedata = []
for cmdname in cmdnames: for cmdname in sorted(cmdnames.keys()):
if aliases.get(cmdname): if aliases.get(cmdname):
a = aliases[cmdname] a = aliases[cmdname]
a.sort() a.sort()
@@ -770,8 +768,7 @@ class RawCmdln(cmd.Cmd):
helpnames[helpname] = True helpnames[helpname] = True
if helpnames: if helpnames:
helpnames = helpnames.keys() helpnames = sorted(helpnames.keys())
helpnames.sort()
linedata = [(self.name+" help "+n, "") for n in helpnames] linedata = [(self.name+" help "+n, "") for n in helpnames]
subindent = indent + ' '*4 subindent = indent + ' '*4

View File

@@ -4135,7 +4135,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if not pac.todo: if not pac.todo:
pac.todo = pac.filenamelist + pac.filenamelist_unvers pac.todo = pac.filenamelist + pac.filenamelist_unvers
pac.todo.sort() pac.todo.sort()
for prj_path, packages in prj_paths.iteritems(): for prj_path, packages in prj_paths.items():
prj = Project(prj_path) prj = Project(prj_path)
if not msg: if not msg:
msg = get_commit_msg(prj.absdir, pac_objs[prj_path]) msg = get_commit_msg(prj.absdir, pac_objs[prj_path])
@@ -6490,7 +6490,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if role_filter: if role_filter:
role_filter = '%s (%s)' % (search_term, role_filter) role_filter = '%s (%s)' % (search_term, role_filter)
kind_map = {'published/binary/id': 'binary'} kind_map = {'published/binary/id': 'binary'}
for kind, root in res.iteritems(): for kind, root in res.items():
results = [] results = []
for node in root.findall(kind_map.get(kind, kind)): for node in root.findall(kind_map.get(kind, kind)):
result = [] result = []
@@ -7791,7 +7791,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
args = parseargs(args) args = parseargs(args)
pacs = [] pacs = []
apiurls = conf.config['api_host_options'].keys() apiurls = list(conf.config['api_host_options'].keys())
apiurl = '' apiurl = ''
for i in args: for i in args:
if is_project_dir(i): if is_project_dir(i):

View File

@@ -1234,9 +1234,7 @@ class Package:
def __generate_commitlist(self, todo_send): def __generate_commitlist(self, todo_send):
root = ET.Element('directory') root = ET.Element('directory')
keys = todo_send.keys() for i in sorted(todo_send.keys()):
keys.sort()
for i in keys:
ET.SubElement(root, 'entry', name=i, md5=todo_send[i]) ET.SubElement(root, 'entry', name=i, md5=todo_send[i])
return root return root
@@ -2302,10 +2300,7 @@ class Action:
raise oscerr.WrongArgs('invalid argument: \'%s\'' % i) raise oscerr.WrongArgs('invalid argument: \'%s\'' % i)
# set all type specific attributes # set all type specific attributes
for i in Action.type_args[type]: for i in Action.type_args[type]:
if kwargs.has_key(i): setattr(self, i, kwargs.get(i))
setattr(self, i, kwargs[i])
else:
setattr(self, i, None)
def to_xml(self): def to_xml(self):
""" """
@@ -3721,7 +3716,7 @@ def get_review_list(apiurl, project='', package='', byuser='', bygroup='', bypro
todo['project'] = project todo['project'] = project
if package: if package:
todo['package'] = package todo['package'] = package
for kind, val in todo.iteritems(): for kind, val in todo.items():
xpath_base = 'action/target/@%(kind)s=\'%(val)s\' or ' \ xpath_base = 'action/target/@%(kind)s=\'%(val)s\' or ' \
'submit/target/@%(kind)s=\'%(val)s\'' 'submit/target/@%(kind)s=\'%(val)s\''
@@ -3787,7 +3782,7 @@ def get_request_list(apiurl, project='', package='', req_who='', req_state=('new
todo['project'] = project todo['project'] = project
if package: if package:
todo['package'] = package todo['package'] = package
for kind, val in todo.iteritems(): for kind, val in todo.items():
xpath_base = 'action/target/@%(kind)s=\'%(val)s\' or ' \ xpath_base = 'action/target/@%(kind)s=\'%(val)s\' or ' \
'submit/target/@%(kind)s=\'%(val)s\'' 'submit/target/@%(kind)s=\'%(val)s\''
@@ -3827,7 +3822,7 @@ def get_user_projpkgs_request_list(apiurl, user, req_state=('new','review',), re
if not i.get('project') in projects: if not i.get('project') in projects:
projpkgs.setdefault(i.get('project'), []).append(i.get('name')) projpkgs.setdefault(i.get('project'), []).append(i.get('name'))
xpath = '' xpath = ''
for prj, pacs in projpkgs.iteritems(): for prj, pacs in projpkgs.items():
if not len(pacs): if not len(pacs):
xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True) xpath = xpath_join(xpath, 'action/target/@project=\'%s\'' % prj, inner=True)
else: else:
@@ -4493,7 +4488,7 @@ def aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map =
aggregate_template += """\ aggregate_template += """\
<nosources /> <nosources />
""" """
for src, tgt in repo_map.iteritems(): for src, tgt in repo_map.items():
aggregate_template += """\ aggregate_template += """\
<repository target="%s" source="%s" /> <repository target="%s" source="%s" />
""" % (tgt, src) """ % (tgt, src)
@@ -5758,7 +5753,7 @@ def search(apiurl, **kwargs):
GET /search/kindN?match=xpathN GET /search/kindN?match=xpathN
""" """
res = {} res = {}
for urlpath, xpath in kwargs.iteritems(): for urlpath, xpath in kwargs.items():
path = [ 'search' ] path = [ 'search' ]
path += urlpath.split('_') # FIXME: take underscores as path seperators. I see no other way atm to fix OBS api calls and not breaking osc api path += urlpath.split('_') # FIXME: take underscores as path seperators. I see no other way atm to fix OBS api calls and not breaking osc api
u = makeurl(apiurl, path, ['match=%s' % quote_plus(xpath)]) u = makeurl(apiurl, path, ['match=%s' % quote_plus(xpath)])
@@ -6591,7 +6586,7 @@ def filter_role(meta, user, role):
remove all project/package nodes if no person node exists remove all project/package nodes if no person node exists
where @userid=user and @role=role where @userid=user and @role=role
""" """
for kind, root in meta.iteritems(): for kind, root in meta.items():
delete = [] delete = []
for node in root.findall(kind): for node in root.findall(kind):
found = False found = False

View File

@@ -122,7 +122,7 @@ class Fetcher:
archive.copyin_file(hdr.filename, os.path.dirname(tmpfile), os.path.basename(tmpfile)) archive.copyin_file(hdr.filename, os.path.dirname(tmpfile), os.path.basename(tmpfile))
self.move_package(tmpfile, pac.localdir, pac) self.move_package(tmpfile, pac.localdir, pac)
# check if we got all packages... (because we've no .errors file) # check if we got all packages... (because we've no .errors file)
for pac in pkgs.itervalues(): for pac in pkgs.values():
if not os.path.isfile(pac.fullfilename): if not os.path.isfile(pac.fullfilename):
raise oscerr.APIError('failed to fetch file \'%s\': ' \ raise oscerr.APIError('failed to fetch file \'%s\': ' \
'does not exist in CPIO archive' % pac.repofilename) 'does not exist in CPIO archive' % pac.repofilename)
@@ -130,7 +130,7 @@ class Fetcher:
if e.errno != 14 or e.code != 414: if e.errno != 14 or e.code != 414:
raise raise
# query str was too large # query str was too large
keys = pkgs.keys() keys = list(pkgs.keys())
if len(keys) == 1: if len(keys) == 1:
raise oscerr.APIError('unable to fetch cpio archive: server always returns code 414') raise oscerr.APIError('unable to fetch cpio archive: server always returns code 414')
n = len(pkgs) / 2 n = len(pkgs) / 2
@@ -145,7 +145,7 @@ class Fetcher:
os.unlink(tmpfile) os.unlink(tmpfile)
def __fetch_cpio(self, apiurl): def __fetch_cpio(self, apiurl):
for prpap, pkgs in self.cpio.iteritems(): for prpap, pkgs in self.cpio.items():
project, repo, arch, package = prpap.split('/', 3) project, repo, arch, package = prpap.split('/', 3)
self.__download_cpio_archive(apiurl, project, repo, arch, package, **pkgs) self.__download_cpio_archive(apiurl, project, repo, arch, package, **pkgs)
@@ -246,7 +246,7 @@ class Fetcher:
self.__fetch_cpio(buildinfo.apiurl) self.__fetch_cpio(buildinfo.apiurl)
prjs = buildinfo.projects.keys() prjs = list(buildinfo.projects.keys())
for i in prjs: for i in prjs:
dest = "%s/%s" % (self.cachedir, i) dest = "%s/%s" % (self.cachedir, i)
if not os.path.exists(dest): if not os.path.exists(dest):

View File

@@ -62,7 +62,7 @@ class CpioHdr:
self.namesize = namesize self.namesize = namesize
# != 0 indicates CRC format (which we do not support atm) # != 0 indicates CRC format (which we do not support atm)
self.checksum = checksum self.checksum = checksum
for k,v in self.__dict__.iteritems(): for k,v in self.__dict__.items():
self.__dict__[k] = int(v, 16) self.__dict__[k] = int(v, 16)
self.filename = filename self.filename = filename
# data starts at dataoff and ends at dataoff+filesize # data starts at dataoff and ends at dataoff+filesize