]> code.ossystems Code Review - openembedded-core.git/commitdiff
fetch: be more pythonic
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Wed, 17 Nov 2010 14:40:51 +0000 (15:40 +0100)
committerRichard Purdie <rpurdie@linux.intel.com>
Tue, 4 Jan 2011 14:46:41 +0000 (14:46 +0000)
no functional changes

(Bitbake rev: e88834fb7c6821cc29c12d296f2edd51f6eb3746)

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
bitbake/lib/bb/fetch/__init__.py
bitbake/lib/bb/fetch/bzr.py
bitbake/lib/bb/fetch/cvs.py
bitbake/lib/bb/fetch/hg.py
bitbake/lib/bb/fetch/osc.py
bitbake/lib/bb/fetch/perforce.py
bitbake/lib/bb/fetch/repo.py
bitbake/lib/bb/fetch/svk.py
bitbake/lib/bb/fetch/svn.py

index 18775301a36880e9403567bebe500337395db4c0..0562d72a23b5d680af83fc3cea624ce944938657 100644 (file)
@@ -733,9 +733,7 @@ class Fetch(object):
         """
         Verify the md5sum we wanted with the one we got
         """
-        wanted_sum = None
-        if 'md5sum' in ud.parm:
-            wanted_sum = ud.parm['md5sum']
+        wanted_sum = ud.parm.get('md5sum')
         if not wanted_sum:
             return True
 
index 92fff741ac4a35056702b24eca50eaa53b72c64e..7d377a15d9bf45bdb76f5d24a8cba6e7d9a720d7 100644 (file)
@@ -61,9 +61,7 @@ class Bzr(Fetch):
 
         basecmd = data.expand('${FETCHCMD_bzr}', d)
 
-        proto = "http"
-        if "proto" in ud.parm:
-            proto = ud.parm["proto"]
+        proto =  ud.parm.get('proto', 'http')
 
         bzrroot = ud.host + ud.path
 
index 42d71ba9fe30f167d9e198371138f5f6a764929b..bd919e234efa25936ba11e911b50c699037d49e5 100644 (file)
@@ -47,9 +47,7 @@ class Cvs(Fetch):
             raise MissingParameterError("cvs method needs a 'module' parameter")
         ud.module = ud.parm["module"]
 
-        ud.tag = ""
-        if 'tag' in ud.parm:
-            ud.tag = ud.parm['tag']
+        ud.tag = ud.parm.get('tag', "")
 
         # Override the default date in certain cases
         if 'date' in ud.parm:
@@ -76,17 +74,9 @@ class Cvs(Fetch):
 
     def go(self, loc, ud, d):
 
-        method = "pserver"
-        if "method" in ud.parm:
-            method = ud.parm["method"]
-
-        localdir = ud.module
-        if "localdir" in ud.parm:
-            localdir = ud.parm["localdir"]
-
-        cvs_port = ""
-        if "port" in ud.parm:
-            cvs_port = ud.parm["port"]
+        method = ud.parm.get('method', 'pserver')
+        localdir = ud.parm.get('localdir', ud.module)
+        cvs_port = ud.parm.get('port', '')
 
         cvs_rsh = None
         if method == "ext":
index 0f8d9b83247c111dd6b73ad9368bcb331bc8b926..6bc261ae681c1acc7be7d939fd5b555b0a93a2bc 100644 (file)
@@ -44,10 +44,7 @@ class Hg(Fetch):
         return ud.type in ['hg']
 
     def forcefetch(self, url, ud, d):
-        if 'rev' in ud.parm:
-            revTag = ud.parm['rev']
-        else:
-            revTag = "tip"
+        revTag = ud.parm.get('rev', 'tip')
         return revTag == "tip"
 
     def localpath(self, url, ud, d):
@@ -84,9 +81,7 @@ class Hg(Fetch):
 
         basecmd = data.expand('${FETCHCMD_hg}', d)
 
-        proto = "http"
-        if "proto" in ud.parm:
-            proto = ud.parm["proto"]
+        proto = ud.parm.get('proto', 'http')
 
         host = ud.host
         if proto == "file":
index a32d0b0a298200c16b6102292cca08dbade5a05c..26820967a3549c4769635bfee0f332b0036b41a1 100644 (file)
@@ -59,9 +59,7 @@ class Osc(Fetch):
 
         basecmd = data.expand('${FETCHCMD_osc}', d)
 
