From d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2 Mon Sep 17 00:00:00 2001 From: Yu Ke Date: Tue, 18 Jan 2011 21:53:36 +0800 Subject: bb.fetch2: add unpack method in fetcher copy exactly the base.bbclass:oe_unpack_file() to bb.fetch2 as the code base Signed-off-by: Yu Ke --- bitbake/lib/bb/fetch2/__init__.py | 84 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'bitbake') diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index 2aeb8b8fe..c09917dcc 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py @@ -254,6 +254,13 @@ def verify_checksum(u, ud, d): ud.sha256_expected, sha256data) raise FetchError("%s checksum mismatch." % u) +def subprocess_setup(): + import signal + # Python installs a SIGPIPE handler by default. This is usually not what + # non-Python subprocesses expect. + # SIGPIPE errors are known issues with gzip/bash + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + def go(d, urls = None): """ Fetch all urls @@ -624,6 +631,83 @@ class Fetch(object): """ raise NoMethodError("Missing implementation for url") + def unpack(file, data, url = None): + import subprocess + if not url: + url = "file://%s" % file + dots = file.split(".") + if dots[-1] in ['gz', 'bz2', 'Z']: + efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1]))) + else: + efile = file + cmd = None + if file.endswith('.tar'): + cmd = 'tar x --no-same-owner -f %s' % file + elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'): + cmd = 'tar xz --no-same-owner -f %s' % file + elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'): + cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file + elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'): + cmd = 'gzip -dc %s > %s' % (file, efile) + elif file.endswith('.bz2'): + cmd = 'bzip2 -dc %s > %s' % (file, efile) + elif file.endswith('.tar.xz'): + cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file + elif file.endswith('.xz'): + cmd = 'xz -dc %s > %s' % (file, efile) + elif file.endswith('.zip') or file.endswith('.jar'): + cmd = 'unzip -q -o' + (type, host, path, user, pswd, parm) = bb.decodeurl(url) + if 'dos' in parm: + cmd = '%s -a' % cmd + cmd = "%s '%s'" % (cmd, file) + elif os.path.isdir(file): + filesdir = os.path.realpath(bb.data.getVar("FILESDIR", data, 1)) + destdir = "." + if file[0:len(filesdir)] == filesdir: + destdir = file[len(filesdir):file.rfind('/')] + destdir = destdir.strip('/') + if len(destdir) < 1: + destdir = "." + elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK): + os.makedirs("%s/%s" % (os.getcwd(), destdir)) + cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir) + else: + (type, host, path, user, pswd, parm) = bb.decodeurl(url) + if not 'patch' in parm: + # The "destdir" handling was specifically done for FILESPATH + # items. So, only do so for file:// entries. + if type == "file" and path.find("/") != -1: + destdir = path.rsplit("/", 1)[0] + else: + destdir = "." + bb.mkdirhier("%s/%s" % (os.getcwd(), destdir)) + cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir) + + if not cmd: + return True + + dest = os.path.join(os.getcwd(), os.path.basename(file)) + if os.path.exists(dest): + if os.path.samefile(file, dest): + return True + + # Change to subdir before executing command + save_cwd = os.getcwd(); + parm = bb.decodeurl(url)[5] + if 'subdir' in parm: + newdir = ("%s/%s" % (os.getcwd(), parm['subdir'])) + bb.mkdirhier(newdir) + os.chdir(newdir) + + cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd) + bb.note("Unpacking %s to %s/" % (file, os.getcwd())) + ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True) + + os.chdir(save_cwd) + + return ret == 0 + def try_premirror(self, url, urldata, d): """ Should premirrors be used? -- cgit v1.2.3