changeset 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
files installfile.py setup.py
diffstat 2 files changed, 86 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/installfile.py	Wed Aug 31 13:49:42 2011 -0700
@@ -0,0 +1,51 @@
+#!/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()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Wed Aug 31 13:49:42 2011 -0700
@@ -0,0 +1,35 @@
+import os
+from setuptools import setup
+
+try:
+    here = os.path.dirname(os.path.abspath(__file__))
+    description = file(os.path.join(here, 'README.txt')).read()
+except IOError:
+    description = None
+
+version = '0.0'
+
+deps = []
+
+setup(name='installfile',
+      version=version,
+      description="install a single file python thingy to sys.path",
+      long_description=description,
+      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      keywords='mozilla',
+      author='Jeff Hammel',
+      author_email='jhammel@mozilla.com',
+      url='http://k0s.org/mozilla/hg/installfile',
+      license='',
+      py_modules=['installfile'],
+      packages=[],
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=deps,
+      entry_points="""
+      # -*- Entry points: -*-
+      [console_scripts]
+      installfile = installfile:main
+      """,
+      )
+