Code cleanup.
authorEd Bartosh <eduard.bartosh@intel.com>
Thu, 30 Aug 2012 11:33:18 +0000 (14:33 +0300)
committerZhang Qiang <qiang.z.zhang@intel.com>
Wed, 5 Sep 2012 07:36:07 +0000 (15:36 +0800)
A bit of pylinting. Also runner/embed function has been removed as
it's not used in gbs.

Change-Id: I25f19ccc17811759db2ebeaa29f16e0f52ffba19

gitbuildsys/cmd_export.py
gitbuildsys/conf.py
gitbuildsys/runner.py
gitbuildsys/utils.py

index 8e6fe37..961f9b8 100644 (file)
@@ -114,7 +114,8 @@ def do(opts, args):
     if not spec.name or not spec.version:
         msger.error('can\'t get correct name or version from spec file.')
     else:
-        outdir = "%s/%s-%s-%s" % (outdir, spec.name, spec.upstreamversion, spec.release)
+        outdir = "%s/%s-%s-%s" % (outdir, spec.name, spec.upstreamversion,
+                                  spec.release)
         shutil.rmtree(outdir, ignore_errors=True)
         shutil.move(export_dir, outdir)
 
index 3534399..ef77447 100644 (file)
@@ -87,19 +87,20 @@ class BrainConfigParser(SafeConfigParser):
                 self._flines[lineno] = None
             else:
                 # is it a section header?
-                mo = self.SECTCRE.match(line)
-                if mo:
-                    cursect = mo.group('header')
+                match = self.SECTCRE.match(line)
+                if match:
+                    cursect = match.group('header')
                     # So sections can't start with a continuation line
                     optname = None
                 # no section header in the file?
                 elif cursect is None:
-                    raise MissingSectionHeaderError(self._fpname, lineno + 1, line)
+                    raise MissingSectionHeaderError(self._fpname,
+                                                    lineno + 1, line)
                 # an option line?
                 else:
-                    mo = self.OPTCRE.match(line)
-                    if mo:
-                        optname = mo.group('option')
+                    match = self.OPTCRE.match(line)
+                    if match:
+                        optname = match.group('option')
                         optname = self.optionxform(optname.rstrip())
                         # Replace / remove options
                         if cursect == section and \
index 7783fdd..6e667c5 100644 (file)
@@ -49,18 +49,8 @@ def runtool(cmdln_or_args, catch=1):
     if catch != 3:
         dev_null = os.open("/dev/null", os.O_WRONLY)
 
-    if catch == 0:
-        sout = dev_null
-        serr = dev_null
-    elif catch == 1:
-        sout = subprocess.PIPE
-        serr = dev_null
-    elif catch == 2:
-        sout = dev_null
-        serr = subprocess.PIPE
-    elif catch == 3:
-        sout = subprocess.PIPE
-        serr = subprocess.STDOUT
+    sout = [dev_null, subprocess.PIPE, dev_null, subprocess.PIPE][catch]
+    serr = [dev_null, dev_null, subprocess.PIPE, subprocess.STDOUT][catch]
 
     try:
         process = subprocess.Popen(cmdln_or_args, stdout=sout,
@@ -110,22 +100,3 @@ def outs(cmdln_or_args, catch=1):
 def quiet(cmdln_or_args):
     return runtool(cmdln_or_args, catch=0)[0]
 
-def embed(cmdln_or_args):
-    # embed shell script into python frame code
-
-    if isinstance(cmdln_or_args, list):
-        args = cmdln_or_args
-    else:
-        import shlex
-        args = shlex.split(cmdln_or_args)
-
-    try:
-        sts = subprocess.call(args)
-    except OSError, exc:
-        if exc.errno == 2:
-            # [Errno 2] No such file or directory
-            msger.error('Cannot run command: %s, lost dependency?' % args[0])
-        else:
-            raise # relay
-
-    return sts
index 9d0af2d..9ac6bc4 100644 (file)
@@ -23,14 +23,9 @@ import shutil
 import pycurl
 import hashlib
 import signal
+import xml.etree.ElementTree as ET
 from collections import defaultdict
 
-# cElementTree can be standard or 3rd-party depending on python version
-try:
-    from xml.etree import cElementTree as ET
-except ImportError:
-    import cElementTree as ET
-
 from gitbuildsys import errors, msger
 
 from gbp.rpm.git import GitRepositoryError
@@ -104,9 +99,9 @@ class Temp(object):
                 if content:
                     with file(path, 'w+') as fobj:
                         fobj.write(content)
-        except OSError, (e, msg):
+        except OSError, err:
             raise errors.GbsError("Failed to create dir or file on %s: %s" % \
-                            (target_dir, msg))
+                            (target_dir, str(err)))
         self.path = path
 
     def __del__(self):