summaryrefslogtreecommitdiff
path: root/bitbake
diff options
context:
space:
mode:
authorYu Ke <ke.yu@intel.com>2011-01-18 21:53:36 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-01-25 12:25:46 +0000
commitd8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2 (patch)
tree1ac0032521309fa0e047bce2191463ecb98b5956 /bitbake
parent6dc67915365d8455c22a411e231e71a72814b889 (diff)
downloadopenembedded-core-d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2.tar.gz
openembedded-core-d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2.tar.bz2
openembedded-core-d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2.zip
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 <ke.yu@intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 2aeb8b8fe1..c09917dcca 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?