From 40368f624bf97d3a23e711b3aab679641221de66 Mon Sep 17 00:00:00 2001 From: Lingchaox Xin Date: Thu, 11 Apr 2013 14:08:47 +0800 Subject: [PATCH] Pylinted for common/utils.py Change-Id: I519780acbe77d80566c0adc0de87ab9a7b7adcd5 --- common/utils.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/common/utils.py b/common/utils.py index 4fc5104..3a720f7 100644 --- a/common/utils.py +++ b/common/utils.py @@ -16,24 +16,16 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +"""Tool collections can be used everywhere""" + import os import glob -import shutil -from lxml import etree -import sys -import tempfile, locale - -import errors -import runner -from envparas import export -envparas = ['GERRIT_SSHPORT', - 'GERRIT_USERNAME', - 'GERRIT_HOSTNAME'] -export(envparas, locals()) -GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME) +from common import runner class Workdir(object): + """A class which supports with statement""" + def __init__(self, path): self._newdir = path self._cwd = os.getcwd() @@ -47,7 +39,9 @@ class Workdir(object): os.chdir(self._cwd) def retry(func, opts): - """This will try to execute one function 3 times(by default) until success.""" + """This will try to execute one function 3 times(by default) until \ + success.""" + retry_count = 3 while retry_count > 0: if apply(func, opts): @@ -59,9 +53,13 @@ def retry(func, opts): return False def find_spec(workdir): + """Return specfile list in workdir""" + return glob.glob('%s/*.spec' % workdir) def find_changelog(workdir): + """Get change log needed""" + changes = glob.glob('%s/*.changes' % workdir) if len(changes) > 1: print("Can't decide which changelog file to use.") @@ -71,6 +69,8 @@ def find_changelog(workdir): return None def parse_link(path): + """Parse path link""" + if os.path.islink(path): return runner.outs('readlink %s' % path) else: @@ -82,7 +82,8 @@ def unicode_to_str(obj): if isinstance(obj, list): return [unicode_to_str(element) for element in obj] elif isinstance(obj, dict): - return {unicode_to_str(key) : unicode_to_str(value) for key, value in obj.iteritems()} + return {unicode_to_str(key) : unicode_to_str(value) for key, value \ + in obj.iteritems()} elif isinstance(obj, unicode): return obj.encode('utf-8') else: -- 2.7.4