fetchers: Cleanup more variables
authorRichard Purdie <rpurdie@linux.intel.com>
Sun, 12 Nov 2006 15:03:40 +0000 (15:03 +0000)
committerRichard Purdie <rpurdie@linux.intel.com>
Sun, 12 Nov 2006 15:03:40 +0000 (15:03 +0000)
lib/bb/fetch/__init__.py
lib/bb/fetch/cvs.py
lib/bb/fetch/git.py
lib/bb/fetch/ssh.py
lib/bb/fetch/svk.py
lib/bb/fetch/svn.py
lib/bb/fetch/wget.py

index d75afaa..023b2e0 100644 (file)
@@ -110,7 +110,10 @@ def go(d):
     """Fetch all urls"""
     for m in methods:
         for u in m.urls:
+            # RP - is olddir needed?
+            olddir = os.path.abspath(os.getcwd())
             m.go(u, urldata[u], d)
+            os.chdir(olddir)
 
 def localpaths(d):
     """Return a list of the local filenames, assuming successful fetch"""
index 4c72bda..80fd908 100644 (file)
@@ -57,9 +57,9 @@ class Cvs(Fetch):
         elif ud.tag:
             ud.date = ""
 
-        ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.tag, ud.date), d)
+        ud.localfile = data.expand('%s_%s_%s_%s.tar.gz' % (ud.module.replace('/', '.'), ud.host, ud.tag, ud.date), d)
 
-        return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
+        return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
 
     def go(self, loc, ud, d):
 
@@ -67,14 +67,6 @@ class Cvs(Fetch):
         data.setVar('OVERRIDES', "cvs:%s" % data.getVar('OVERRIDES', localdata), localdata)
         data.update_data(localdata)
 
-        if not "module" in ud.parm:
-            raise MissingParameterError("cvs method needs a 'module' parameter")
-        else:
-            module = ud.parm["module"]
-
-        dlfile = ud.localpath
-        dldir = data.getVar('DL_DIR', localdata, 1)
-
         # setup cvs options
         options = []
 
@@ -86,18 +78,16 @@ class Cvs(Fetch):
         if "localdir" in ud.parm:
             localdir = ud.parm["localdir"]
         else:
-            localdir = module
+            localdir = ud.module
 
         cvs_rsh = None
         if method == "ext":
             if "rsh" in ud.parm:
                 cvs_rsh = ud.parm["rsh"]
 
-        tarfn = ud.localfile
-
         # try to use the tarball stash
         if (date != "now") and Fetch.try_mirror(d, ud.localfile):
-            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping cvs checkout." % tarfn)
+            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping cvs checkout." % ud.localpath)
             return
 
         if ud.date:
@@ -105,9 +95,6 @@ class Cvs(Fetch):
         if ud.tag:
             options.append("-r %s" % ud.tag)
 
-        olddir = os.path.abspath(os.getcwd())
-        os.chdir(data.expand(dldir, localdata))
-
         # setup cvsroot
         if method == "dir":
             cvsroot = ud.path
@@ -119,7 +106,7 @@ class Cvs(Fetch):
 
         data.setVar('CVSROOT', cvsroot, localdata)
         data.setVar('CVSCOOPTS', " ".join(options), localdata)
-        data.setVar('CVSMODULE', module, localdata)
+        data.setVar('CVSMODULE', ud.module, localdata)
         cvscmd = data.getVar('FETCHCOMMAND', localdata, 1)
         cvsupdatecmd = data.getVar('UPDATECOMMAND', localdata, 1)
 
@@ -150,15 +137,14 @@ class Cvs(Fetch):
                 os.rmdir(moddir)
             except OSError:
                  pass
-            raise FetchError(module)
+            raise FetchError(ud.module)
 
         os.chdir(moddir)
         os.chdir('..')
         # tar them up to a defined filename
-        myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(moddir)))
+        myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(moddir)))
         if myret != 0:
             try:
-                os.unlink(tarfn)
+                os.unlink(ud.localpath)
             except OSError:
                 pass
-        os.chdir(olddir)
index 4987e87..5c79962 100644 (file)
@@ -68,7 +68,7 @@ class Git(Fetch):
 
         ud.localfile = data.expand('git_%s%s_%s.tar.gz' % (ud.host, ud.path.replace('/', '.'), ud.tag), d)
 
-        return os.path.join(data.getVar("DL_DIR", d, 1), ud.localfile)
+        return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
 
     def go(self, loc, ud, d):
         """Fetch url"""
@@ -82,11 +82,9 @@ class Git(Fetch):
         coname = '%s' % (ud.tag)
         codir = os.path.join(repodir, coname)
 
