Michele Lacchia avatar Michele Lacchia committed d8143f8

Wheel unpack

Comments (0)

Files changed (2)

wheel/__main__.py

 Wheel command-line utility.
 """
 
+import os
 import baker
 import ed25519ll
 import sys
 
 wb = baker.Baker()
 
-@wb.command()
+@wb.command
 def keygen():
     """Generate a public/private key pair."""
     keypair = ed25519ll.crypto_sign_keypair()
     if sk2 != sk:
         raise Exception("Keyring is broken. Could not retrieve secret key.")
 
-@wb.command()
+@wb.command
 def sign(wheelfile, replace=False):
     """Sign a wheel"""
     import hashlib    
     wf.zipfile.writestr(sig_name, json.dumps(sig, sort_keys=True))
     wf.zipfile.close()
 
-@wb.command()
+@wb.command
 def verify(wheelfile):
     """Verify a wheel."""
     import pprint
     sys.stdout.write("Signatures are internally consistent.\n%s\n" % (
                      pprint.pformat(wheel.signatures.verify(sig),)))
 
-def main():
-    wb.run()
-    
+
+@wb.command(shortopts={'dest': 'd'})
+def unpack(wheelfile, dest='.'):
+    """Unpack a wheel.
+
+    Wheel content will be unpacked to {dest}/{name}-{ver}, where {name}
+    is the package name and {ver} its version.
+
+    :param wheelfile: The path to the wheel.
+    :param dest: Destination directory (default to current directory).
+    """
+    wf = wheel.install.WheelFile(wheelfile)
+    namever = wf.parsed_filename.group('namever')
+    destination = os.path.join(dest, namever)
+    sys.stdout.write("Unpacking to: %s\n" % (destination))
+    wf.zipfile.extractall(destination)
+    wf.zipfile.close()
+
+
 if __name__ == "__main__":
     wb.run()
     \.whl|\.dist-info)$""",
     re.VERBOSE).match
 
+
 class BadWheelFile(ValueError):
     pass
 
+
 class WheelFile(object):
     """Parse wheel-specific attributes from a wheel (.whl) file"""
     WHEEL_INFO = "WHEEL"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.