From 2763e53bb5cb37f28373c09d8da8b56e34259f8e Mon Sep 17 00:00:00 2001
From: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Date: Wed, 17 Nov 2010 15:40:51 +0100
Subject: [PATCH 4/4] fetch: be more pythonic

no functional changes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
---
 lib/bb/fetch/__init__.py |    4 +---
 lib/bb/fetch/bzr.py      |    4 +---
 lib/bb/fetch/cvs.py      |   18 ++++--------------
 lib/bb/fetch/hg.py       |    9 ++-------
 lib/bb/fetch/osc.py      |    6 ++----
 lib/bb/fetch/perforce.py |    7 ++-----
 lib/bb/fetch/repo.py     |   23 +++++------------------
 lib/bb/fetch/svk.py      |   10 +++-------
 lib/bb/fetch/svn.py      |    5 ++---
 9 files changed, 22 insertions(+), 64 deletions(-)

diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py
index 81597be..532858e 100644
--- a/lib/bb/fetch/__init__.py
+++ b/lib/bb/fetch/__init__.py
@@ -656,9 +656,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', None)
         if not wanted_sum:
             return True
 
diff --git a/lib/bb/fetch/bzr.py b/lib/bb/fetch/bzr.py
index 92fff74..7d377a1 100644
--- a/lib/bb/fetch/bzr.py
+++ b/lib/bb/fetch/bzr.py
@@ -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
 
diff --git a/lib/bb/fetch/cvs.py b/lib/bb/fetch/cvs.py
index 42d71ba..bd919e2 100644
--- a/lib/bb/fetch/cvs.py
+++ b/lib/bb/fetch/cvs.py
@@ -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":
diff --git a/lib/bb/fetch/hg.py b/lib/bb/fetch/hg.py
index 86c58f8..370af40 100644
--- a/lib/bb/fetch/hg.py
+++ b/lib/bb/fetch/hg.py
@@ -45,10 +45,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):
@@ -85,9 +82,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":
diff --git a/lib/bb/fetch/osc.py b/lib/bb/fetch/osc.py
index a32d0b0..2682096 100644
--- a/lib/bb/fetch/osc.py
+++ b/lib/bb/fetch/osc.py
@@ -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)
 
diff --git a/lib/bb/fetch/perforce.py b/lib/bb/fetch/perforce.py
index bdd23de..222ed7e 100644
--- a/lib/bb/fetch/perforce.py
+++ b/lib/bb/fetch/perforce.py
@@ -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)
diff --git a/lib/bb/fetch/repo.py b/lib/bb/fetch/repo.py
index bafdb2a..e5132a1 100644
--- a/lib/bb/fetch/repo.py
+++ b/lib/bb/fetch/repo.py
@@ -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)
 
diff --git a/lib/bb/fetch/svk.py b/lib/bb/fetch/svk.py
index 2754971..595a9da 100644
--- a/lib/bb/fetch/svk.py
+++ b/lib/bb/fetch/svk.py
@@ -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)
diff --git a/lib/bb/fetch/svn.py b/lib/bb/fetch/svn.py
index c46ace4..a0d584c 100644
--- a/lib/bb/fetch/svn.py
+++ b/lib/bb/fetch/svn.py
@@ -67,6 +67,7 @@ class Svn(Fetch):
             #
             pv = data.getVar("PV", d, 0)
             if "DATE" in pv:
+                #logger.warn("You should switch to SRCREV")
                 ud.revision = ""
             else:
                 rev = Fetch.srcrev_internal_helper(ud, d)
@@ -91,9 +92,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:
-- 
1.7.2.3

