From 87b6f7d27ace9d6465414c28bbba003f368a49dd Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Wed, 17 Nov 2010 14:44:40 +0100 Subject: fetch: add common helper _strip_leading_slashes() 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 Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch/__init__.py | 7 +++++++ bitbake/lib/bb/fetch/bzr.py | 5 +---- bitbake/lib/bb/fetch/hg.py | 5 +---- bitbake/lib/bb/fetch/osc.py | 10 ++-------- bitbake/lib/bb/fetch/perforce.py | 3 +-- bitbake/lib/bb/fetch/svn.py | 5 +---- 6 files changed, 13 insertions(+), 22 deletions(-) (limited to 'bitbake/lib/bb/fetch') diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py index faf7fc489f..c9c8bdb893 100644 --- a/bitbake/lib/bb/fetch/__init__.py +++ b/bitbake/lib/bb/fetch/__init__.py @@ -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 diff --git a/bitbake/lib/bb/fetch/bzr.py b/bitbake/lib/bb/fetch/bzr.py index 4cd51cb337..92fff741ac 100644 --- a/bitbake/lib/bb/fetch/bzr.py +++ b/bitbake/lib/bb/fetch/bzr.py @@ -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) diff --git a/bitbake/lib/bb/fetch/hg.py b/bitbake/lib/bb/fetch/hg.py index 264a52da9f..0f8d9b8324 100644 --- a/bitbake/lib/bb/fetch/hg.py +++ b/bitbake/lib/bb/fetch/hg.py @@ -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) diff --git a/bitbake/lib/bb/fetch/osc.py b/bitbake/lib/bb/fetch/osc.py index 6fcb344ce0..a32d0b0a29 100644 --- a/bitbake/lib/bb/fetch/osc.py +++ b/bitbake/lib/bb/fetch/osc.py @@ -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)) diff --git a/bitbake/lib/bb/fetch/perforce.py b/bitbake/lib/bb/fetch/perforce.py index 6f68d85614..bdd23deef5 100644 --- a/bitbake/lib/bb/fetch/perforce.py +++ b/bitbake/lib/bb/fetch/perforce.py @@ -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) diff --git a/bitbake/lib/bb/fetch/svn.py b/bitbake/lib/bb/fetch/svn.py index 538b4c2a2d..c46ace423d 100644 --- a/bitbake/lib/bb/fetch/svn.py +++ b/bitbake/lib/bb/fetch/svn.py @@ -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) -- cgit v1.2.3-54-g00ecf