comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cf72635e9572
1 #!/usr/bin/env python
2
3 """
4 installs python files to sys.path
5 """
6
7 import os
8 import shutil
9 import sys
10 import optparse
11
12 from distutils.sysconfig import get_python_lib
13
14 def install(path):
15 """install to sys.path"""
16 site_packages = get_python_lib()
17 path = os.path.abspath(path)
18 dirname, filename = os.path.split(path)
19 root, ext = os.path.splitext(filename)
20 pth = file(os.path.join(site_packages, '%s.pth' % root), 'w')
21 pth.write(dirname)
22 pth.close()
23
24 def main(args=sys.argv[1:]):
25
26 # parse command line arguments
27 usage = '%prog [options] python_file.py another_python_file.py [...]'
28
29 # description formatter
30 class PlainDescriptionFormatter(optparse.IndentedHelpFormatter):
31 def format_description(self, description):
32 if description:
33 return description + '\n'
34 else:
35 return ''
36
37 parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter())
38 options, args = parser.parse_args(args)
39
40 # print usage if no files are given
41 if not args:
42 parser.print_usage()
43 parser.exit()
44
45 # install the things
46 for python_file in args:
47 install(python_file)
48
49 if __name__ == '__main__':
50 main()
51