lukeplant_python / dist.py

#!/usr/bin/python
"""
Creates a source distribution from a project in this tree
"""

import sys
import os
import shutil

THISDIR = os.path.dirname(os.path.abspath(__file__))
TOPDIR = os.path.join(THISDIR, "lukeplant_me_uk")
SETUPDIR = os.path.join(TOPDIR, 'setup')

if len(sys.argv) == 1:
    print """Usage:
    python dist.py <projectname>
    
    where <projectname> is one of:    """
    for d in os.listdir(SETUPDIR):
        if not d.startswith('.') and os.path.isdir(os.path.join(SETUPDIR,d)):
            print "        " + d
    
    print
else:
    d = os.path.join(SETUPDIR, sys.argv[1])
    if not os.path.isdir(d):
        print "'%s' is not a directory in the setup folder." % sys.argv[1]
        exit(1)
    
    manifest_exists = False
    setup_files = ['setup.py', 'MANIFEST.in', 'README', 'AUTHORS']
    for f in setup_files:
        fullpath = os.path.join(d, f)
        if os.path.isfile(fullpath):
            topfile = os.path.join(THISDIR, f)
            if os.path.isfile(topfile):
                os.unlink(topfile)
            shutil.copy(fullpath, topfile)
            if f == "MANIFEST.in":
              manifest_exists = True

    os.chdir(THISDIR)
    if manifest_exists:
        os.system('python setup.py sdist --force-manifest')
    else:
        os.system('python setup.py sdist')
        
    # Cleanup
    for f in setup_files:
        topfile = os.path.join(THISDIR, f)
        if os.path.isfile(topfile):
          os.unlink(topfile)
    if manifest_exists:
        os.unlink('MANIFEST') # created automatically by setup.py
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.