-        cofile = ud.localpath
-
         # tag=="master" must always update
         if (ud.tag != "master") and Fetch.try_mirror(d, ud.localfile):
-            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % cofile)
+            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists (or was stashed). Skipping git checkout." % ud.localpath)
             return
 
         if not os.path.exists(repodir):
@@ -121,4 +119,4 @@ class Git(Fetch):
 
         os.chdir(codir)
         bb.msg.note(1, bb.msg.domain.Fetcher, "Creating tarball of git checkout")
-        rungitcmd("tar -czf %s %s" % (cofile, os.path.join(".", "*") ),d)
+        rungitcmd("tar -czf %s %s" % (ud.localpath, os.path.join(".", "*") ),d)
index 94a2b46..e5f69e3 100644 (file)
@@ -71,7 +71,7 @@ class SSH(Fetch):
         m = __pattern__.match(url)
         path = m.group('path')
         host = m.group('host')
-        lpath = os.path.join(data.getVar('DL_DIR', d, 1), host, os.path.basename(path))
+        lpath = os.path.join(data.getVar('DL_DIR', d, True), host, os.path.basename(path))
         return lpath
 
     def go(self, url, urldata, d):
index 8f106e7..383ce4c 100644 (file)
@@ -52,15 +52,15 @@ class Svk(Fetch):
         if not "module" in ud.parm:
             raise MissingParameterError("svk method needs a 'module' parameter")
         else:
-            module = ud.parm["module"]
+            ud.module = ud.parm["module"]
+
+        ud.revision = ""
         if 'rev' in ud.parm:
-            revision = ud.parm['rev']
-        else:
-            revision = ""
+            ud.revision = ud.parm['rev']
 
-        ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), revision, ud.date), d)
+        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, 1), ud.localfile)
+        return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
 
     def go(self, loc, ud, d):
         """Fetch urls"""
@@ -69,40 +69,21 @@ class Svk(Fetch):
         data.setVar('OVERRIDES', "svk:%s" % data.getVar('OVERRIDES', localdata), localdata)
         data.update_data(localdata)
 
-        if not "module" in ud.parm:
-            raise MissingParameterError("svk method needs a 'module' parameter")
-        else:
-            module = ud.parm["module"]
-
-        dlfile = ud.localpath
-        dldir = data.getVar('DL_DIR', localdata, 1)
-
         # setup svk options
         options = []
-        if 'rev' in ud.parm:
-            revision = ud.parm['rev']
-        else:
-            revision = ""
-
-        tarfn = ud.localfile
-        data.setVar('TARFILES', dlfile, localdata)
-        data.setVar('TARFN', tarfn, localdata)
 
         if (date != "now") and Fetch.try_mirror(d, ud.localfile):
             return
 
-        olddir = os.path.abspath(os.getcwd())
-        os.chdir(data.expand(dldir, localdata))
-
         svkroot = ud.host + ud.path
 
         data.setVar('SVKROOT', svkroot, localdata)
         data.setVar('SVKCOOPTS', " ".join(options), localdata)
-        data.setVar('SVKMODULE', module, localdata)
-        svkcmd = "svk co -r {%s} %s/%s" % (date, svkroot, module)
+        data.setVar('SVKMODULE', ud.module, localdata)
+        svkcmd = "svk co -r {%s} %s/%s" % (date, svkroot, ud.module)
 
-        if revision:
-            svkcmd = "svk co -r %s/%s" % (revision, svkroot, module)
+        if ud.revision:
+            svkcmd = "svk co -r %s/%s" % (ud.revision, svkroot, ud.module)
 
         # create temp directory
         bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: creating temporary directory")
@@ -112,7 +93,7 @@ class Svk(Fetch):
         tmpfile = tmppipe.readline().strip()
         if not tmpfile:
             bb.msg.error(bb.msg.domain.Fetcher, "Fetch: unable to create temporary directory.. make sure 'mktemp' is in the PATH.")
-            raise FetchError(module)
+            raise FetchError(ud.module)
 
         # check out sources there
         os.chdir(tmpfile)
@@ -124,17 +105,15 @@ class Svk(Fetch):
                 os.rmdir(tmpfile)
             except OSError:
                 pass
-            raise FetchError(module)
+            raise FetchError(ud.module)
 
-        os.chdir(os.path.join(tmpfile, os.path.dirname(module)))
+        os.chdir(os.path.join(tmpfile, os.path.dirname(ud.module)))
         # tar them up to a defined filename
-        myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
+        myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
         if myret != 0:
             try:
-                os.unlink(tarfn)
+                os.unlink(ud.localpath)
             except OSError:
                 pass
         # cleanup
         os.system('rm -rf %s' % tmpfile)
-        os.chdir(olddir)
-
index a068fa1..f8db7b2 100644 (file)
@@ -45,15 +45,15 @@ class Svn(Fetch):
         if not "module" in ud.parm:
             raise MissingParameterError("svn method needs a 'module' parameter")
         else:
-            module = ud.parm["module"]
+            ud.module = ud.parm["module"]
 
         ud.revision = ""
         if 'rev' in parm:
             ud.revision = ud.parm['rev']
 
-        ud.localfile = data.expand('%s_%s_%s_%s_%s.tar.gz' % (module.replace('/', '.'), ud.host, ud.path.replace('/', '.'), ud.revision, ud.date), d)
+        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, 1), )
+        return os.path.join(data.getVar("DL_DIR", d, True), ud.localfile)
 
     def go(self, loc, ud, d):
         """Fetch url"""
@@ -62,36 +62,22 @@ class Svn(Fetch):
         data.setVar('OVERRIDES', "svn:%s" % data.getVar('OVERRIDES', localdata), localdata)
         data.update_data(localdata)
 
-        if not "module" in ud.parm:
-            raise MissingParameterError("svn method needs a 'module' parameter")
-        else:
-            module = ud.parm["module"]
-
-        dlfile = self.localpath(loc, localdata)
-        dldir = data.getVar('DL_DIR', localdata, 1)
-
         # setup svn options
         options = []
 
+        proto = "svn"
         if "proto" in ud.parm:
             proto = ud.parm["proto"]
-        else:
-            proto = "svn"
 
         svn_rsh = None
         if proto == "svn+ssh" and "rsh" in ud.parm:
             svn_rsh = ud.parm["rsh"]
 
-        tarfn = ud.localfile
-
         # try to use the tarball stash
         if (date != "now") and Fetch.try_mirror(d, ud.localfile):
-            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % tarfn)
+            bb.msg.debug(1, bb.msg.domain.Fetcher, "%s already exists or was mirrored, skipping svn checkout." % ud.localpath)
             return
 
-        olddir = os.path.abspath(os.getcwd())
-        os.chdir(data.expand(dldir, localdata))
-
         svnroot = ud.host + ud.path
 
         # either use the revision, or SRCDATE in braces, or nothing for SRCDATE = "now"
@@ -100,9 +86,9 @@ class Svn(Fetch):
         elif ud.date != "now":
             options.append("-r {%s}" % ud.date)
 
-        data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, module), localdata)
+        data.setVar('SVNROOT', "%s://%s/%s" % (proto, svnroot, ud.module), localdata)
         data.setVar('SVNCOOPTS', " ".join(options), localdata)
-        data.setVar('SVNMODULE', module, localdata)
+        data.setVar('SVNMODULE', ud.module, localdata)
         svncmd = data.getVar('FETCHCOMMAND', localdata, 1)
         svnupcmd = data.getVar('UPDATECOMMAND', localdata, 1)
 
@@ -112,7 +98,7 @@ class Svn(Fetch):
 
         pkg=data.expand('${PN}', d)
         pkgdir=os.path.join(data.expand('${SVNDIR}', localdata), pkg)
-        moddir=os.path.join(pkgdir, module)
+        moddir=os.path.join(pkgdir, ud.module)
         bb.msg.debug(2, bb.msg.domain.Fetcher, "Fetch: checking for module directory '" + moddir + "'")
 
         if os.access(os.path.join(moddir,'.svn'), os.R_OK):
@@ -130,14 +116,13 @@ class Svn(Fetch):
             myret = os.system(svncmd)
 
         if myret != 0:
-            raise FetchError(module)
+            raise FetchError(ud.module)
 
         os.chdir(pkgdir)
         # tar them up to a defined filename
-        myret = os.system("tar -czf %s %s" % (os.path.join(dldir,tarfn), os.path.basename(module)))
+        myret = os.system("tar -czf %s %s" % (ud.localpath, os.path.basename(ud.module)))
         if myret != 0:
             try:
-                os.unlink(tarfn)
+                os.unlink(ud.localpath)
             except OSError:
                 pass
-        os.chdir(olddir)
index d417759..5620380 100644 (file)
@@ -45,7 +45,7 @@ class Wget(Fetch):
 
         url = bb.encodeurl([ud.type, ud.host, ud.path, ud.user, ud.pswd, {}])
 
-        return os.path.join(data.getVar("DL_DIR", d), os.path.basename(url))
+        return data.expand(os.path.join(data.getVar("DL_DIR", d), os.path.basename(url)), d)
 
     def go(self, uri, ud, d):
         """Fetch urls"""