Mercurial > hg > installfile
view installfile.py @ 0:cf72635e9572 default tip
install a file to site-packages
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 31 Aug 2011 13:49:42 -0700 |
parents | |
children |
line wrap: on
line source
#!/usr/bin/env python """ installs python files to sys.path """ import os import shutil import sys import optparse from distutils.sysconfig import get_python_lib def install(path): """install to sys.path""" site_packages = get_python_lib() path = os.path.abspath(path) dirname, filename = os.path.split(path) root, ext = os.path.splitext(filename) pth = file(os.path.join(site_packages, '%s.pth' % root), 'w') pth.write(dirname) pth.close() def main(args=sys.argv[1:]): # parse command line arguments usage = '%prog [options] python_file.py another_python_file.py [...]' # description formatter class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): def format_description(self, description): if description: return description + '\n' else: return '' parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) options, args = parser.parse_args(args) # print usage if no files are given if not args: parser.print_usage() parser.exit() # install the things for python_file in args: install(python_file) if __name__ == '__main__': main()