-        proto = "ocs"
-        if "proto" in ud.parm:
-            proto = ud.parm["proto"]
+        proto = ud.parm.get('proto', 'ocs')
 
         options = []
 
@@ -124,7 +122,7 @@ class Osc(Fetch):
         Generate a .oscrc to be used for this run.
         """
 
-        config_path = "%s/oscrc" % data.expand('${OSCDIR}', d)
+        config_path = os.path.join(data.expand('${OSCDIR}', d), "oscrc")
         if (os.path.exists(config_path)):
             os.remove(config_path)
 
index bdd23deef5cbcc3e8dc8482d7afce260a5c5d4e5..222ed7eaaa8cb16f6c9b9daf8eafd260d623be9e 100644 (file)
@@ -133,10 +133,7 @@ class Perforce(Fetch):
         else:
             path = depot
 
-        if "module" in parm:
-            module = parm["module"]
-        else:
-            module = os.path.basename(path)
+        module = parm.get('module', os.path.basename(path))
 
         localdata = data.createCopy(d)
         data.setVar('OVERRIDES', "p4:%s" % data.getVar('OVERRIDES', localdata), localdata)
@@ -206,4 +203,4 @@ class Perforce(Fetch):
                 pass
             raise FetchError(module)
         # cleanup
-        os.system('rm -rf %s' % tmpfile)
+        bb.utils.prunedir(tmpfile)
index bafdb2a179c4fa86afbf5cd228bf1532f55e079a..e5132a14fed7255a5821d912c7e44659401ba542 100644 (file)
@@ -45,24 +45,11 @@ class Repo(Fetch):
         "master".
         """
 
-        if "protocol" in ud.parm:
-            ud.proto = ud.parm["protocol"]
-        else:
-            ud.proto = "git"
-
-        if "branch" in ud.parm:
-            ud.branch = ud.parm["branch"]
-        else:
-            ud.branch = "master"
-
-        if "manifest" in ud.parm:
-            manifest = ud.parm["manifest"]
-            if manifest.endswith(".xml"):
-                ud.manifest = manifest
-            else:
-                ud.manifest = manifest + ".xml"
-        else:
-            ud.manifest = "default.xml"
+        ud.proto = ud.parm.get('protocol', 'git')
+        ud.branch = ud.parm.get('branch', 'master')
+        ud.manifest = ud.parm.get('manifest', 'default.xml')
+        if not ud.manifest.endswith('.xml'):
+            ud.manifest += '.xml'
 
         ud.localfile = data.expand("repo_%s%s_%s_%s.tar.gz" % (ud.host, ud.path.replace("/", "."), ud.manifest, ud.branch), d)
 
index 2754971eba64d0e10ec235cef453570c10842f92..595a9da25518ca760a9a0e28789e9021210fddcb 100644 (file)
@@ -48,18 +48,14 @@ class Svk(Fetch):
         else:
             ud.module = ud.parm["module"]
 
-        ud.revision = ""
-        if 'rev' in ud.parm:
-            ud.revision = ud.parm['rev']
+        ud.revision = ud.parm.get('rev', "")
 
         ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
 
         return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
 
     def forcefetch(self, url, ud, d):
-        if (ud.date == "now"):
-            return True
-        return False
+        return ud.date == "now"
 
     def go(self, loc, ud, d):
         """Fetch urls"""
@@ -105,4 +101,4 @@ class Svk(Fetch):
                 pass
             raise FetchError(ud.module)
         # cleanup
-        os.system('rm -rf %s' % tmpfile)
+        bb.utils.prunedir(tmpfile)
index c46ace423d35ded2a5ab91968daa36a5d66bfb57..dc35c9d121259b9180ddd5dbdca1df7d1a44a275 100644 (file)
@@ -91,9 +91,7 @@ class Svn(Fetch):
 
         basecmd = data.expand('${FETCHCMD_svn}', d)
 
-        proto = "svn"
-        if "proto" in ud.parm:
-            proto = ud.parm["proto"]
+        proto = ud.parm.get('proto', 'svn')
 
         svn_rsh = None
         if proto == "svn+ssh" and "rsh" in ud.parm: