Commits

Stan Seibert  committed ce871f6

Create package directories with -p option

  • Participants
  • Parent commits 54326fa

Comments (0)

Files changed (1)

File shrinkwrap/command.py

 import tempfile
 import shutil
 import subprocess
-
+import optparse
 
 def activate():
     VIRTUAL_ENV = os.environ['VIRTUAL_ENV']
 
 
 def createpkg(argv):
+    parser = optparse.OptionParser()
+    parser.add_option('-p', '--package-dir', dest='package_dir', default=None,
+        help='Output packages into directory hierarchy at this location')
+
+    options, args = parser.parse_args(argv)
+
     orig_work_dir = os.getcwd()
+    if options.package_dir is not None:
+        package_dir = os.path.realpath(options.package_dir)
+    else:
+        package_dir = None
 
-    for setup_filename in argv:
+    for setup_filename in args:
         print 'Generating package for', setup_filename
         temp_dir = None
         try:
                 raise Exception('Multiple files were generated by setup.py sdist')
             else:
                 tar = file_list[0]
-                target = os.path.join(orig_work_dir, os.path.basename(tar))
+                tar_basename = os.path.basename(tar)
+                if package_dir is None:
+                    target = os.path.join(orig_work_dir, tar_basename)
+                else:
+                    last_dash = tar_basename.rfind('-')
+                    package_name = tar_basename[:last_dash]
+                    package_subdir = os.path.join(package_dir, package_name)
+                    if not os.path.exists(package_subdir):
+                        os.makedirs(package_subdir)
+                    target = os.path.join(package_subdir, tar_basename)
                 shutil.copy(tar, target)
         finally:
             if temp_dir is not None: