From: yan11.meng Date: Fri, 13 Dec 2019 03:20:45 +0000 (+0800) Subject: fix pylint error for osc X-Git-Tag: submit/trunk/20191221.141128^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c5b4b826a95f6ac240e1508200ab284a37ab4329;p=tools%2Fosc.git fix pylint error for osc Change-Id: I72b6ecf579e9ab7362269d47e11d0ab6b1176b3d Signed-off-by: yan11.meng --- diff --git a/debian/control b/debian/control index 27868b9..9749a24 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Homepage: http://en.opensuse.org/Build_Service/CLI Package: osc Section: devel Architecture: all -Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python (>= 2.5), python-urlgrabber, python-rpm, python-m2crypto (>= 0.20) +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, python (>= 2.5), python-urlgrabber, python-rpm, python-keyring, python-gobject, python-m2crypto (>= 0.20) Suggests: python-gnomekeyring, gnome-keyring, build (> 2010.04.24) Description: openSUSE (buildsystem) commander Commandline client for the openSUSE Build Service, which allows to access diff --git a/osc/__init__.py b/osc/__init__.py index 7872a4e..f5dbe69 100644 --- a/osc/__init__.py +++ b/osc/__init__.py @@ -1,3 +1,3 @@ -__all__ = ['babysitter', 'core', 'commandline', 'oscerr', 'othermethods', 'build', 'fetch', 'meter'] +__all__ = ['babysitter', 'core', 'commandline', 'oscerr', 'build', 'fetch', 'meter'] # vim: sw=4 et diff --git a/osc/babysitter.py b/osc/babysitter.py index 682de94..272aabd 100644 --- a/osc/babysitter.py +++ b/osc/babysitter.py @@ -27,7 +27,7 @@ except: try: # import as RPMError because the class "error" is too generic - from rpm import error as RPMError + from rpm import error as RPMError #pylint: disable=no-name-in-module except: # if rpm-python isn't installed (we might be on a debian system): RPMError = None diff --git a/osc/build.py b/osc/build.py index b2fe44c..218d354 100644 --- a/osc/build.py +++ b/osc/build.py @@ -319,7 +319,7 @@ def get_repo(path): return repositoryDirectory -def get_prefer_pkgs(dirs, wanted_arch, type, cpio): +def get_prefer_pkgs(dirs, wanted_arch, type, cpio=None): import glob from .util import repodata, packagequery paths = [] @@ -813,7 +813,7 @@ def main(apiurl, opts, argv): self._rmtree(self.name) def __del__(self): self.cleanup() - def __exit__(self): + def __exit__(self, type=None, value=None, trace=None): self.cleanup() def __str__(self): return self.name diff --git a/osc/cmdln.py b/osc/cmdln.py index da49ce6..c407095 100644 --- a/osc/cmdln.py +++ b/osc/cmdln.py @@ -891,7 +891,7 @@ class RawCmdln(cmd.Cmd): warnings.warn("argument '**%s' on '%s.%s' command " "handler will never get values" % (name, self.__class__.__name__, - getattr(func, "__name__", getattr(func, "func_name")))) + getattr(func_defaults, "__name__", getattr(func_defaults, "func_name")))) if co_flags & CO_FLAGS_ARGS: name = argnames.pop(-1) tail = "[%s...]" % name.upper() diff --git a/osc/commandline.py b/osc/commandline.py index 8aba26b..d7710b2 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -1152,7 +1152,7 @@ class Osc(cmdln.Cmdln): raise oscerr.UserAbort() elif len(args) >= 3: # get the arguments from the commandline - src_project, src_package, dst_project = args[0:3] + src_project, src_package, dst_project = args[0:3] #pylint: disable=unbalanced-tuple-unpacking if len(args) == 4: dst_package = args[3] else: @@ -2779,6 +2779,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. raise oscerr.WrongArgs('Too many arguments.') if len(args) == 0: + wd = os.curdir if is_project_dir(os.curdir): source_project = store_read_project(os.curdir) elif is_package_dir(os.curdir): @@ -7538,7 +7539,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. opts.headers = None opts.data = None opts.file = None - return self.do_api('list', opts, *args) + return self.do_api('list', opts, *args) #pylint: disable=no-value-for-parameter diff --git a/osc/conf.py b/osc/conf.py index 3239cd8..3ca6afb 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -73,7 +73,7 @@ except: try: import gobject gobject.set_application_name('osc') - import gnomekeyring + import gnomekeyring #pylint: disable=import-error if os.environ['GNOME_DESKTOP_SESSION_ID']: # otherwise gnome keyring bindings spit out errors, when you have # it installed, but you are not under gnome @@ -443,7 +443,7 @@ def get_apiurl_usr(apiurl): # cafile/capath locations) def _build_opener(url): from osc.core import __version__ - global config + apiurl = urljoin(*parse_apisrv_url(None, url)) if 'last_opener' not in _build_opener.__dict__: _build_opener.last_opener = (None, None) @@ -733,7 +733,7 @@ def add_section(filename, url, user, passwd): """ Add a section to config file for new api url. """ - global config + cp = get_configParser(filename) try: cp.add_section(url) diff --git a/osc/core.py b/osc/core.py index 052d8ea..ed32497 100644 --- a/osc/core.py +++ b/osc/core.py @@ -644,7 +644,6 @@ class Project: self.pacs_missing = [ i for i in self.pacs_available if i not in self.pacs_have ] def wc_check(self): - global store dirty_files = [] req_storefiles = Project.REQ_STOREFILES if conf.config['do_package_tracking']: @@ -655,7 +654,6 @@ class Project: return dirty_files def wc_repair(self, apiurl=None): - global store if not os.path.exists(os.path.join(self.dir, store, '_apiurl')) or apiurl: if apiurl is None: msg = 'cannot repair wc: the \'_apiurl\' file is missing but ' \ @@ -746,7 +744,7 @@ class Project: Returns an ``xml.etree.cElementTree`` object representing the parsed contents of the project's ``.osc/_packages`` XML file. """ - global store + packages_file = os.path.join(self.absdir, store, '_packages') if os.path.isfile(packages_file) and os.path.getsize(packages_file): @@ -1038,7 +1036,6 @@ class Project: @staticmethod def init_project(apiurl, dir, project, package_tracking=True, getPackageList=True, progress_obj=None, wc_check=True): - global store if not os.path.exists(dir): # use makedirs (checkout_no_colon config option might be enabled) @@ -1067,7 +1064,6 @@ class Package: '_size_limit', '_commit_msg') def __init__(self, workingdir, progress_obj=None, size_limit=None, wc_check=True): - global store self.dir = workingdir self.absdir = os.path.abspath(self.dir) @@ -1754,7 +1750,6 @@ class Package: return i def get_status(self, excluded=False, *exclude_states): - global store todo = self.todo if not todo: todo = self.filenamelist + self.to_be_added + \ @@ -2324,7 +2319,6 @@ rev: %s @staticmethod def init_package(apiurl, project, package, dir, size_limit=None, meta=False, progress_obj=None): - global store if not os.path.exists(dir): os.mkdir(dir) @@ -2917,15 +2911,11 @@ def shorttime(t): def is_project_dir(d): - global store - return os.path.exists(os.path.join(d, store, '_project')) and not \ os.path.exists(os.path.join(d, store, '_package')) def is_package_dir(d): - global store - return os.path.exists(os.path.join(d, store, '_project')) and \ os.path.exists(os.path.join(d, store, '_package')) @@ -2933,9 +2923,6 @@ def parse_disturl(disturl): """Parse a disturl, returns tuple (apiurl, project, source, repository, revision), else raises an oscerr.WrongArgs exception """ - - global DISTURL_RE - m = DISTURL_RE.match(disturl) if not m: raise oscerr.WrongArgs("`%s' does not look like disturl" % disturl) @@ -2949,8 +2936,6 @@ def parse_buildlogurl(buildlogurl): """Parse a build log url, returns a tuple (apiurl, project, package, repository, arch), else raises oscerr.WrongArgs exception""" - global BUILDLOGURL_RE - m = BUILDLOGURL_RE.match(buildlogurl) if not m: raise oscerr.WrongArgs('\'%s\' does not look like url with a build log' % buildlogurl) @@ -3052,7 +3037,6 @@ def filedir_to_pac(f, progress_obj=None): def read_filemeta(dir): - global store msg = '\'%s\' is not a valid working copy.' % dir filesmeta = os.path.join(dir, store, '_files') @@ -3068,7 +3052,6 @@ def read_filemeta(dir): return r def store_readlist(dir, name): - global store r = [] if os.path.exists(os.path.join(dir, store, name)): @@ -3082,7 +3065,6 @@ def read_tobedeleted(dir): return store_readlist(dir, '_to_be_deleted') def read_sizelimit(dir): - global store r = None fname = os.path.join(dir, store, '_size_limit') @@ -3228,7 +3210,6 @@ def http_DELETE(*args, **kwargs): return http_request('DELETE', *args, **kwargs) def check_store_version(dir): - global store versionfile = os.path.join(dir, store, '_osclib_version') try: @@ -3541,8 +3522,6 @@ def meta_exists(metatype, create_new=True, apiurl=None): - global metatypes - if not apiurl: apiurl = conf.config['apiurl'] url = make_meta_url(metatype, path_args, apiurl) @@ -3559,8 +3538,6 @@ def meta_exists(metatype, return data def make_meta_url(metatype, path_args=None, apiurl=None, force=False, remove_linking_repositories=False): - global metatypes - if not apiurl: apiurl = conf.config['apiurl'] if metatype not in metatypes.keys(): @@ -3589,8 +3566,6 @@ def edit_meta(metatype, change_is_required=False, apiurl=None): - global metatypes - if not apiurl: apiurl = conf.config['apiurl'] if not data: @@ -4320,7 +4295,6 @@ def get_group_data(apiurl, group, *tags): def download(url, filename, progress_obj = None, mtime = None): import tempfile, shutil - global BUFSIZE o = None try: @@ -4388,8 +4362,6 @@ def dgst(file): #if not os.path.exists(file): #return None - global BUFSIZE - try: import hashlib md5 = hashlib @@ -4403,7 +4375,7 @@ def dgst(file): if not buf: break s.update(buf) return s.hexdigest() - f.close() + # f.close() def binary(s): @@ -4428,8 +4400,6 @@ def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None, import difflib - global store - if not oldfilename: oldfilename = filename @@ -5272,7 +5242,7 @@ def get_binarylist_published(apiurl, prj, repo, arch): return r -def show_results_meta(apiurl, prj, package=None, lastbuild=None, repository=[], arch=[], oldstate=None): +def show_results_meta(apiurl=None, prj=None, package=None, lastbuild=None, repository=[], arch=[], oldstate=None): query = {} if package: query['package'] = package @@ -5295,7 +5265,7 @@ def show_prj_results_meta(apiurl, prj): return f.readlines() -def get_package_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], oldstate=None): +def get_package_results(apiurl=None, prj=None, package=None, lastbuild=None, repository=[], arch=[], oldstate=None): """ return a package results as a list of dicts """ r = [] @@ -5335,7 +5305,7 @@ def format_results(results, format): """apply selected format on each dict in results and return it as a list of strings""" return [format % r for r in results] -def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], verbose=False, wait=False, printJoin=None): +def get_results(apiurl=None, prj=None, package=None, lastbuild=None, repository=[], arch=[], verbose=False, wait=False, printJoin=None): r = [] result_line_templ = '%(rep)-20s %(arch)-10s %(status)s' oldstate = None @@ -5390,7 +5360,6 @@ def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[], ve def get_prj_results(apiurl, prj, hide_legend=False, csv=False, status_filter=None, name_filter=None, arch=None, repo=None, vertical=None, show_excluded=None): #print '----------------------------------------' - global buildstatus_symbols r = [] @@ -5917,8 +5886,6 @@ def rebuild(apiurl, prj, package, repo, arch, code=None): def store_read_project(dir): - global store - try: p = open(os.path.join(dir, store, '_project')).readlines()[0].strip() except IOError: @@ -5930,8 +5897,6 @@ def store_read_project(dir): def store_read_package(dir): - global store - try: p = open(os.path.join(dir, store, '_package')).readlines()[0].strip() except IOError: @@ -5942,8 +5907,6 @@ def store_read_package(dir): return p def store_read_apiurl(dir, defaulturl=True): - global store - fname = os.path.join(dir, store, '_apiurl') try: url = open(fname).readlines()[0].strip() @@ -5970,8 +5933,6 @@ def store_read_apiurl(dir, defaulturl=True): return apiurl def store_write_string(dir, file, string, subdir=''): - global store - if subdir and not os.path.isdir(os.path.join(dir, store, subdir)): os.mkdir(os.path.join(dir, store, subdir)) fname = os.path.join(dir, store, subdir, file) @@ -5992,14 +5953,10 @@ def store_write_apiurl(dir, apiurl): store_write_string(dir, '_apiurl', apiurl + '\n') def store_unlink_file(dir, file): - global store - try: os.unlink(os.path.join(dir, store, file)) except: pass def store_read_file(dir, file): - global store - try: content = open(os.path.join(dir, store, file)).read() return content @@ -6007,8 +5964,6 @@ def store_read_file(dir, file): return None def store_write_initial_packages(dir, project, subelements): - global store - fname = os.path.join(dir, store, '_packages') root = ET.Element('project', name=project) for elem in subelements: @@ -6480,7 +6435,7 @@ def createPackageDir(pathname, prj_obj=None): """ prj_dir, pac_dir = getPrjPacPaths(pathname) if is_project_dir(prj_dir): - global store + if not os.path.exists(pac_dir+store): prj = prj_obj or Project(prj_dir, False) Package.init_package(prj.apiurl, prj.name, pac_dir, pac_dir) diff --git a/osc/oscerr.py b/osc/oscerr.py index 372d646..7d3f21c 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -147,7 +147,7 @@ class PackageFileConflict(PackageError): self.msg = msg class PackageInternalError(PackageError): - def __init__(self, prj, pac, msg): + def __init__(self, prj, pac=None, msg=None): PackageError.__init__(self, prj, pac) self.msg = msg # vim: sw=4 et diff --git a/osc/util/ar.py b/osc/util/ar.py index 34337a1..6eeb05f 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -101,7 +101,7 @@ class Ar: def __init__(self, fn = None, fh = None): if fn == None and fh == None: - raise ArError('either \'fn\' or \'fh\' must be != None') + raise ArError(fn,'either \'fn\' or \'fh\' must be != None') if fh != None: self.__file = fh self.__closefile = False diff --git a/packaging/osc.spec b/packaging/osc.spec index a4225f3..9f902ff 100644 --- a/packaging/osc.spec +++ b/packaging/osc.spec @@ -13,6 +13,9 @@ BuildArch: noarch BuildRequires: python-devel BuildRequires: python-urlgrabber Requires: python-urlgrabber +Requires: python-keyring +Requires: python-gobject +Requires: python-rpm %if 0%{?suse_version} || "0%{?tizen_version}" != "0" BuildRequires: python-m2crypto diff --git a/setup.py b/setup.py index f608e63..220b03c 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ from osc import commandline from osc import babysitter # optional support for py2exe try: - import py2exe + import py2exe #pylint: disable=import-error HAVE_PY2EXE = True except: HAVE_PY2EXE = False diff --git a/tests/common.py b/tests/common.py index f0fee8b..7ed9bc8 100644 --- a/tests/common.py +++ b/tests/common.py @@ -17,8 +17,8 @@ try: from urlparse import urlparse, parse_qs except ImportError: from io import StringIO - from urllib.request import HTTPHandler, addinfourl, build_opener - from urllib.parse import urlparse, parse_qs + from urllib.request import HTTPHandler, addinfourl, build_opener #pylint: disable=no-name-in-module,import-error + from urllib.parse import urlparse, parse_qs #pylint: disable=no-name-in-module,import-error def urlcompare(url, *args): """compare all components of url except query string - it is converted to @@ -135,7 +135,7 @@ def DELETE(fullurl, **kwargs): return urldecorator('DELETE', fullurl, **kwargs) def addExpectedRequest(method, url, **kwargs): - global EXPECTED_REQUESTS + EXPECTED_REQUESTS.append((method, url, kwargs)) class OscTestCase(unittest.TestCase): diff --git a/tests/test_setlinkrev.py b/tests/test_setlinkrev.py index 6d09712..da699e0 100644 --- a/tests/test_setlinkrev.py +++ b/tests/test_setlinkrev.py @@ -78,7 +78,7 @@ class TestSetLinkRev(OscTestCase): @GET('http://localhost/source/osctest/simple/_link', file='md5_rev_link') @PUT('http://localhost/source/osctest/simple/_link', exp='', text='dummytext') - def test_deleterev(self): + def test_deleterev1(self): """delete rev and vrev attribute from link xml""" osc.core.set_link_rev('http://localhost', 'osctest', 'simple', revision=None)