]> code.ossystems Code Review - openembedded-core.git/commitdiff
fetch: add common helper _strip_leading_slashes()
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Wed, 17 Nov 2010 13:44:40 +0000 (14:44 +0100)
committerRichard Purdie <rpurdie@linux.intel.com>
Tue, 4 Jan 2011 14:46:41 +0000 (14:46 +0000)
Several fetcher need a way to strip leading slashes off a local path.
This helper-function consolidates all such occurances.

(Bitbake rev: 823a02185ed109054c6c1ae366221aaed0353f24)

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/hg.py
bitbake/lib/bb/fetch/osc.py
bitbake/lib/bb/fetch/perforce.py
bitbake/lib/bb/fetch/svn.py

index faf7fc489f9ed437baae5a8ff4648e109193175d..c9c8bdb893d60ce4bdfc81d01f56a9ea307bc745 100644 (file)
@@ -607,6 +607,13 @@ class Fetch(object):
         and duplicate code execution)
         """
         return url
+    def _strip_leading_slashes(self, relpath):
+        """
+        Remove leading slash as os.path.join can't cope
+        """
+        while os.path.isabs(relpath):
+            relpath = relpath[1:]
+        return relpath
 
     def setUrls(self, urls):
         self.__urls = urls
index 4cd51cb3378fae23ab01017c63697bbd79e49973..92fff741ac4a35056702b24eca50eaa53b72c64e 100644 (file)
@@ -37,10 +37,7 @@ class Bzr(Fetch):
     def localpath (self, url, ud, d):
 
         # Create paths to bzr checkouts
-        relpath = ud.path
-        if relpath.startswith('/'):
-            # Remove leading slash as os.path.join can't cope
-            relpath = relpath[1:]
+        relpath = self._strip_leading_slashes(ud.path)
         ud.pkgdir = os.path.join(data.expand('${BZRDIR}', d), ud.host, relpath)
 
         revision = Fetch.srcrev_internal_helper(ud, d)
index 264a52da9feb3b29671c63d01f0c7cec1a92c004..0f8d9b83247c111dd6b73ad9368bcb331bc8b926 100644 (file)
@@ -57,10 +57,7 @@ class Hg(Fetch):
         ud.module = ud.parm["module"]
 
         # Create paths to mercurial checkouts
-        relpath = ud.path
-        if relpath.startswith('/'):
-            # Remove leading slash as os.path.join can't cope
-            relpath = relpath[1:]
+        relpath = self._strip_leading_slashes(ud.path)
         ud.pkgdir = os.path.join(data.expand('${HGDIR}', d), ud.host, relpath)
         ud.moddir = os.path.join(ud.pkgdir, ud.module)
 
index 6fcb344ce0a5abecf9b59a72c605279b168a719c..a32d0b0a298200c16b6102292cca08dbade5a05c 100644 (file)
@@ -33,10 +33,7 @@ class Osc(Fetch):
         ud.module = ud.parm["module"]
 
         # Create paths to osc checkouts
-        relpath = ud.path
-        if relpath.startswith('/'):
-            # Remove leading slash as os.path.join can't cope
-            relpath = relpath[1:]
+        relpath = self._strip_leading_slashes(ud.path)
         ud.pkgdir = os.path.join(data.expand('${OSCDIR}', d), ud.host)
         ud.moddir = os.path.join(ud.pkgdir, relpath, ud.module)
 
@@ -73,10 +70,7 @@ class Osc(Fetch):
         if ud.revision:
             options.append("-r %s" % ud.revision)
 
-        coroot = ud.path
-        if coroot.startswith('/'):
-            # Remove leading slash as os.path.join can't cope
-            coroot= coroot[1:]
+        coroot = self._strip_leading_slashes(ud.path)
 
         if command is "fetch":
             osccmd = "%s %s co %s/%s %s" % (basecmd, config, coroot, ud.module, " ".join(options))
index 6f68d85614fb9210c0f725b92fdf347955d3d3f8..bdd23deef5cbcc3e8dc8482d7afce260a5c5d4e5 100644 (file)
@@ -113,8 +113,7 @@ class Perforce(Fetch):
         if which != -1:
             base = path[:which]
 
-        if base[0] == "/":
-            base = base[1:]
+        base = self._strip_leading_slashes(base)
 
         cset = Perforce.getcset(d, path, host, user, pswd, parm)
 
index 538b4c2a2d85e7b61006c7af9ae1c6f695b7827d..c46ace423d35ded2a5ab91968daa36a5d66bfb57 100644 (file)
@@ -49,10 +49,7 @@ class Svn(Fetch):
         ud.module = ud.parm["module"]
 
         # Create paths to svn checkouts
-        relpath = ud.path
-        if relpath.startswith('/'):
-            # Remove leading slash as os.path.join can't cope
-            relpath = relpath[1:]
+        relpath = self._strip_leading_slashes(ud.path)
         ud.pkgdir = os.path.join(data.expand('${SVNDIR}', d), ud.host, relpath)
         ud.moddir = os.path.join(ud.pkgdir, ud.module)