[arch-dev-public] [PATCH] Use a wrapper script to support different compression types
From: Pierre Schmitz <pierre@archlinux.de> Signed-off-by: Pierre Schmitz <pierre@archlinux.de> --- namcap | 27 +++++++++++++++++++++++++++ namcap.py | 2 +- pacman.py | 2 +- setup.py | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 namcap diff --git a/namcap b/namcap new file mode 100644 index 0000000..f262985 --- /dev/null +++ b/namcap @@ -0,0 +1,27 @@ +#!/bin/bash + +args='' +tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) + +for arg in "${@}"; do + if echo "${arg}" | grep -q -E "^.+\.pkg\.tar\..+$" && [ -f "${arg}" ]; then + + case "${arg##*.}" in + gz|z|Z) cmd='gzip' ;; + bz2|bz) cmd='bzip2' ;; + xz) cmd='xz' ;; + *) echo 'Unsupported compression'; exit 1;; + esac + + tar="${tmp}/$(basename "${arg%.*}")" + $cmd -dcf "${arg}" > "${tar}" + + args="${args} ${tar}" + else + args="${args} ${arg}" + fi +done + +python -m namcap ${args} + +rm -rf "${tmp}" diff --git a/namcap.py b/namcap.py index 19c6ceb..18dfbc8 100755 --- a/namcap.py +++ b/namcap.py @@ -228,7 +228,7 @@ for package in packages: print "Error: Problem reading " + package usage() - if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': process_realpackage(package, active_modules) elif package[-8:] == 'PKGBUILD': process_pkgbuild(package, active_modules) diff --git a/pacman.py b/pacman.py index e4b6cf3..c56d399 100644 --- a/pacman.py +++ b/pacman.py @@ -66,7 +66,7 @@ def load(package, root=None): if root == None: root = pacmandb # We know it's a local package - if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': pkgtar = tarfile.open(package, "r") if not pkgtar: return None diff --git a/setup.py b/setup.py index 66ee2ba..754ee72 100755 --- a/setup.py +++ b/setup.py @@ -10,6 +10,6 @@ setup(name="namcap", description="Pacman package analyzer", author="Jason Chu", author_email="jason@archlinux.org", - py_modules=["pacman"], packages=["Namcap"], scripts=["namcap.py", 'parsepkgbuild'],data_files =DATAFILES) + py_modules=["pacman", "namcap"], packages=["Namcap"], scripts=['parsepkgbuild', 'namcap'],data_files =DATAFILES) # vim: set ts=4 sw=4 noet: -- 1.7.0
OK, here goes nothing. On Tue, Feb 23, 2010 at 11:26 PM, Dan McGee <dan@archlinux.org> wrote:
From: Pierre Schmitz <pierre@archlinux.de>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de> --- namcap | 27 +++++++++++++++++++++++++++ namcap.py | 2 +- pacman.py | 2 +- setup.py | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 namcap
diff --git a/namcap b/namcap new file mode 100644 index 0000000..f262985 --- /dev/null +++ b/namcap @@ -0,0 +1,27 @@ +#!/bin/bash + +args='' +tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) + +for arg in "${@}"; do + if echo "${arg}" | grep -q -E "^.+\.pkg\.tar\..+$" && [ -f "${arg}" ]; then + + case "${arg##*.}" in + gz|z|Z) cmd='gzip' ;; + bz2|bz) cmd='bzip2' ;; + xz) cmd='xz' ;; + *) echo 'Unsupported compression'; exit 1;; + esac + + tar="${tmp}/$(basename "${arg%.*}")" + $cmd -dcf "${arg}" > "${tar}" + + args="${args} ${tar}" + else + args="${args} ${arg}" + fi +done + +python -m namcap ${args} + +rm -rf "${tmp}" Overall this script is in pretty good shape. One big problem however is this: dmcgee@galway ~/projects/namcap (master) $ du -sh /tmp/namcap.* 93M /tmp/namcap.1094 93M /tmp/namcap.1648 248K /tmp/namcap.25917 248K /tmp/namcap.26362 248K /tmp/namcap.26423 248K /tmp/namcap.26526 248K /tmp/namcap.26922
I've managed to accumulate a ton of junk in /tmp/ already, because there are several ways to exit the script without the rm getting called. I think what we want to set up is a trap function. makepkg has a bit of a complex one, but it should go something like this: tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) cleanup() { rm -rf "${tmp}" } trap 'cleanup' 0 And then completely remove the rm -rf at the end, as it will happen in any exit condition.
diff --git a/namcap.py b/namcap.py index 19c6ceb..18dfbc8 100755 --- a/namcap.py +++ b/namcap.py @@ -228,7 +228,7 @@ for package in packages: print "Error: Problem reading " + package usage()
- if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': I took care of this one a bit differently tonight, and hopefully a bit smarter from a python point of view: http://projects.archlinux.org/namcap.git/commit/?id=0e4a9cbe0be95f061effac4e...
process_realpackage(package, active_modules) elif package[-8:] == 'PKGBUILD': process_pkgbuild(package, active_modules) diff --git a/pacman.py b/pacman.py index e4b6cf3..c56d399 100644 --- a/pacman.py +++ b/pacman.py @@ -66,7 +66,7 @@ def load(package, root=None): if root == None: root = pacmandb # We know it's a local package - if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': pkgtar = tarfile.open(package, "r") if not pkgtar: return None diff --git a/setup.py b/setup.py index 66ee2ba..754ee72 100755 --- a/setup.py +++ b/setup.py @@ -10,6 +10,6 @@ setup(name="namcap", description="Pacman package analyzer", author="Jason Chu", author_email="jason@archlinux.org", - py_modules=["pacman"], packages=["Namcap"], scripts=["namcap.py", 'parsepkgbuild'],data_files =DATAFILES) + py_modules=["pacman", "namcap"], packages=["Namcap"], scripts=['parsepkgbuild', 'namcap'],data_files =DATAFILES) Looks fine to me, although I touched up the setup.py file tonight so
So you can omit this change and the below one in pacman.py from the patch resubmit. these are on seperate lines like the rest of the data was: http://projects.archlinux.org/namcap.git/commit/?id=de1d5e9dfad8d79fda6903b1... -Dan
On Tue, Feb 23, 2010 at 11:51 PM, Dan McGee <dan@archlinux.org> wrote:
OK, here goes nothing.
On Tue, Feb 23, 2010 at 11:26 PM, Dan McGee <dan@archlinux.org> wrote:
From: Pierre Schmitz <pierre@archlinux.de>
Signed-off-by: Pierre Schmitz <pierre@archlinux.de> --- namcap | 27 +++++++++++++++++++++++++++ namcap.py | 2 +- pacman.py | 2 +- setup.py | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 namcap
diff --git a/namcap b/namcap new file mode 100644 index 0000000..f262985 --- /dev/null +++ b/namcap @@ -0,0 +1,27 @@ +#!/bin/bash + +args='' +tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) + +for arg in "${@}"; do + if echo "${arg}" | grep -q -E "^.+\.pkg\.tar\..+$" && [ -f "${arg}" ]; then + + case "${arg##*.}" in + gz|z|Z) cmd='gzip' ;; + bz2|bz) cmd='bzip2' ;; + xz) cmd='xz' ;; + *) echo 'Unsupported compression'; exit 1;; + esac + + tar="${tmp}/$(basename "${arg%.*}")" + $cmd -dcf "${arg}" > "${tar}" + + args="${args} ${tar}" + else + args="${args} ${arg}" + fi +done + +python -m namcap ${args} + +rm -rf "${tmp}" Overall this script is in pretty good shape. One big problem however is this: dmcgee@galway ~/projects/namcap (master) $ du -sh /tmp/namcap.* 93M /tmp/namcap.1094 93M /tmp/namcap.1648 248K /tmp/namcap.25917 248K /tmp/namcap.26362 248K /tmp/namcap.26423 248K /tmp/namcap.26526 248K /tmp/namcap.26922
I'm smoking something here, and it isn't making me smart. The above are from namcap itself and not your script...but the trap idea is probably still quite worth it anyway. I'll see if I can't fix namcap in a similar fashion...
I've managed to accumulate a ton of junk in /tmp/ already, because there are several ways to exit the script without the rm getting called. I think what we want to set up is a trap function. makepkg has a bit of a complex one, but it should go something like this:
tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) cleanup() { rm -rf "${tmp}" }
trap 'cleanup' 0
And then completely remove the rm -rf at the end, as it will happen in any exit condition.
diff --git a/namcap.py b/namcap.py index 19c6ceb..18dfbc8 100755 --- a/namcap.py +++ b/namcap.py @@ -228,7 +228,7 @@ for package in packages: print "Error: Problem reading " + package usage()
- if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': I took care of this one a bit differently tonight, and hopefully a bit smarter from a python point of view: http://projects.archlinux.org/namcap.git/commit/?id=0e4a9cbe0be95f061effac4e...
process_realpackage(package, active_modules) elif package[-8:] == 'PKGBUILD': process_pkgbuild(package, active_modules) diff --git a/pacman.py b/pacman.py index e4b6cf3..c56d399 100644 --- a/pacman.py +++ b/pacman.py @@ -66,7 +66,7 @@ def load(package, root=None): if root == None: root = pacmandb # We know it's a local package - if package[-7:] == '.tar.gz': + if package[-4:] == '.tar': pkgtar = tarfile.open(package, "r") if not pkgtar: return None diff --git a/setup.py b/setup.py index 66ee2ba..754ee72 100755 --- a/setup.py +++ b/setup.py @@ -10,6 +10,6 @@ setup(name="namcap", description="Pacman package analyzer", author="Jason Chu", author_email="jason@archlinux.org", - py_modules=["pacman"], packages=["Namcap"], scripts=["namcap.py", 'parsepkgbuild'],data_files =DATAFILES) + py_modules=["pacman", "namcap"], packages=["Namcap"], scripts=['parsepkgbuild', 'namcap'],data_files =DATAFILES) Looks fine to me, although I touched up the setup.py file tonight so
So you can omit this change and the below one in pacman.py from the patch resubmit. these are on seperate lines like the rest of the data was: http://projects.archlinux.org/namcap.git/commit/?id=de1d5e9dfad8d79fda6903b1...
-Dan
Signed-off-by: Pierre Schmitz <pierre@archlinux.de> --- namcap | 29 +++++++++++++++++++++++++++++ setup.py | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 namcap diff --git a/namcap b/namcap new file mode 100755 index 0000000..e95fcdd --- /dev/null +++ b/namcap @@ -0,0 +1,29 @@ +#!/bin/bash + +args='' +tmp=$(mktemp -d /tmp/namcap.XXXXXXXXXX) +cleanup() { + rm -rf "${tmp}" +} +trap 'cleanup' 0 + +for arg in "${@}"; do + if echo "${arg}" | grep -q -E "^.+\.pkg\.tar\..+$" && [ -f "${arg}" ]; then + + case "${arg##*.}" in + gz|z|Z) cmd='gzip' ;; + bz2|bz) cmd='bzip2' ;; + xz) cmd='xz' ;; + *) echo 'Unsupported compression'; exit 1;; + esac + + tar="${tmp}/$(basename "${arg%.*}")" + $cmd -dcf "${arg}" > "${tar}" + + args="${args} ${tar}" + else + args="${args} ${arg}" + fi +done + +python -m namcap ${args} diff --git a/setup.py b/setup.py index 8a6c862..bab1f65 100755 --- a/setup.py +++ b/setup.py @@ -10,9 +10,9 @@ setup(name="namcap", description="Pacman package analyzer", author="Jason Chu", author_email="jason@archlinux.org", - py_modules=["pacman"], + py_modules=["pacman", "namcap"], packages=["Namcap"], - scripts=["namcap.py", 'parsepkgbuild'], + scripts=["namcap", 'parsepkgbuild'], data_files=DATAFILES) # vim: set ts=4 sw=4 noet: -- 1.7.0
participants (2)
-
Dan McGee
-
Pierre Schmitz