Pylining
authorEd Bartosh <eduard.bartosh@intel.com>
Tue, 14 Aug 2012 10:09:40 +0000 (13:09 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Fri, 17 Aug 2012 15:08:42 +0000 (18:08 +0300)
Change-Id: Ia3d0b4f28f6863207d4de398131bde712093f8fa

gitbuildsys/cmd_build.py
gitbuildsys/cmd_changelog.py
gitbuildsys/cmd_chroot.py
gitbuildsys/cmd_export.py
gitbuildsys/cmd_remotebuild.py
gitbuildsys/conf.py
gitbuildsys/runner.py
gitbuildsys/utils.py
setup.py

index ab55382..1225491 100644 (file)
@@ -37,7 +37,7 @@ from gbp.rpm.git import GitRepositoryError, RpmGitRepository
 import gbp.rpm as rpm
 from gbp.errors import GbpError
 
-change_personality = {
+CHANGE_PERSONALITY = {
             'i686':  'linux32',
             'i586':  'linux32',
             'i386':  'linux32',
@@ -47,19 +47,14 @@ change_personality = {
             'sparcv8': 'linux32',
           }
 
-obsarchmap = {
-            'i686':     'i586',
-            'i586':     'i586',
-          }
-
-buildarchmap = {
+BUILDARCHMAP = {
             'ia32':     'i686',
             'i686':     'i686',
             'i586':     'i686',
             'i386':     'i686',
           }
 
-supportedarchs = [
+SUPPORTEDARCHS = [
             'ia32',
             'i686',
             'i586',
@@ -144,7 +139,11 @@ def setup_qemu_emulator():
 
     # register qemu emulator for interpreting other arch executable file
     if not os.path.exists(node):
-        qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:" % qemu_emulator
+        qemu_arm_string = ":arm:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00"\
+                          "\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff"\
+                          "\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff"\
+                          "\\xff\\xff\\xff\\xff\\xff\\xfa\\xff\\xff\\xff:%s:" \
+                          % qemu_emulator
         try:
             (tmpfd, tmppth) = tempfile.mkstemp()
             os.write(tmpfd, "echo '%s' > /proc/sys/fs/binfmt_misc/register" \
@@ -265,7 +264,7 @@ def do(opts, args):
         msger.error(str(err))
 
     if not opts.incremental:
-        utils.gitStatusChecker(repo, opts)
+        utils.git_status_checker(repo, opts)
     workdir = repo.path
 
     hostarch = get_hostarch()
@@ -274,12 +273,12 @@ def do(opts, args):
     else:
         buildarch = hostarch
         msger.info('No arch specified, using system arch: %s' % hostarch)
-    if buildarch in buildarchmap:
-        buildarch = buildarchmap[buildarch]
+    if buildarch in BUILDARCHMAP:
+        buildarch = BUILDARCHMAP[buildarch]
 
-    if not buildarch in supportedarchs:
+    if not buildarch in SUPPORTEDARCHS:
         msger.error('arch %s not supported, supported archs are: %s ' % \
-                   (buildarch, ','.join(supportedarchs)))
+                   (buildarch, ','.join(SUPPORTEDARCHS)))
 
     build_cmd  = configmgr.get('build_cmd', 'build')
     userid     = configmgr.get('user', 'remotebuild')
@@ -357,8 +356,8 @@ def do(opts, args):
         extrapkgs = opts.extra_packs.split(',')
         cmd += ['--extra-packs=%s' % ' '.join(extrapkgs)]
 
-    if hostarch != buildarch and buildarch in change_personality:
-        cmd = [ change_personality[buildarch] ] + cmd
+    if hostarch != buildarch and buildarch in CHANGE_PERSONALITY:
+        cmd = [ CHANGE_PERSONALITY[buildarch] ] + cmd
 
     proxies = get_env_proxies()
 
@@ -398,7 +397,8 @@ def do(opts, args):
 
     # Parse spec file
     try:
-        spec = rpm.parse_spec(os.path.join(export_dir, os.path.basename(specfile)))
+        spec = rpm.parse_spec(os.path.join(export_dir,
+                                           os.path.basename(specfile)))
     except GbpError, err:
         msger.error('%s' % err)
 
index bc74647..caa3fba 100644 (file)
@@ -67,7 +67,6 @@ def get_version(git_repo, commit):
 def make_log_entries(commits, git_repo):
     """Make changelog entries from the set of git commits."""
     entries = []
-    prevauthor = None
     # Add header
     author = git_repo.get_author_info()
     entries.append("* %s %s <%s> %s" % \
@@ -77,7 +76,6 @@ def make_log_entries(commits, git_repo):
     for commit in commits:
         commit_info =  git_repo.get_commit_info(commit)
         entries.append("- %s" % commit_info["subject"])
-        prevauthor = commit_info["author"].name
     return entries
 
 
index 249f729..ad867e6 100644 (file)
@@ -24,7 +24,7 @@ import subprocess
 from gitbuildsys import msger
 from gitbuildsys.conf import configmgr
 
-def do(opts, args):
+def do(opts, _args):
 
     if opts.arch in ['ia32', 'i686', 'i586', 'i386']:
         arch = 'i686'
@@ -45,12 +45,12 @@ def do(opts, args):
     try:
         subprocess.call(['sudo', 'cp', '/etc/resolv.conf', build_root + \
                          '/etc/resolv.conf'])
-    except:
+    except OSError:
         msger.warning('failed to setup /etc/resolv.conf')
 
     try:
         build_env = os.environ
-        build_env['PS1']="(tizen-build-env)@\h \W]\$ "
+        build_env['PS1'] = "(tizen-build-env)@\h \W]\$ "
         subprocess.call(cmd, env=build_env)
     except OSError, err:
         msger.error('failed to chroot to %s: %s' % (build_root, err))
index 57221a4..619ed44 100644 (file)
@@ -64,7 +64,7 @@ def do(opts, args):
     except GitRepositoryError, err:
         msger.error(str(err))
 
-    utils.gitStatusChecker(repo, opts)
+    utils.git_status_checker(repo, opts)
     workdir = repo.path
 
     if not os.path.exists("%s/packaging" % workdir):
@@ -106,7 +106,8 @@ def do(opts, args):
             msger.error("Repository error: %s" % excobj)
 
     try:
-        spec = rpm.parse_spec(os.path.join(export_dir, os.path.basename(specfile)))
+        spec = rpm.parse_spec(os.path.join(export_dir,
+                                           os.path.basename(specfile)))
     except GbpError, err:
         msger.error('%s' % err)
 
index a82a35a..51e354f 100644 (file)
@@ -21,8 +21,6 @@
 
 import os
 import glob
-import shutil
-
 
 from gitbuildsys import msger, errors, utils
 
@@ -84,7 +82,7 @@ def do(opts, args):
         msger.error(str(err))
 
     if not (opts.buildlog or opts.status):
-        utils.gitStatusChecker(repo, opts)
+        utils.git_status_checker(repo, opts)
     workdir = repo.path
 
     # TODO: check ./packaging dir at first
@@ -124,7 +122,8 @@ def do(opts, args):
             }
 
     tmpdir     = configmgr.get('tmpdir', 'general')
-    tmpd = utils.Temp(prefix=os.path.join(tmpdir, '.gbs_remotebuild_'), directory=True)
+    tmpd = utils.Temp(prefix=os.path.join(tmpdir, '.gbs_remotebuild_'),
+                      directory=True)
     exportdir = tmpd.path
     tmpf = utils.Temp(dirn=exportdir, prefix='.oscrc', content=oscrc)
     oscrcpath = tmpf.path
index 8d10970..02744e2 100644 (file)
@@ -54,9 +54,6 @@ class BrainConfigParser(SafeConfigParser):
         the sections and keys
         """
 
-        def _get_savekey(sec, opt):
-            return "%s.%s" % (sec, opt)
-
         # save the original filepath and contents
         self._fpname = fname
         self._flines = fptr.readlines()
@@ -86,7 +83,7 @@ class BrainConfigParser(SafeConfigParser):
                 value = line.strip()
                 if value:
                     cursect[optname] = "%s\n%s" % (cursect[optname], value)
-                    savekey = _get_savekey(cursect['__name__'], optname)
+                    savekey = "%s.%s" % (cursect['__name__'], optname)
                     self._opt_linenos[savekey].append(lineno)
             # a section header or option header?
             else:
@@ -132,7 +129,7 @@ class BrainConfigParser(SafeConfigParser):
                             optval = ''
                         optname = self.optionxform(optname.rstrip())
                         cursect[optname] = optval
-                        savekey = _get_savekey(cursect['__name__'], optname)
+                        savekey = "%s.%s" % (cursect['__name__'], optname)
                         self._opt_linenos[savekey] = [lineno]
 
                     else:
@@ -276,11 +273,13 @@ distconf = $build__distconf
     def __init__(self, fpath=None):
         self.cfgparser = BrainConfigParser()
         self.reset_from_conf(fpath)
+        self.replaced_keys = defaultdict(list)
 
     def reset_from_conf(self, fpath):
         if fpath:
             if not os.path.exists(fpath):
-                raise errors.ConfigError('Configuration file %s does not exist' % fpath)
+                raise errors.ConfigError('Configuration file %s does not '\
+                                         'exist' % fpath)
             fpaths = [fpath]
         else:
             # use the default path
@@ -298,7 +297,8 @@ distconf = $build__distconf
                 raise errors.ConfigError('config file error:%s' % err)
             self._check_passwd()
 
-    def _lookfor_confs(self):
+    @staticmethod
+    def _lookfor_confs():
         """Look for available config files following the order:
             > Global
             > User
index 369e7f4..7783fdd 100644 (file)
@@ -91,7 +91,8 @@ def show(cmdln_or_args):
         cmd = cmdln_or_args
 
     msg =  'running command: "%s"' % cmd
-    if out: out = out.strip()
+    if out:
+        out = out.strip()
     if out:
         msg += ', with output::'
         msg += '\n  +----------------'
index 2abb694..b71bd65 100644 (file)
@@ -166,15 +166,15 @@ def urlgrab(url, filename, user = None, passwd = None):
 
     try:
         curl.perform()
-    except pycurl.error, e:
-        errcode = e.args[0]
+    except pycurl.error, err:
+        errcode = err.args[0]
         if errcode == pycurl.E_OPERATION_TIMEOUTED:
-            raise errors.UrlError('timeout on %s: %s' % (url, e))
+            raise errors.UrlError('timeout on %s: %s' % (url, err))
         elif errcode == pycurl.E_FILESIZE_EXCEEDED:
             raise errors.UrlError('max download size exceeded on %s'\
                                        % url)
         else:
-            errmsg = 'pycurl error %s - "%s"' % (errcode, str(e.args[1]))
+            errmsg = 'pycurl error %s - "%s"' % (errcode, str(err.args[1]))
             raise errors.UrlError(errmsg)
     finally:
         outfile.close()
@@ -196,21 +196,18 @@ class RepoParser(object):
         self.parse()
 
     def get_buildconf(self):
-        elementTree = ET.parse(self.buildmeta)
-        root = elementTree.getroot()
-        buildElem = root.find('buildconf')
-        if buildElem is None:
+        etree = ET.parse(self.buildmeta)
+        buildelem = etree.getroot().find('buildconf')
+        if buildelem is None:
             return None
-        buildconf = buildElem.text.strip()
-
-        return buildconf
+        return buildelem.text.strip()
 
     def build_repos_from_buildmeta(self, baseurl):
         if not (self.buildmeta and os.path.exists(self.buildmeta)):
             return
 
-        elementTree = ET.parse(self.buildmeta)
-        root = elementTree.getroot()
+        etree = ET.parse(self.buildmeta)
+        root = etree.getroot()
         archs = []
         repos = []
         repo_items = root.find('repos')
@@ -269,7 +266,6 @@ class RepoParser(object):
                 if self.buildmeta:
                     self.buildconf = None
                     break
-                pass
 
             # Check if it's repo with builddata/build.xml exist
             buildxml_url = os.path.join(repo, 'builddata/build.xml')
@@ -313,11 +309,11 @@ class RepoParser(object):
 
         return None
 
-def gitStatusChecker(git, opts):
+def git_status_checker(git, opts):
     try:
         if opts.commit:
             git.rev_parse(opts.commit)
-        is_clean, out = git.is_clean()
+        is_clean = git.is_clean()[0]
         status = git.status()
     except (GbpError, GitRepositoryError), err:
         msger.error(str(err))
index e68f935..ebecebc 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,7 @@ import glob
 import re
 
 from distutils.core import setup
+
 try:
     import setuptools
     # enable "setup.py develop", optional
@@ -31,13 +32,11 @@ if sys.version_info[:2] > (2, 5):
     if len(sys.argv) > 1 and 'install' in sys.argv:
         try:
             import platform
-            (dist, ver, rid) = platform.linux_distribution()
-
             # for debian-like distros, mods will be installed to
             # ${PYTHONLIB}/dist-packages
-            if dist in ('debian', 'Ubuntu'):
+            if platform.linux_distribution()[0] in ('debian', 'Ubuntu'):
                 sys.argv.append('--install-layout=deb')
-        except:
+        except Exception:
             pass
 
 setup(name='gbs',