mirror of
https://git.yoctoproject.org/poky
synced 2026-09-20 03:49:32 +02:00
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>
This commit is contained in:
@@ -631,10 +631,9 @@ class Fetch(object):
|
|||||||
"""
|
"""
|
||||||
raise NoMethodError("Missing implementation for url")
|
raise NoMethodError("Missing implementation for url")
|
||||||
|
|
||||||
def unpack(file, data, url = None):
|
def unpack(self, urldata, rootdir, data):
|
||||||
import subprocess
|
import subprocess
|
||||||
if not url:
|
file = urldata.localpath
|
||||||
url = "file://%s" % file
|
|
||||||
dots = file.split(".")
|
dots = file.split(".")
|
||||||
if dots[-1] in ['gz', 'bz2', 'Z']:
|
if dots[-1] in ['gz', 'bz2', 'Z']:
|
||||||
efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
|
efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
|
||||||
@@ -657,8 +656,7 @@ class Fetch(object):
|
|||||||
cmd = 'xz -dc %s > %s' % (file, efile)
|
cmd = 'xz -dc %s > %s' % (file, efile)
|
||||||
elif file.endswith('.zip') or file.endswith('.jar'):
|
elif file.endswith('.zip') or file.endswith('.jar'):
|
||||||
cmd = 'unzip -q -o'
|
cmd = 'unzip -q -o'
|
||||||
(type, host, path, user, pswd, parm) = bb.decodeurl(url)
|
if 'dos' in urldata.parm:
|
||||||
if 'dos' in parm:
|
|
||||||
cmd = '%s -a' % cmd
|
cmd = '%s -a' % cmd
|
||||||
cmd = "%s '%s'" % (cmd, file)
|
cmd = "%s '%s'" % (cmd, file)
|
||||||
elif os.path.isdir(file):
|
elif os.path.isdir(file):
|
||||||
@@ -669,34 +667,33 @@ class Fetch(object):
|
|||||||
destdir = destdir.strip('/')
|
destdir = destdir.strip('/')
|
||||||
if len(destdir) < 1:
|
if len(destdir) < 1:
|
||||||
destdir = "."
|
destdir = "."
|
||||||
elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
|
elif not os.access("%s/%s" % (rootdir, destdir), os.F_OK):
|
||||||
os.makedirs("%s/%s" % (os.getcwd(), destdir))
|
os.makedirs("%s/%s" % (rootdir, destdir))
|
||||||
cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
|
cmd = 'cp -pPR %s %s/%s/' % (file, rootdir, destdir)
|
||||||
else:
|
else:
|
||||||
(type, host, path, user, pswd, parm) = bb.decodeurl(url)
|
if not 'patch' in urldata.parm:
|
||||||
if not 'patch' in parm:
|
|
||||||
# The "destdir" handling was specifically done for FILESPATH
|
# The "destdir" handling was specifically done for FILESPATH
|
||||||
# items. So, only do so for file:// entries.
|
# items. So, only do so for file:// entries.
|
||||||
if type == "file" and path.find("/") != -1:
|
if urldata.type == "file" and urldata.path.find("/") != -1:
|
||||||
destdir = path.rsplit("/", 1)[0]
|
destdir = urldata.path.rsplit("/", 1)[0]
|
||||||
else:
|
else:
|
||||||
destdir = "."
|
destdir = "."
|
||||||
bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
|
bb.mkdirhier("%s/%s" % (rootdir, destdir))
|
||||||
cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
|
cmd = 'cp %s %s/%s/' % (file, rootdir, destdir)
|
||||||
|
|
||||||
if not cmd:
|
if not cmd:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
dest = os.path.join(os.getcwd(), os.path.basename(file))
|
dest = os.path.join(rootdir, os.path.basename(file))
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
if os.path.samefile(file, dest):
|
if os.path.samefile(file, dest):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Change to subdir before executing command
|
# Change to subdir before executing command
|
||||||
save_cwd = os.getcwd();
|
save_cwd = os.getcwd();
|
||||||
parm = bb.decodeurl(url)[5]
|
os.chdir(rootdir)
|
||||||
if 'subdir' in parm:
|
if 'subdir' in urldata.parm:
|
||||||
newdir = ("%s/%s" % (os.getcwd(), parm['subdir']))
|
newdir = ("%s/%s" % (rootdir, urldata.parm['subdir']))
|
||||||
bb.mkdirhier(newdir)
|
bb.mkdirhier(newdir)
|
||||||
os.chdir(newdir)
|
os.chdir(newdir)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user