summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2
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/lib/bb/fetch2
parent6dc67915365d8455c22a411e231e71a72814b889 (diff)
downloadpoky-d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2.tar.gz
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/lib/bb/fetch2')
-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):
254 ud.sha256_expected, sha256data) 254 ud.sha256_expected, sha256data)
255 raise FetchError("%s checksum mismatch." % u) 255 raise FetchError("%s checksum mismatch." % u)
256 256
257def subprocess_setup():
258 import signal
259 # Python installs a SIGPIPE handler by default. This is usually not what
260 # non-Python subprocesses expect.
261 # SIGPIPE errors are known issues with gzip/bash
262 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
263
257def go(d, urls = None): 264def go(d, urls = None):
258 """ 265 """
259 Fetch all urls 266 Fetch all urls
@@ -624,6 +631,83 @@ class Fetch(object):
624 """ 631 """
625 raise NoMethodError("Missing implementation for url") 632 raise NoMethodError("Missing implementation for url")
626 633
634 def unpack(file, data, url = None):
635 import subprocess
636 if not url:
637 url = "file://%s" % file
638 dots = file.split(".")
639 if dots[-1] in ['gz', 'bz2', 'Z']:
640 efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
641 else:
642 efile = file
643 cmd = None
644 if file.endswith('.tar'):
645 cmd = 'tar x --no-same-owner -f %s' % file
646 elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
647 cmd = 'tar xz --no-same-owner -f %s' % file
648 elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'):
649 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
650 elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):
651 cmd = 'gzip -dc %s > %s' % (file, efile)
652 elif file.endswith('.bz2'):
653 cmd = 'bzip2 -dc %s > %s' % (file, efile)
654 elif file.endswith('.tar.xz'):
655 cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file
656 elif file.endswith('.xz'):
657 cmd = 'xz -dc %s > %s' % (file, efile)
658 elif file.endswith('.zip') or file.endswith('.jar'):
659 cmd = 'unzip -q -o'
660 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
661 if 'dos' in parm:
662 cmd = '%s -a' % cmd
663 cmd = "%s '%s'" % (cmd, file)
664 elif os.path.isdir(file):
665 filesdir = os.path.realpath(bb.data.getVar("FILESDIR", data, 1))
666 destdir = "."
667 if file[0:len(filesdir)] == filesdir:
668 destdir = file[len(filesdir):file.rfind('/')]
669 destdir = destdir.strip('/')
670 if len(destdir) < 1:
671 destdir = "."
672 elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
673 os.makedirs("%s/%s" % (os.getcwd(), destdir))
674 cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
675 else:
676 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
677 if not 'patch' in parm:
678 # The "destdir" handling was specifically done for FILESPATH
679 # items. So, only do so for file:// entries.
680 if type == "file" and path.find("/") != -1:
681 destdir = path.rsplit("/", 1)[0]
682 else:
683 destdir = "."
684 bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
685 cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
686
687 if not cmd:
688 return True
689
690 dest = os.path.join(os.getcwd(), os.path.basename(file))
691 if os.path.exists(dest):
692 if os.path.samefile(file, dest):
693 return True
694
695 # Change to subdir before executing command
696 save_cwd = os.getcwd();
697 parm = bb.decodeurl(url)[5]
698 if 'subdir' in parm:
699 newdir = ("%s/%s" % (os.getcwd(), parm['subdir']))
700 bb.mkdirhier(newdir)
701 os.chdir(newdir)
702
703 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd)
704 bb.note("Unpacking %s to %s/" % (file, os.getcwd()))
705 ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)
706
707 os.chdir(save_cwd)
708
709 return ret == 0
710
627 def try_premirror(self, url, urldata, d): 711 def try_premirror(self, url, urldata, d):
628 """ 712 """
629 Should premirrors be used? 713 Should premirrors be used?