From: Lingchaox Xin Date: Tue, 18 Jun 2013 06:22:44 +0000 (+0800) Subject: Pylint for common/obspkg.py X-Git-Tag: 0.14~132 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8aa543f236dea6085ba0ba859fd7753691235a53;p=services%2Fjenkins-scripts.git Pylint for common/obspkg.py Use absolute import instead of relative import, replace `cmp` parameter with `key` since the latter is faster. Change-Id: I004dff6de87c17935e8bb6ec36a3426b94bdd4d6 --- diff --git a/common/obspkg.py b/common/obspkg.py index 324ab1b..4fef3ea 100644 --- a/common/obspkg.py +++ b/common/obspkg.py @@ -16,13 +16,15 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +"""A wrapper to handle with OBS operations""" + from __future__ import with_statement import os import shutil -import buildservice -import runner -import errors -from utils import Workdir +from common import buildservice +from common import runner +from common import errors +from common.utils import Workdir from osc import core, oscerr @@ -64,13 +66,15 @@ class ObsPackage(object): else: # branch from target project print "branch package %s from %s" % (self._pkg, realprj) - self._bs.branch_pkg(realprj, self._pkg, target_project=self._prj) + self._bs.branch_pkg(realprj, self._pkg, \ + target_project=self._prj) self._checkout_latest() else: # to init new package in local dir self._mkpac() def _mkpac(self): + """Make a package in OBS""" print "mkpac %s %s" % (self._prj, self._pkg) with Workdir(self._bdir): self._bs.mk_pac(self._prj, self._pkg) @@ -92,16 +96,17 @@ class ObsPackage(object): with Workdir(self._pkgpath): try: pac = core.findpacs([filename])[0] - st, fn = sorted(pac.get_status(), lambda x, y: cmp(x[1], y[1]))[0] - except oscerr.OscIOError, err: + status = sorted(pac.get_status(), key=lambda x: x[1])[0][0] + except oscerr.OscIOError: return '?' - return st + return status def is_new_pkg(self): - """Check whether this is new package in obs + """Check whether this is a new package in obs """ - print "%s package list:" % self._prj, self._bs.get_package_list(self._prj) - if self._pkg in self._bs.get_package_list(self._prj): + packages = self._bs.get_package_list(self._prj) + print "%s package list:" % self._prj, packages + if self._pkg in packages: print "%s is NOT new package in %s" % (self._pkg, self._prj) return False else: @@ -109,9 +114,11 @@ class ObsPackage(object): return True def get_workdir(self): + """Get package path""" return self._pkgpath def get_pkgname(self): + """Get package name""" return self._pkg def remove_all(self): @@ -143,6 +150,7 @@ class ObsPackage(object): pac.delete_file(filename) def add_file(self, fpath): + """Add a file with its' fpath to local package""" # copy the file in runner.quiet('/bin/cp -f %s %s' % (fpath, self._pkgpath)) @@ -155,6 +163,7 @@ class ObsPackage(object): print 'Invalid pac working dir, skip' def commit(self, msg): + """Submit a package change to OBS with msg""" with Workdir(self._pkgpath): self._bs.submit(msg) @@ -173,9 +182,11 @@ class ObsPackage(object): dst_pkg = self._pkg with Workdir(self._pkgpath): reqs = self._bs.get_request_list(dst_prj, dst_pkg) - newreq = self._bs.submit_req(self._prj, self._pkg, dst_prj, dst_pkg, msg, src_update='cleanup') + newreq = self._bs.submit_req(self._prj, self._pkg, dst_prj, \ + dst_pkg, msg, src_update='cleanup') if supersede: for req in reqs: - self._bs.req_supersede(req.reqid, 'superseded by %s' % newreq, newreq) + self._bs.req_supersede(req.reqid, 'superseded by %s' % \ + newreq, newreq) return newreq