From e8d6801f98c9b8e556adc16dbf5c174307020335 Mon Sep 17 00:00:00 2001 From: "biao716.wang" Date: Thu, 3 Nov 2022 16:55:32 +0900 Subject: [PATCH] port code from python2.x to python3.x Change-Id: Iebed78d34b8d8355068123f09bede0e24be1aafd Signed-off-by: biao716.wang --- bsr/bsr/__version__.py | 2 +- bsr/bsr/analyzer/data_analyzer.py | 6 +-- bsr/bsr/gbs/gbs_actions.py | 4 +- bsr/bsr/network/dep_parse.py | 20 ++++---- bsr/bsr/report/depends_xml.py | 2 +- bsr/bsr/utility/monitoring.py | 2 +- bsr/bsr/utility/utils.py | 10 ++-- bsr/setup.py | 2 +- debian/control | 22 ++++---- debian/rules | 6 +-- gitbuildsys/cmd_build.py | 8 +-- gitbuildsys/cmd_depends.py | 4 +- gitbuildsys/cmd_devel.py | 4 +- gitbuildsys/cmd_export.py | 4 +- gitbuildsys/cmd_remotebuild.py | 10 ++-- gitbuildsys/conf.py | 21 ++++---- gitbuildsys/oscapi.py | 27 +++++----- gitbuildsys/parsing.py | 4 +- gitbuildsys/safe_url.py | 16 +++--- gitbuildsys/utils.py | 2 +- packaging/gbs.spec | 83 +++++++++++++++---------------- setup.py | 6 +-- tests/test_config.py | 6 +-- tests/test_help.py | 2 +- tests/test_passwdx.py | 14 +++--- tests/test_profile.py | 42 ++++++++-------- tools/gbs | 2 +- 27 files changed, 164 insertions(+), 167 deletions(-) diff --git a/bsr/bsr/__version__.py b/bsr/bsr/__version__.py index 6c9ad8f..064e1f4 100644 --- a/bsr/bsr/__version__.py +++ b/bsr/bsr/__version__.py @@ -9,4 +9,4 @@ __author__ = 'Hyokeun Jeon' __author_email__ = 'hyokeun.jeon@samsung.com' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2020 Samsung Research' -__cake__ = u'\u2728 \U0001f370 \u2728' +__cake__ = '\u2728 \U0001f370 \u2728' diff --git a/bsr/bsr/analyzer/data_analyzer.py b/bsr/bsr/analyzer/data_analyzer.py index 33ade9c..5801c47 100755 --- a/bsr/bsr/analyzer/data_analyzer.py +++ b/bsr/bsr/analyzer/data_analyzer.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2021 Samsung Electronics.Co.Ltd. @@ -124,7 +124,7 @@ class DataAnalyzer: for package in self.topology_sorted[level]: for dep in self.edges[package]: count_link[package][dep] = 1 - zipped = zip(count_link[package], count_link[dep]) + zipped = list(zip(count_link[package], count_link[dep])) count_link[package] = list(starmap(or_, zipped)) self.count_link_map = count_link @@ -190,7 +190,7 @@ class DataAnalyzer: console('{} does not exists in the top order'.format(package), verbose=True) # [[pkg1, 39], [pkg2, 21], [pkg2, 7], ...] - top_links_order = sorted(top_links_order.items(), key=lambda x: x[1], reverse=True) + top_links_order = sorted(list(top_links_order.items()), key=lambda x: x[1], reverse=True) console('Total #{} items...'.format(len(top_links_order)), verbose=self.verbose) diff --git a/bsr/bsr/gbs/gbs_actions.py b/bsr/bsr/gbs/gbs_actions.py index 38d5ec7..471fd8c 100755 --- a/bsr/bsr/gbs/gbs_actions.py +++ b/bsr/bsr/gbs/gbs_actions.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2021 Samsung Electronics.Co.Ltd. @@ -19,7 +19,7 @@ import subprocess import shutil try: - from ConfigParser import SafeConfigParser + from configparser import SafeConfigParser except ImportError: from configparser import SafeConfigParser diff --git a/bsr/bsr/network/dep_parse.py b/bsr/bsr/network/dep_parse.py index 49a36a9..8d943a5 100644 --- a/bsr/bsr/network/dep_parse.py +++ b/bsr/bsr/network/dep_parse.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2021 Samsung Electronics.Co.Ltd. @@ -91,7 +91,7 @@ def make_edges(nodes, sorted_info, dep_packages, cycle_edges, reduced_info): edges.add(short_item) level = level + 1 - for src_pkg, dst_pkgs in cycle_edges.items(): + for src_pkg, dst_pkgs in list(cycle_edges.items()): for dst_pkg in dst_pkgs: if src_pkg in nodes and dst_pkg in nodes: edges.add((src_pkg, dst_pkg, 'true')) @@ -110,7 +110,7 @@ def make_full_edges(nodes, dep_packages, cycle_edges): if dst_pkg in nodes: edges.add((pkg, dst_pkg, 'false')) - for src_pkg, dst_pkgs in cycle_edges.items(): + for src_pkg, dst_pkgs in list(cycle_edges.items()): for dst_pkg in dst_pkgs: if src_pkg in nodes and dst_pkg in nodes: edges.add((src_pkg, dst_pkg, 'true')) @@ -154,7 +154,7 @@ def topology_sort_package(nodes, dep_packages, in_edge_count, cycle_edges, reduc # compensate nodes. # if a node is in cycle_edges, insert it into the nodes. - for src, dst_pkgs in cycle_edges.items(): + for src, dst_pkgs in list(cycle_edges.items()): if src not in nodes: continue for dst_pkg in dst_pkgs: @@ -183,7 +183,7 @@ def find_main_package_name(sub_pkg_name, share_var): # If it is a main package, we cannot find it in sub_main_pkg. # In this case, just return the package name - if sub_pkg_name in share_var.main_sub_pkg.keys(): + if sub_pkg_name in list(share_var.main_sub_pkg.keys()): return sub_pkg_name if not sub_pkg_name in share_var.sub_main_pkg: @@ -200,8 +200,8 @@ def insert_sub_package(pkg_name, sub_pkg_name, share_var): share_var.main_sub_pkg[pkg_name].append(sub_pkg_name) if sub_pkg_name in share_var.sub_main_pkg: - print('Subpackage ' + sub_pkg_name + ' is related to one or more main ' + 'packages(' \ - + share_var.sub_main_pkg[sub_pkg_name] + ',' + pkg_name + ')!\n') + print(('Subpackage ' + sub_pkg_name + ' is related to one or more main ' + 'packages(' \ + + share_var.sub_main_pkg[sub_pkg_name] + ',' + pkg_name + ')!\n')) share_var.sub_main_pkg[sub_pkg_name] = pkg_name share_var.pkg_print_index[sub_pkg_name] = 0 @@ -240,7 +240,7 @@ def remove_cycle(main_pkg_edges, full_in_edge_count): for dst in dst_pkgs: if dst in path: # cycle! - print("removing cycle (" + node + "->" + dst + ")") + print(("removing cycle (" + node + "->" + dst + ")")) if node not in cycle_edges: cycle_edges[node] = set() cycle_edges[node].add(dst) @@ -250,7 +250,7 @@ def remove_cycle(main_pkg_edges, full_in_edge_count): visit(level + 1, dst) path.remove(node) - for pkg in main_pkg_edges.keys(): + for pkg in list(main_pkg_edges.keys()): visit(0, pkg) return main_pkg_edges, cycle_edges, full_in_edge_count @@ -398,7 +398,7 @@ def make_dep_graph(input_file_contents, dest_dir_name, package_name_ids): main_pkg_reverse_edges = {} full_in_reverse_edge_count = {} # generate main_pkg_edges using sub_pkg_edges - for src, dst_pkgs in share_var.sub_pkg_edges.items(): + for src, dst_pkgs in list(share_var.sub_pkg_edges.items()): src_main = find_main_package_name(src, share_var) if src_main is None: continue diff --git a/bsr/bsr/report/depends_xml.py b/bsr/bsr/report/depends_xml.py index 575bb86..e1040eb 100755 --- a/bsr/bsr/report/depends_xml.py +++ b/bsr/bsr/report/depends_xml.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2021 Samsung Electronics.Co.Ltd. diff --git a/bsr/bsr/utility/monitoring.py b/bsr/bsr/utility/monitoring.py index 312b728..ff54b09 100755 --- a/bsr/bsr/utility/monitoring.py +++ b/bsr/bsr/utility/monitoring.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright (c) 2021 Samsung Electronics.Co.Ltd. diff --git a/bsr/bsr/utility/utils.py b/bsr/bsr/utility/utils.py index eec185b..805fcae 100755 --- a/bsr/bsr/utility/utils.py +++ b/bsr/bsr/utility/utils.py @@ -30,8 +30,8 @@ try: import http.server import socketserver except ImportError: - import SimpleHTTPServer - import SocketServer + import http.server + import socketserver from datetime import datetime, timedelta @@ -39,7 +39,7 @@ from datetime import datetime, timedelta def console(text, level='INFO', verbose=False): """logging wrapper""" if verbose is True: - print('[{}] {}'.format(level, text)) + print(('[{}] {}'.format(level, text))) sys.stdout.flush() @@ -242,8 +242,8 @@ def serve_web(port, root_dir): handler = http.server.SimpleHTTPRequestHandler httpd = socketserver.TCPServer(("", port), handler) except NameError: - handler = SimpleHTTPServer.SimpleHTTPRequestHandler + handler = http.server.SimpleHTTPRequestHandler handler.extensions_map.update({'.webapp': 'application/x-web-app-manifest+json'}) - httpd = SocketServer.TCPServer(("", port), handler) + httpd = socketserver.TCPServer(("", port), handler) httpd.allow_reuse_address = True httpd.serve_forever() diff --git a/bsr/setup.py b/bsr/setup.py index f2c757a..323e297 100644 --- a/bsr/setup.py +++ b/bsr/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """A setuptools based setup module. """ diff --git a/debian/control b/debian/control index a2d37d5..ddae7a1 100755 --- a/debian/control +++ b/debian/control @@ -2,17 +2,17 @@ Source: gbs Section: devel Priority: extra Maintainer: Jian-feng Ding -Build-Depends: debhelper, python (>= 2.6), python-docutils, python-setuptools +Build-Depends: debhelper, dh-python, python3, python3-docutils, python3-setuptools Standards-Version: 3.8.0 X-Python-Version: >= 2.6 Homepage: http://www.tizen.org Package: gbs Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, - python-pycurl, - python-requests, - python-lxml, +Depends: ${misc:Depends}, ${python3:Depends}, + python3-pycurl, + python3-requests, + python3-lxml, sudo, osc (>= 0.132.6), git-buildpackage-rpm (>= 0.9.21-tizen20210514), @@ -28,8 +28,8 @@ Description: Command line tools for Tizen package developers Package: gbs-api Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, - python-pycurl, +Depends: ${misc:Depends}, ${python3:Depends}, + python3-pycurl, osc (>= 0.132.6), git-buildpackage-rpm Conflicts: gbs (<< 0.15) @@ -40,7 +40,7 @@ Description: GBS API Package: gbs-export Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, +Depends: ${misc:Depends}, ${python3:Depends}, gbs-api (= ${binary:Version}), pristine-tar (>= 1.35-tizen20161231), git-buildpackage-rpm @@ -52,7 +52,7 @@ Description: GBS export API Package: gbs-remotebuild Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, +Depends: ${misc:Depends}, ${python3:Depends}, gbs-api (= ${binary:Version}), gbs-export (= ${binary:Version}), git-buildpackage-rpm @@ -78,7 +78,7 @@ Description: Jenkins scripts used by gbs-jenkins-job Package: gbs-bsr Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, - python-psutil +Depends: ${misc:Depends}, ${python3:Depends}, + python3-psutil Description: GBS build monitirong scripts This package monitors the build status and generates report using the relevant data. diff --git a/debian/rules b/debian/rules index 3d82e78..2e96989 100644 --- a/debian/rules +++ b/debian/rules @@ -1,12 +1,12 @@ #!/usr/bin/make -f %: - dh $@ + dh $@ --with python3 --buildsystem=pybuild override_dh_auto_install: - python setup.py install --root=debian/tmp --prefix=/usr + python3 setup.py install --root=debian/tmp --prefix=/usr make man - cd bsr && python setup.py install --install-scripts=/usr/local/bin --root=../debian/tmp --prefix=/usr/local && cd .. + cd bsr && python3 setup.py install --install-scripts=/usr/local/bin --root=../debian/tmp --prefix=/usr/local && cd .. mkdir -p debian/tmp/usr/share/man/man1 mkdir -p debian/tmp/usr/share/gbs install -m644 docs/gbs.1 debian/tmp/usr/share/man/man1 diff --git a/gitbuildsys/cmd_build.py b/gitbuildsys/cmd_build.py index 5b76dba..a83b274 100644 --- a/gitbuildsys/cmd_build.py +++ b/gitbuildsys/cmd_build.py @@ -23,7 +23,7 @@ import os import shutil import pwd import re -import urlparse +import urllib.parse import glob import gzip import requests @@ -140,7 +140,7 @@ def prepare_repos_and_build_conf(args, arch, profile): if args.repositories: for repo in args.repositories: try: - if not urlparse.urlsplit(repo).scheme: + if not urllib.parse.urlsplit(repo).scheme: if os.path.exists(repo): repo = os.path.abspath(os.path.expanduser(repo)) else: @@ -426,7 +426,7 @@ def create_autoconf(arch, snapshot, full_build): content += '[general]\nfallback_to_native = true\nprofile = ' + default + '\n' repos_map = {} - for k, v in obs_meta.iteritems(): + for k, v in obs_meta.items(): ref_id = ref_meta.get(v) if ref_id == None: ref_id = 'latest' @@ -463,7 +463,7 @@ def create_autoconf(arch, snapshot, full_build): content += '[repo.' + k + '_' + repo + '_pkgs]\n' content += 'url = ' + url + '/builddata/depends/' + v + '_' + repo + '_' + arch + '_revpkgdepends.xml\n' - for k, v in profile_meta.iteritems(): + for k, v in profile_meta.items(): content += '[profile.' + k + ']\n' if full_build: v = v[:v.index('repo.' + k) - 1] diff --git a/gitbuildsys/cmd_depends.py b/gitbuildsys/cmd_depends.py index d9ecc20..73d7991 100644 --- a/gitbuildsys/cmd_depends.py +++ b/gitbuildsys/cmd_depends.py @@ -22,7 +22,7 @@ import os import shutil import pwd import re -import urlparse +import urllib.parse import glob import requests import subprocess @@ -81,7 +81,7 @@ def prepare_repos_and_build_conf(args, arch, profile): if args.repositories: for repo in args.repositories: try: - if not urlparse.urlsplit(repo).scheme: + if not urllib.parse.urlsplit(repo).scheme: if os.path.exists(repo): repo = os.path.abspath(os.path.expanduser(repo)) else: diff --git a/gitbuildsys/cmd_devel.py b/gitbuildsys/cmd_devel.py index 6ad0190..6fb743e 100644 --- a/gitbuildsys/cmd_devel.py +++ b/gitbuildsys/cmd_devel.py @@ -68,8 +68,8 @@ def update_local_conf(repo, values): log.info('Updating local .gbs.conf') with open(conf_fn, 'a+') as conf_fp: parser.readfp(conf_fp) - for section, items in values.iteritems(): - for key, value in items.iteritems(): + for section, items in values.items(): + for key, value in items.items(): parser.set_into_file(section, key, value) parser.update() diff --git a/gitbuildsys/cmd_export.py b/gitbuildsys/cmd_export.py index eea01f0..99b71aa 100644 --- a/gitbuildsys/cmd_export.py +++ b/gitbuildsys/cmd_export.py @@ -24,7 +24,7 @@ import re import shutil import glob import errno -from urlparse import urlparse +from urllib.parse import urlparse from gitbuildsys import utils from gitbuildsys.conf import configmgr @@ -122,7 +122,7 @@ def create_gbp_export_args(repo, commit, export_dir, tmp_dir, spec, args, reponame = "" remotes = repo.get_remote_repos() if remotes: - remotename = 'origin' if 'origin' in remotes else remotes.keys()[0] + remotename = 'origin' if 'origin' in remotes else list(remotes.keys())[0] # Take the remote repo of current branch, if available try: config_remote = repo.get_config('branch.%s.remote' % repo.branch) diff --git a/gitbuildsys/cmd_remotebuild.py b/gitbuildsys/cmd_remotebuild.py index 887fca6..bbde549 100644 --- a/gitbuildsys/cmd_remotebuild.py +++ b/gitbuildsys/cmd_remotebuild.py @@ -160,11 +160,11 @@ def main(args): archlist = [] status = api.get_results(target_prj, package) - for build_repo in status.keys(): + for build_repo in list(status.keys()): for arch in status[build_repo]: archlist.append('%-15s%-15s' % (build_repo, arch)) - if not obs_repo or not obs_arch or obs_repo not in status.keys() \ - or obs_arch not in status[obs_repo].keys(): + if not obs_repo or not obs_arch or obs_repo not in list(status.keys()) \ + or obs_arch not in list(status[obs_repo].keys()): raise GbsError('no valid repo / arch specified for buildlog, '\ 'valid arguments of repo and arch are:\n%s' % \ '\n'.join(archlist)) @@ -175,7 +175,7 @@ def main(args): status[obs_repo][obs_arch])) log.info('build log for %s/%s/%s/%s' % (target_prj, package, obs_repo, obs_arch)) - print(api.get_buildlog(target_prj, package, obs_repo, obs_arch)) + print((api.get_buildlog(target_prj, package, obs_repo, obs_arch))) return 0 @@ -184,7 +184,7 @@ def main(args): status = api.get_results(target_prj, package) - for build_repo in status.keys(): + for build_repo in list(status.keys()): for arch in status[build_repo]: stat = status[build_repo][arch] results.append('%-15s%-15s%-15s' % (build_repo, arch, stat)) diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index a0fd40a..12cf5a6 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -19,13 +19,13 @@ Provides classes and functions to read and write gbs.conf. ''' -from __future__ import with_statement + import os import re import base64 import shutil from collections import namedtuple -from ConfigParser import SafeConfigParser, \ +from configparser import SafeConfigParser, \ MissingSectionHeaderError, Error from gitbuildsys import errors @@ -257,9 +257,9 @@ url = http://download.tizen.org/releases/daily/trunk/ivi/latest/ def _create_default_parser(self): 'create a default parser that handle DEFAULTS values' parser = BrainConfigParser() - for sec, options in self.DEFAULTS.iteritems(): + for sec, options in self.DEFAULTS.items(): parser.add_section(sec) - for key, val in options.iteritems(): + for key, val in options.items(): parser.set(sec, key, val) return parser @@ -381,22 +381,19 @@ url = http://download.tizen.org/releases/daily/trunk/ivi/latest/ try: return cfgparser.get(section, opt) except Error as err: - pass - raise errors.ConfigError(err) + raise errors.ConfigError(err) def options(self, section='general'): 'merge and return options of certain section from multi-levels' sect_found = False + global gerr options = set() for cfgparser in self._cfgparsers: try: options.update(cfgparser.options(section)) sect_found = True except Error as err: - pass - - if not sect_found: - raise errors.ConfigError(err) + raise errors.ConfigError(err) return options @@ -599,7 +596,7 @@ class BizConfigManager(ConfigMgr): except KeyError as err: raise errors.ConfigError('unknown key: %s. Supportted '\ 'keys are %s' % (str(err), ' '.join( \ - self.DEFAULTS['general'].keys()))) + list(self.DEFAULTS['general'].keys())))) return value def is_profile_oriented(self): @@ -766,7 +763,7 @@ class BizConfigManager(ConfigMgr): repos[key]['passwd'] = value else: repos[key][name] = value - return sorted(repos.items(), key=lambda i: i[0]) + return sorted(list(repos.items()), key=lambda i: i[0]) def _build_profile_by_subcommand(self): '''return profile object from subcommand oriented style of config''' diff --git a/gitbuildsys/oscapi.py b/gitbuildsys/oscapi.py index 930d5d1..23afe39 100644 --- a/gitbuildsys/oscapi.py +++ b/gitbuildsys/oscapi.py @@ -24,13 +24,14 @@ Only APIs which are required by cmd_remotebuild present here. import os import re -import urllib2 +import urllib.request, urllib.error, urllib.parse import M2Crypto from M2Crypto.SSL.Checker import SSLVerificationError import ssl from collections import defaultdict -from urllib import quote_plus, pathname2url +from urllib.parse import quote_plus +from urllib.request import pathname2url from xml.etree import cElementTree as ET @@ -60,7 +61,7 @@ class OSC(object): 'for specified oscrc: %s' % oscrc) raise # else - except urllib2.URLError: + except urllib.error.URLError: raise ObsError("invalid service apiurl: %s" % apiurl) else: conf.get_config() @@ -79,13 +80,13 @@ class OSC(object): for count in (1, 2, 3): try: return method(url, data=data, file=filep) - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError, ssl.SSLError) as err: if count == 3: raise OSCError(str(err)) raise OSCError('Got empty response from %s %s' % \ - (method.func_name.split('_')[-1], url)) + (method.__name__.split('_')[-1], url)) def get_repos_of_project(self, project): """Get dictionary name: list of archs for project repos""" @@ -161,7 +162,7 @@ class OSC(object): try: # Create project and set its meta core.edit_meta('prj', path_args=quote_plus(target), data=meta) - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError) as err: raise ObsError("Can't set meta for %s: %s" % (target, str(err))) @@ -172,7 +173,7 @@ class OSC(object): # copy project config try: config = core.show_project_conf(self.apiurl, src) - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError) as err: raise ObsError("Can't get config from project %s: %s" \ % (src, str(err))) @@ -205,10 +206,10 @@ class OSC(object): try: core.meta_exists(metatype=metatype, path_args=path_args, create_new=False, apiurl=self.apiurl) - except urllib2.HTTPError as err: + except urllib.error.HTTPError as err: if err.code == 404: return False - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \ + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, \ M2Crypto.SSL.SSLError) as err: pass except SSLVerificationError: @@ -222,7 +223,7 @@ class OSC(object): """Rebuild package.""" try: return core.rebuild(self.apiurl, prj, pkg, repo=None, arch=arch) - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \ + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, \ M2Crypto.SSL.SSLError) as err: raise ObsError("Can't trigger rebuild for %s/%s: %s" % \ (prj, pkg, str(err))) @@ -269,7 +270,7 @@ class OSC(object): else: new.append(lpath) - return rdict.keys(), not_changed, changed, new + return list(rdict.keys()), not_changed, changed, new @waiting def commit_files(self, prj, pkg, files, message): @@ -318,7 +319,7 @@ class OSC(object): results = defaultdict(dict) try: build_status = core.get_results(self.apiurl, prj, pkg) - except (urllib2.URLError, M2Crypto.m2urllib2.URLError, + except (urllib.error.URLError, M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError) as err: raise ObsError("can't get %s/%s build results: %s" \ % (prj, pkg, str(err))) @@ -348,7 +349,7 @@ class OSC(object): raise ObsError("can't get %s/%s build log: %s" % (prj, pkg, err)) return log.translate(None, "".join([chr(i) for i in \ - range(10) + range(11, 32)])) + list(range(10)) + list(range(11, 32))])) @staticmethod def get_path(prj, pkg=None): diff --git a/gitbuildsys/parsing.py b/gitbuildsys/parsing.py index e62829e..0b4981b 100644 --- a/gitbuildsys/parsing.py +++ b/gitbuildsys/parsing.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # vim: ai ts=4 sts=4 et sw=4 # # Copyright (c) 2011 Intel, Inc. @@ -35,7 +35,7 @@ class GbsHelpFormatter(RawDescriptionHelpFormatter): """Collect aliases.""" if action.choices: - for item, parser in action.choices.iteritems(): + for item, parser in action.choices.items(): self._aliases[str(item)] = parser.get_default('alias') return super(GbsHelpFormatter, self).add_argument(action) diff --git a/gitbuildsys/safe_url.py b/gitbuildsys/safe_url.py index 1293e63..4671518 100644 --- a/gitbuildsys/safe_url.py +++ b/gitbuildsys/safe_url.py @@ -20,8 +20,8 @@ This module provides a class SafeURL which can contain url/user/password read from config file, and hide plain user and password when it print to screen """ -import urllib -import urlparse +import urllib.request, urllib.parse, urllib.error +import urllib.parse class SafeURL(str): @@ -38,7 +38,7 @@ class SafeURL(str): inst.user, inst.passwd = SafeURL._check_userinfo(inline_user, inline_passwd, user, passwd) - inst.components = urlparse.urlsplit(safe_url) + inst.components = urllib.parse.urlsplit(safe_url) return inst @property @@ -57,7 +57,7 @@ class SafeURL(str): new_components = list(self.components) new_components[1] = login - return urlparse.urlunsplit(new_components) + return urllib.parse.urlunsplit(new_components) def is_local(self): 'return True is it is local path' @@ -65,7 +65,7 @@ class SafeURL(str): def pathjoin(self, args): '''treat self as path and urljoin''' - new = urlparse.urljoin(self.rstrip('/') + '/', args) + new = urllib.parse.urljoin(self.rstrip('/') + '/', args) return SafeURL(new, self.user, self.passwd) def _get_userinfo(self): @@ -73,19 +73,19 @@ class SafeURL(str): if not self.user: return '' - escape = lambda raw: urllib.quote(raw, safe='') + escape = lambda raw: urllib.parse.quote(raw, safe='') return '%s:%s' % (escape(self.user), escape(self.passwd)) \ if self.passwd else escape(self.user) @staticmethod def _extract_userinfo(url): '''strip inline user/password from url''' - results = urlparse.urlsplit(url) + results = urllib.parse.urlsplit(url) hostport = SafeURL._get_hostport(results) components = list(results) components[1] = hostport - safe_url = urlparse.urlunsplit(components) + safe_url = urllib.parse.urlunsplit(components) return safe_url, results.username, results.password diff --git a/gitbuildsys/utils.py b/gitbuildsys/utils.py index 8224290..becd0fd 100644 --- a/gitbuildsys/utils.py +++ b/gitbuildsys/utils.py @@ -623,7 +623,7 @@ class GerritNameMapper(object): lst_node = root.getiterator("package") for node in lst_node: - if node.attrib.has_key("name"): + if "name" in node.attrib: for child in node.getchildren(): if child.tag == 'source': self._pkg2src[node.attrib['name']] = child.text diff --git a/packaging/gbs.spec b/packaging/gbs.spec index b31a717..6a6414d 100755 --- a/packaging/gbs.spec +++ b/packaging/gbs.spec @@ -1,5 +1,4 @@ -%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} -%{!?python_version: %define python_version %(%{__python} -c "import sys; sys.stdout.write(sys.version[:3])")} +%{!?python3_sitelib: %define python3_sitelib %(python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])')} %define jobs_dir /var/lib/jenkins/jobs %define scripts_dir /var/lib/jenkins/jenkins-scripts @@ -17,18 +16,15 @@ License: GPLv2 BuildArch: noarch URL: http://www.tizen.org Source0: %{name}_%{version}.tar.gz -Requires: python >= 2.6 -Requires: python-pycurl -Requires: python-requests -Requires: python-lxml +Requires: python3 +Requires: python3-pycurl +Requires: python3-requests +Requires: python3-lxml Requires: sudo Requires: osc >= 0.132.6 Requires: tizen-gbp-rpm >= 20210514 Requires: depanneur >= 0.16.18 -%if "%{?python_version}" < "2.7" -Requires: python-argparse -%endif %if ! 0%{?tizen_version:1} Requires: rpm-tizen >= 4.11.0.1.tizen20130618-tizen20131001 %endif @@ -36,8 +32,8 @@ Requires: %{name}-api = %{version}-%{release} Requires: %{name}-export = %{version}-%{release} Requires: %{name}-remotebuild = %{version}-%{release} -BuildRequires: python-docutils -BuildRequires: python-setuptools +BuildRequires: python3-docutils +BuildRequires: python3-setuptools BuildRoot: %{_tmppath}/%{name}-%{version}-build %description @@ -47,8 +43,8 @@ be used to do packaging related tasks. %package api Summary: GBS APIs Conflicts: gbs < 0.15 -Requires: python -Requires: python-pycurl +Requires: python3 +Requires: python3-pycurl Requires: osc >= 0.132.6 Requires: git-buildpackage-rpm @@ -59,7 +55,7 @@ external software. %package export Summary: GBS export module Conflicts: gbs < 0.15 -Requires: python +Requires: python3 Requires: tizen-pristine-tar >= 20161231 Requires: gbs-api = %{version}-%{release} Requires: git-buildpackage-rpm @@ -71,7 +67,7 @@ external software. %package remotebuild Summary: GBS remotebuild module Conflicts: gbs < 0.18.1 -Requires: python +Requires: python3 Requires: gbs-api = %{version}-%{release} Requires: gbs-export = %{version}-%{release} Requires: git-buildpackage-rpm @@ -110,9 +106,9 @@ and generates a report using the relevant data. %build -%{__python} setup.py build +python3 setup.py build make man -pushd bsr && %{__python} setup.py build && popd +pushd bsr && python3 setup.py build && popd %pre /usr/bin/getent group jenkins >/dev/null || /usr/sbin/groupadd -r jenkins &>/dev/null || : @@ -120,8 +116,8 @@ pushd bsr && %{__python} setup.py build && popd -d "%{workdir}" jenkins &>/dev/null || : %install -%{__python} setup.py install --prefix=%{_prefix} --root=%{buildroot} -pushd bsr && %{__python} setup.py install --prefix=%{_prefix} --root=%{buildroot} && popd +python3 setup.py install --prefix=%{_prefix} --root=%{buildroot} +pushd bsr && python3 setup.py install --prefix=%{_prefix} --root=%{buildroot} && popd mkdir -p %{buildroot}/%{_prefix}/share/man/man1 @@ -142,6 +138,9 @@ done mkdir -p %{buildroot}/%{scripts_dir} install -m755 jenkins-jobs/scripts/* %{buildroot}/%{scripts_dir} +#remove /usr/lib/python3.*/site-packages/gitbuildsys/__pycache__/ directory +rm -rf %{buildroot}/%{python3_sitelib}/gitbuildsys/__pycache__ + %clean rm -rf %{buildroot} @@ -151,40 +150,40 @@ rm -rf %{buildroot} %dir %{_prefix}/share/gbs %{_mandir}/man1/* %{_prefix}/share/gbs/* -%{python_sitelib}/gitbuildsys/cmd_build.py* -%{python_sitelib}/gitbuildsys/cmd_changelog.py* -%{python_sitelib}/gitbuildsys/cmd_chroot.py* -%{python_sitelib}/gitbuildsys/cmd_clone.py* -%{python_sitelib}/gitbuildsys/cmd_createimage.py* -%{python_sitelib}/gitbuildsys/cmd_devel.py* -%{python_sitelib}/gitbuildsys/cmd_import.py* -%{python_sitelib}/gitbuildsys/cmd_pull.py* -%{python_sitelib}/gitbuildsys/cmd_submit.py* -%{python_sitelib}/gitbuildsys/cmd_depends.py* -%{python_sitelib}/gitbuildsys/parsing.py* +%{python3_sitelib}/gitbuildsys/cmd_build.py* +%{python3_sitelib}/gitbuildsys/cmd_changelog.py* +%{python3_sitelib}/gitbuildsys/cmd_chroot.py* +%{python3_sitelib}/gitbuildsys/cmd_clone.py* +%{python3_sitelib}/gitbuildsys/cmd_createimage.py* +%{python3_sitelib}/gitbuildsys/cmd_devel.py* +%{python3_sitelib}/gitbuildsys/cmd_import.py* +%{python3_sitelib}/gitbuildsys/cmd_pull.py* +%{python3_sitelib}/gitbuildsys/cmd_submit.py* +%{python3_sitelib}/gitbuildsys/cmd_depends.py* +%{python3_sitelib}/gitbuildsys/parsing.py* %{_bindir}/gbs %{_sysconfdir}/bash_completion.d %{_sysconfdir}/zsh_completion.d %files api %defattr(-,root,root,-) -%dir %{python_sitelib}/gitbuildsys -%{python_sitelib}/gitbuildsys/__init__.py* -%{python_sitelib}/gitbuildsys/oscapi.py* -%{python_sitelib}/gitbuildsys/errors.py* -%{python_sitelib}/gitbuildsys/log.py* -%{python_sitelib}/gitbuildsys/safe_url.py* -%{python_sitelib}/gitbuildsys/conf.py* -%{python_sitelib}/gitbuildsys/utils.py* -%{python_sitelib}/gbs-*-py*.egg-info +%dir %{python3_sitelib}/gitbuildsys +%{python3_sitelib}/gitbuildsys/__init__.py* +%{python3_sitelib}/gitbuildsys/oscapi.py* +%{python3_sitelib}/gitbuildsys/errors.py* +%{python3_sitelib}/gitbuildsys/log.py* +%{python3_sitelib}/gitbuildsys/safe_url.py* +%{python3_sitelib}/gitbuildsys/conf.py* +%{python3_sitelib}/gitbuildsys/utils.py* +%{python3_sitelib}/gbs-*-py*.egg-info %files export %defattr(-,root,root,-) -%{python_sitelib}/gitbuildsys/cmd_export.py* +%{python3_sitelib}/gitbuildsys/cmd_export.py* %files remotebuild %defattr(-,root,root,-) -%{python_sitelib}/gitbuildsys/cmd_remotebuild.py* +%{python3_sitelib}/gitbuildsys/cmd_remotebuild.py* %files jenkins-jobs %defattr(-,root,root,-) @@ -205,5 +204,5 @@ rm -rf %{buildroot} %files bsr %defattr(-,root,root,-) -%{python_sitelib}/bsr* +%{python3_sitelib}/bsr* %{_bindir}/bsr diff --git a/setup.py b/setup.py index 42519df..d101c7a 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """GBS setup.""" @@ -27,7 +27,7 @@ def get_version(mod_name): """Get version from module __init__.py""" path = os.path.join(mod_name, "__init__.py") if not os.path.isfile(path): - print('No %s version file found' % path) + print(('No %s version file found' % path)) sys.exit(1) content = open(path).read() @@ -36,7 +36,7 @@ def get_version(mod_name): if match: return match.group(1) - print('Unable to find version in %s' % path) + print(('Unable to find version in %s' % path)) sys.exit(1) check_debian() diff --git a/tests/test_config.py b/tests/test_config.py index fbae7db..feda74f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -75,7 +75,7 @@ class Fixture(object): patch('gitbuildsys.conf.os.path.exists', self.fake_exists), patch('gitbuildsys.conf.os.path.expanduser', self.fake_expanduser), patch('gitbuildsys.conf.os.path.abspath', self.fake_abspath), - patch('ConfigParser.open', self.fake_open, create=True), + patch('configparser.ConfigParser.open', self.fake_open, create=True), ] for patcher in patchers: func = patcher(func) @@ -132,7 +132,7 @@ class ConfigGettingTest(unittest.TestCase): @Fixture(home='home1.ini') def test_default_value(self): 'test get hardcode default value ' - self.assertEquals('/var/tmp', self.get('general', 'tmpdir')) + self.assertEqual('/var/tmp', self.get('general', 'tmpdir')) @Fixture(home='without_section_header.ini') def test_invalid_ini(self): @@ -147,7 +147,7 @@ class ConfigGettingTest(unittest.TestCase): @Fixture(home='interpolation.ini') def test_interpolation(self): 'test interpolation is supported' - self.assertEquals('abc/def', self.get('remote', 'target')) + self.assertEqual('abc/def', self.get('remote', 'target')) @Fixture(home='home1.ini') def test_addconf(self): diff --git a/tests/test_help.py b/tests/test_help.py index d7d7d48..186366a 100644 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -36,7 +36,7 @@ class TestHelp(unittest.TestCase): "chroot", "chr"]: try: - print('>>>sub', sub) + print(('>>>sub', sub)) GBS(argv=["gbs", sub, "--help"]) except SystemExit as err: eq_(err.code, 0) diff --git a/tests/test_passwdx.py b/tests/test_passwdx.py index d63e193..b7cb539 100644 --- a/tests/test_passwdx.py +++ b/tests/test_passwdx.py @@ -17,7 +17,7 @@ # Temple Place - Suite 330, Boston, MA 02111-1307, USA. """Functional tests for setting passwdx back to config""" import unittest -from StringIO import StringIO +from io import StringIO from mock import patch @@ -67,7 +67,7 @@ class PasswdxTest(unittest.TestCase): reload(gitbuildsys.conf) - self.assertEquals('''[remotebuild] + self.assertEqual('''[remotebuild] build_server = https://api passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s @@ -90,7 +90,7 @@ repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s reload(gitbuildsys.conf) - self.assertEquals('''[remotebuild] + self.assertEqual('''[remotebuild] build_server = https://api passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s @@ -99,7 +99,7 @@ repo1.url = https://repo1 repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s ''', confs[0].getvalue()) - self.assertEquals('''[remotebuild] + self.assertEqual('''[remotebuild] build_server = https://api user = test passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s @@ -117,7 +117,7 @@ repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s reload(gitbuildsys.conf) pwd = gitbuildsys.conf.configmgr.get('passwd', 'remotebuild') - self.assertEquals('secret', pwd) + self.assertEqual('secret', pwd) @Fixture(home='plain_passwd.ini') def test_get_passwd(self, fake_open): @@ -127,7 +127,7 @@ repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s reload(gitbuildsys.conf) pwd = gitbuildsys.conf.configmgr.get('passwd', 'remotebuild') - self.assertEquals('secret', pwd) + self.assertEqual('secret', pwd) @Fixture(home='bad_passwdx.ini') def test_bad_passwdx(self, _fake_open): @@ -143,7 +143,7 @@ repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s reload(gitbuildsys.conf) pwd = gitbuildsys.conf.configmgr.get('passwd', 'remotebuild') - self.assertEquals('', pwd) + self.assertEqual('', pwd) @patch('gitbuildsys.conf.os.chmod') diff --git a/tests/test_profile.py b/tests/test_profile.py index 562d9f4..93898eb 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -40,24 +40,24 @@ class ProfileStyleTest(unittest.TestCase): @Fixture(home='profile.ini') def test_profile_api(self): 'test get obs api' - self.assertEquals('https://api.tz/path', get_profile().obs.url) + self.assertEqual('https://api.tz/path', get_profile().obs.url) @Fixture(home='profile.ini') def test_api_inherit_auth(self): 'test api can inherit auto from parent profile section' - self.assertEquals('https://Alice:secret@api.tz/path', + self.assertEqual('https://Alice:secret@api.tz/path', get_profile().obs.url.full) @Fixture(home='profile_only_has_api.ini') def test_api_auth_can_be_overwrite(self): 'test api auth can be overwrite' - self.assertEquals('https://Bob:classified@api.tz/path', + self.assertEqual('https://Bob:classified@api.tz/path', get_profile().obs.url.full) @Fixture(home='profile.ini') def test_profile_repos_in_order(self): 'repos must be in same order as they are write in config' - self.assertEquals(['https://repo/ia32/main', + self.assertEqual(['https://repo/ia32/main', 'https://repo/ia32/non-oss', 'https://repo/ia32/base', '/local/path'], @@ -66,29 +66,29 @@ class ProfileStyleTest(unittest.TestCase): @Fixture(home='profile.ini') def test_repo_inherit_auth(self): 'test repo can inherit auth from parent section' - self.assertEquals('https://Alice:secret@repo/ia32/main', + self.assertEqual('https://Alice:secret@repo/ia32/main', get_profile().repos[0].url.full) @Fixture(home='profile.ini') def test_repo_overwrite_auth(self): 'test repo auth can be overwrite' - self.assertEquals('https://Bob:classified@repo/ia32/base', + self.assertEqual('https://Bob:classified@repo/ia32/base', get_profile().repos[2].url.full) @Fixture(home='bug387_inherit_only_user.ini') def test_inherit_only_user(self): 'test inherit only user from parent' - self.assertEquals('https://tester:secret@repo', + self.assertEqual('https://tester:secret@repo', get_profile().repos[0].url.full) - self.assertEquals('https://tester:secret@obs', + self.assertEqual('https://tester:secret@obs', get_profile().obs.url.full) @Fixture(home='bug387_inherit_only_passwdx.ini') def test_inherit_only_passwdx(self): 'test inherit only password from parent' - self.assertEquals('https://tester:secret@repo', + self.assertEqual('https://tester:secret@repo', get_profile().repos[0].url.full) - self.assertEquals('https://tester:secret@obs', + self.assertEqual('https://tester:secret@obs', get_profile().obs.url.full) @Fixture(home='bug387_only_password_no_user.ini') @@ -99,7 +99,7 @@ class ProfileStyleTest(unittest.TestCase): @Fixture(home='bug387_inline_auth_has_the_highest_priority.ini') def test_inline_highest_priority(self): 'test inline auth has the highest priority' - self.assertEquals('https://this:inline-pwd@obs', + self.assertEqual('https://this:inline-pwd@obs', get_profile().obs.url.full) @Fixture(home='no_such_profile_section_name.ini') @@ -112,23 +112,23 @@ class ProfileStyleTest(unittest.TestCase): 'test get a empty profile' profile = get_profile() - self.assertEquals(None, profile.obs) - self.assertEquals([], profile.repos) + self.assertEqual(None, profile.obs) + self.assertEqual([], profile.repos) @Fixture(home='profile.ini') def test_local_repo_need_not_auth(self): '''test local path needn't auth info''' - self.assertEquals('/local/path', get_profile().repos[3].url.full) + self.assertEqual('/local/path', get_profile().repos[3].url.full) @Fixture(home='profile.ini') def test_obs_base_project(self): 'test read base project from conf' - self.assertEquals('base', get_profile().obs.base) + self.assertEqual('base', get_profile().obs.base) @Fixture(home='profile.ini') def test_obs_target_project(self): 'test read target project from conf' - self.assertEquals('target', get_profile().obs.target) + self.assertEqual('target', get_profile().obs.target) @patch('gitbuildsys.conf.open', MagicMock(), create=True) @@ -139,18 +139,18 @@ class SubcommandStyleTest(unittest.TestCase): @Fixture(home='subcommand.ini') def test_api(self): 'test obs api' - self.assertEquals('https://api/build/server', get_profile().obs.url) + self.assertEqual('https://api/build/server', get_profile().obs.url) @Fixture(home='subcommand.ini') def test_api_auth(self): 'test api auth' - self.assertEquals('https://Alice:secret@api/build/server', + self.assertEqual('https://Alice:secret@api/build/server', get_profile().obs.url.full) @Fixture(home='subcommand.ini') def test_repos_in_order(self): 'repos list must be in the same order as they are write in config' - self.assertEquals(['https://repo1/path', + self.assertEqual(['https://repo1/path', 'https://repo2/path', '/local/path/repo'], [i.url for i in get_profile().repos]) @@ -158,7 +158,7 @@ class SubcommandStyleTest(unittest.TestCase): @Fixture(home='subcommand.ini') def test_repo_auth(self): 'test repo auth' - self.assertEquals('https://Alice:secret@repo1/path', + self.assertEqual('https://Alice:secret@repo1/path', get_profile().repos[0].url.full) @@ -175,7 +175,7 @@ class ConvertTest(unittest.TestCase): get_profile() - self.assertEquals(conf.getvalue(), '''[general] + self.assertEqual(conf.getvalue(), '''[general] profile = profile.current [obs.remotebuild] diff --git a/tools/gbs b/tools/gbs index 73233fa..7d920f0 100755 --- a/tools/gbs +++ b/tools/gbs @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # vim: ai ts=4 sts=4 et sw=4 # # Copyright (c) 2011 Intel, Inc. -- 2.34.1