diff options
author | Yu Ke <ke.yu@intel.com> | 2011-01-18 22:08:09 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2011-01-25 12:25:46 +0000 |
commit | 84ff79413a3b56f287f42b8ca1dd2ab194337c42 (patch) | |
tree | 36711f4fdaf3c08b8f90b6cbc5ea8d4fb1d7c00b /bitbake | |
parent | d8698b92ffcc2cbd29b57d3dc8e851d3d6c137f2 (diff) | |
download | poky-84ff79413a3b56f287f42b8ca1dd2ab194337c42.tar.gz |
bb.fetch2: revise the Fetch.unpack API
change the unpack to use the urldata and rootdir parameter
- urldata is the FetchData instance
- rootdir is the dir to put the extracted source. the original unpack
use current dir (os.getcwd) as destination dir, which is not flexible
and error-prone (error will occur if caller not chdir to dest dir)
Signed-off-by: Yu Ke <ke.yu@intel.com>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/__init__.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py index c09917dcca..e7752ee336 100644 --- a/bitbake/lib/bb/fetch2/__init__.py +++ b/bitbake/lib/bb/fetch2/__init__.py | |||
@@ -631,10 +631,9 @@ class Fetch(object): | |||
631 | """ | 631 | """ |
632 | raise NoMethodError("Missing implementation for url") | 632 | raise NoMethodError("Missing implementation for url") |
633 | 633 | ||
634 | def unpack(file, data, url = None): | 634 | def unpack(self, urldata, rootdir, data): |
635 | import subprocess | 635 | import subprocess |
636 | if not url: | 636 | file = urldata.localpath |
637 | url = "file://%s" % file | ||
638 | dots = file.split(".") | 637 | dots = file.split(".") |
639 | if dots[-1] in ['gz', 'bz2', 'Z']: | 638 | 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]))) | 639 | efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1]))) |
@@ -657,8 +656,7 @@ class Fetch(object): | |||
657 | cmd = 'xz -dc %s > %s' % (file, efile) | 656 | cmd = 'xz -dc %s > %s' % (file, efile) |
658 | elif file.endswith('.zip') or file.endswith('.jar'): | 657 | elif file.endswith('.zip') or file.endswith('.jar'): |
659 | cmd = 'unzip -q -o' | 658 | cmd = 'unzip -q -o' |
660 | (type, host, path, user, pswd, parm) = bb.decodeurl(url) | 659 | if 'dos' in urldata.parm: |
661 | if 'dos' in parm: | ||
662 | cmd = '%s -a' % cmd | 660 | cmd = '%s -a' % cmd |
663 | cmd = "%s '%s'" % (cmd, file) | 661 | cmd = "%s '%s'" % (cmd, file) |
664 | elif os.path.isdir(file): | 662 | elif os.path.isdir(file): |
@@ -669,34 +667,33 @@ class Fetch(object): | |||
669 | destdir = destdir.strip('/') | 667 | destdir = destdir.strip('/') |
670 | if len(destdir) < 1: | 668 | if len(destdir) < 1: |
671 | destdir = "." | 669 | destdir = "." |
672 | elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK): | 670 | elif not os.access("%s/%s" % (rootdir, destdir), os.F_OK): |
673 | os.makedirs("%s/%s" % (os.getcwd(), destdir)) | 671 | os.makedirs("%s/%s" % (rootdir, destdir)) |
674 | cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir) | 672 | cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir) |
675 | else: | 673 | else: |
676 | (type, host, path, user, pswd, parm) = bb.decodeurl(url) | 674 | if not 'patch' in urldata.parm: |
677 | if not 'patch' in parm: | ||
678 | # The "destdir" handling was specifically done for FILESPATH | 675 | # The "destdir" handling was specifically done for FILESPATH |
679 | # items. So, only do so for file:// entries. | 676 | # items. So, only do so for file:// entries. |
680 | if type == "file" and path.find("/") != -1: | 677 | if urldata.type == "file" and urldata.path.find("/") != -1: |
681 | destdir = path.rsplit("/", 1)[0] | 678 | destdir = urldata.path.rsplit("/", 1)[0] |
682 | else: | 679 | else: |
683 | destdir = "." | 680 | destdir = "." |
684 | bb.mkdirhier("%s/%s" % (os.getcwd(), destdir)) | 681 | bb.mkdirhier("%s/%s" % (rootdir, destdir)) |
685 | cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir) | 682 | cmd = 'cp %s %s/%s/' % (file, rootdir, destdir) |
686 | 683 | ||
687 | if not cmd: | 684 | if not cmd: |
688 | return True | 685 | return True |
689 | 686 | ||
690 | dest = os.path.join(os.getcwd(), os.path.basename(file)) | 687 | dest = os.path.join(rootdir, os.path.basename(file)) |
691 | if os.path.exists(dest): | 688 | if os.path.exists(dest): |
692 | if os.path.samefile(file, dest): | 689 | if os.path.samefile(file, dest): |
693 | return True | 690 | return True |
694 | 691 | ||
695 | # Change to subdir before executing command | 692 | # Change to subdir before executing command |
696 | save_cwd = os.getcwd(); | 693 | save_cwd = os.getcwd(); |
697 | parm = bb.decodeurl(url)[5] | 694 | os.chdir(rootdir) |
698 | if 'subdir' in parm: | 695 | if 'subdir' in urldata.parm: |
699 | newdir = ("%s/%s" % (os.getcwd(), parm['subdir'])) | 696 | newdir = ("%s/%s" % (rootdir, urldata.parm['subdir'])) |
700 | bb.mkdirhier(newdir) | 697 | bb.mkdirhier(newdir) |
701 | os.chdir(newdir) | 698 | os.chdir(newdir) |
702 | 699 | ||