Pylint for common/obspkg.py
authorLingchaox Xin <lingchaox.xin@intel.com>
Tue, 18 Jun 2013 06:22:44 +0000 (14:22 +0800)
committerGerrit Code Review <gerrit2@otctools.jf.intel.com>
Tue, 18 Jun 2013 07:23:47 +0000 (00:23 -0700)
Use absolute import instead of relative import, replace `cmp` parameter
with `key` since the latter is faster.

Change-Id: I004dff6de87c17935e8bb6ec36a3426b94bdd4d6

common/obspkg.py

index 324ab1b..4fef3ea 100644 (file)
 # 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 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