Skip to contentSkip to conversation

Adding a nounpack url parameter to base.bbclass

PATCH Ash Charles 2 participants 2 messages Apr 30, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I added a minor change to base.bbclass to accept a 'nounpack=1' parameter to stop bitbake from unpacking a file that has a bz2, tar... extension; this is useful if you actually want to include such an archive file in a package. I'm not familiar with the policies for submitting patches however I thought other people might find it useful so I've included it below:
==================================

classes/base.bbclass +9 -2
index 4d5d73d..387a066 100644
@@ -171,21 +171,29 @@ def oe_unpack_file(file, data, url = None):
        else:
                efile = file
        cmd = None
-       if file.endswith('.tar'):
+
+        # allow a 'nounpack=1' url parameter to prevent unpacking of archives
+        unpack = True
+        (type, host, path, user, pswd, parm) = bb.decodeurl(url)
+        if 'nounpack' in parm:
+                if parm['nounpack']:
+                        unpack = False
+
+       if unpack and 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'):
+ elif unpack and (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'):
+ elif unpack and (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'):
+       elif unpack and (file.endswith('.gz') or file.endswith('.Z')
or file.endswith('.z')):
                cmd = 'gzip -dc %s > %s' % (file, efile)
-       elif file.endswith('.bz2'):
+       elif unpack and file.endswith('.bz2'):
                cmd = 'bzip2 -dc %s > %s' % (file, efile)
-       elif file.endswith('.tar.xz'):
+       elif unpack and file.endswith('.tar.xz'):
                cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file
-       elif file.endswith('.xz'):
+       elif unpack and file.endswith('.xz'):
                cmd = 'xz -dc %s > %s' % (file, efile)

- elif file.endswith('.zip') or file.endswith('.jar'):
+ elif unpack and (file.endswith('.zip') or file.endswith('.jar')):
cmd = 'unzip -q -o'
(type, host, path, user, pswd, parm) = bb.decodeurl(url) if 'dos' in parm:
==================================

This is a learning experience for me so comments on how to submit patches properly are very welcome :).

-Ash

classes/base.bbclass +16 -8
index 4d5d73d..5b3d92e 100644
@@ -171,21 +171,29 @@ def oe_unpack_file(file, data, url = None):
 	else:
 		efile = file
 	cmd = None
-	if file.endswith('.tar'):
+
+        # allow a 'nounpack=1' url parameter to prevent unpacking of archives
+        unpack = True
+        (type, host, path, user, pswd, parm) = bb.decodeurl(url)
+        if 'nounpack' in parm:
+                if parm['nounpack']:
+                        unpack = False
+
+	if unpack and 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'):
+	elif unpack and (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'):
+	elif unpack and (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'):
+	elif unpack and (file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z')):
 		cmd = 'gzip -dc %s > %s' % (file, efile)
-	elif file.endswith('.bz2'):
+	elif unpack and file.endswith('.bz2'):
 		cmd = 'bzip2 -dc %s > %s' % (file, efile)
-	elif file.endswith('.tar.xz'):
+	elif unpack and file.endswith('.tar.xz'):
 		cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file
-	elif file.endswith('.xz'):
+	elif unpack and file.endswith('.xz'):
 		cmd = 'xz -dc %s > %s' % (file, efile)
-	elif file.endswith('.zip') or file.endswith('.jar'):
+	elif unpack and (file.endswith('.zip') or file.endswith('.jar')):
 		cmd = 'unzip -q -o'
 		(type, host, path, user, pswd, parm) = bb.decodeurl(url)
 		if 'dos' in parm:
#1 lore raw

В сообщении от Пятница 30 апреля 2010 21:28:40 автор Ash Charles написал:

Quoted 54 lines

I added a minor change to base.bbclass to accept a 'nounpack=1' parameter to stop bitbake from unpacking a file that has a bz2, tar... extension; this is useful if you actually want to include such an archive file in a package. I'm not familiar with the policies for submitting patches however I thought other people might find it useful so I've included it below:
==================================

classes/base.bbclass +8 -2
index 4d5d73d..387a066 100644
@@ -171,21 +171,29 @@ def oe_unpack_file(file, data, url = None):
        else:
                efile = file
        cmd = None
-       if file.endswith('.tar'):
+
+        # allow a 'nounpack=1' url parameter to prevent unpacking of
 archives +        unpack = True
+        (type, host, path, user, pswd, parm) = bb.decodeurl(url)
+        if 'nounpack' in parm:
+                if parm['nounpack']:
+                        unpack = False
+
+       if unpack and 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'):
+ elif unpack and (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'):
+ elif unpack and (file.endswith('.tbz') or
file.endswith('.tbz2') or file.endswith('.tar.bz2')):

                cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
classes/base.bbclass +4 -5
-       elif file.endswith('.gz') or file.endswith('.Z') or
 file.endswith('.z'): +       elif unpack and (file.endswith('.gz') or
 file.endswith('.Z') or file.endswith('.z')):
                cmd = 'gzip -dc %s > %s' % (file, efile)
-       elif file.endswith('.bz2'):
+       elif unpack and file.endswith('.bz2'):
                cmd = 'bzip2 -dc %s > %s' % (file, efile)
-       elif file.endswith('.tar.xz'):
+       elif unpack and file.endswith('.tar.xz'):
                cmd = 'xz -dc %s | tar x --no-same-owner -f -' % file
-       elif file.endswith('.xz'):
+       elif unpack and file.endswith('.xz'):
                cmd = 'xz -dc %s > %s' % (file, efile)
-       elif file.endswith('.zip') or file.endswith('.jar'):
+       elif unpack and (file.endswith('.zip') or file.endswith('.jar')):
                cmd = 'unzip -q -o'
                (type, host, path, user, pswd, parm) = bb.decodeurl(url)
                if 'dos' in parm:
Quoted 1 line

==================================

Wouldn't it be easier to do something like:

+ if 'nounpack' not in parm:
+ if file.endswith('.tar'):
....
+ elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
....

? The diff would be a bit bigger, but the end result is cleaner IMO.

Signature · 3 lines
 http://roman.khimov.ru
mailto: [email protected]
gpg --keyserver hkp://subkeys.pgp.net --recv-keys 0xE5E055C3