From f9b427652f1e18230bedd232be9a3156cb34c58a Mon Sep 17 00:00:00 2001 From: Michel Alexandre Salim Date: Apr 09 2021 23:30:09 +0000 Subject: Add support for Zip archives If the archive filename ends with `.zip`, use `unzip` rather than `tar` to test and extract. ``` $ opam2rpm camlzip Archive: /home/michel/.cache/opam2rpm/src/camlzip-rel110.zip 61b7f60b29d6a432b303b978a95e9262f27a969e creating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/ inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/.depend inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/.gitignore inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/Changes inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/LICENSE extracting: /home/michel/.cache/opam2rpm/src/camlzip-rel110/META-camlzip inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/META-zip inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/Makefile inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/README inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/gzip.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/gzip.mli creating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/test/ inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/test/Makefile inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/test/minigzip.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/test/minizip.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/test/testzlib.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/zip.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/zip.mli inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/zlib.ml inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/zlib.mli inflating: /home/michel/.cache/opam2rpm/src/camlzip-rel110/zlibstubs.c Upstream license tag LGPL-2.1-or-later translated to LGPLv2+ ``` Fixes #5. Signed-off-by: Michel Alexandre Salim --- diff --git a/opam2rpm/__main__.py b/opam2rpm/__main__.py index 6c6bd0f..740fefa 100644 --- a/opam2rpm/__main__.py +++ b/opam2rpm/__main__.py @@ -181,10 +181,18 @@ def download(url): def unpack(filename): """Unpack a (possibly compressed) tarball.""" parent = os.path.dirname(filename) - subprocess.run(['tar', '-xf', filename, '-C', parent], check=True) + is_zip =filename.endswith('.zip') + if is_zip: + subprocess.run(['unzip', '-x', filename, '-d', parent], check=True) + else: + subprocess.run(['tar', '-xf', filename, '-C', parent], check=True) # Get the name of the unpacked directory - proc = subprocess.run([f'tar -tf {filename} | head -1 | cut -d/ -f1'], + if is_zip: + testcmd = f"unzip -t {filename} | grep 'testing:' | head -n1 | sed -e's/^.*testing: //' | cut -d/ -f1" + else: + testcmd = f'tar -tf {filename} | head -1 | cut -d/ -f1' + proc = subprocess.run([testcmd], capture_output=True, shell=True, text=True, check=True) return os.path.join(parent, proc.stdout.strip()) \