Commits

Michal Dvorak committed 889ac9f

First version of recipe

Comments (0)

Files changed (3)

+=====================
+Setup Buildout Recipe
+=====================
+
+TODO
+#!/usr/bin/env python
+import os
+from setuptools import setup, find_packages
+
+def read(fname):
+    return open(os.path.join(os.path.dirname(__file__), fname)).read()
+
+setup(
+    name="setup-recipe",
+    version='0.1',
+    entry_points = {'zc.buildout': ['default = setup_recipe:Recipe']},
+    url='https://bitbucket.org/mdvorak/setup-recipe',
+    author='Michal Dvorak',
+    author_email='mikee@mdvorak.org',
+    description='TODO',
+    long_description=read('README.txt'),
+    packages=find_packages(),
+    classifiers=[
+        'Development Status :: 2 - Pre-Alpha',
+        'Intended Audience :: Developers',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+    ],
+)

setup_recipe/__init__.py

+import os, re
+
+class Recipe(object):
+    def __init__(self, buildout, name, options):
+        self.buildout, self.name, self.options = buildout, name, options
+
+        self.develop = []
+        for dir in re.split(r'\s+', self.options['develop']):
+            self.develop.append(os.path.abspath(dir))
+
+    def install(self):
+        bin = self.buildout['python']['bin-directory']
+        python = self.buildout['python']['executable']
+        script = os.path.join(bin, self.name)
+        interpreter = os.path.join(bin, self.options['use-interpreter'])
+        command = self.options.get('command')
+
+        f = open(script, 'w')
+        f.write('#!' + python + '\n')
+
+        f.write('import os, sys\n')
+        f.write('from subprocess import call\n\n')
+
+        f.write('INTERPRETER = "' + interpreter + '"\n')
+        f.write('DEVELOP = ' + str(self.develop) + '\n')
+
+        if command:
+            f.write('CMD = ["' + command + '"]\n')
+        else:
+            f.write('CMD = []\n')
+
+        f.write('ARGS = sys.argv[1:]\n\n')
+
+        f.write('for dir in DEVELOP:\n')
+        f.write('  print "Processing " + dir\n')
+        f.write('  r = call([INTERPRETER, os.path.join(dir, "setup.py")] + CMD + ARGS, cwd=dir) if len(dir) else 0\n')
+        f.write('  if r != 0:\n')
+        f.write('    sys.exit(r)\n\n')
+
+        f.write('print "All OK"\n')
+        f.write('sys.exit(0)\n')
+
+        f.close()
+        os.chmod(script, 0777)
+
+        return script
+
+    update = install