changeset 0:7a76836b50a7

initial (non-working) commit to makeitso
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 02 Nov 2010 17:56:14 -0700
parents
children c2f8464e0395
files example.txt makeitso/__init__.py makeitso/main.py setup.py
diffstat 4 files changed, 87 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example.txt	Tue Nov 02 17:56:14 2010 -0700
@@ -0,0 +1,3 @@
+#!/usr/bin/env makeitso
+
+Hello {{name}}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/makeitso/__init__.py	Tue Nov 02 17:56:14 2010 -0700
@@ -0,0 +1,1 @@
+#
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/makeitso/main.py	Tue Nov 02 17:56:14 2010 -0700
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+"""
+filesystem template interpreter
+"""
+
+import os
+import subprocess
+import sys
+
+from optparse import OptionParser
+from tempita import Template
+
+def call(command, *args, **kw):
+    code = subprocess.call(command, *args, **kw)
+    if code:
+        if isinstance(command, basestring):
+            cmdstr = command
+        else:
+            cmdstr = ' '.join(command)
+        raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code))
+
+def template_variables(template):
+    """return the variables needed for a template"""
+    raise NotImplementedError
+
+def main(args=sys.argv[1:]):
+
+    # create option parser
+    usage = '%prog [options]'
+    parser = OptionParser(usage, description=__doc__)
+    parser.add_option('--variables', dest='variables',
+                      help='print the variables in a template')
+    options, args = parser.parse_args(args)
+
+    # template variables
+    variables = {}
+    _vars = []
+    _args = []
+    for arg in args:
+        if '=' in arg:
+            key, value = arg.split('=')
+            variables[key] = value
+        else:
+            _args.append(arg)
+    args = _args
+
+    # get the content
+    content = sys.stdin.read()
+    template = Template(content)
+    print template.interpolate(**variables)
+        
+
+if __name__ == '__main__':
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Tue Nov 02 17:56:14 2010 -0700
@@ -0,0 +1,29 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.0'
+
+setup(name='MakeItSo',
+      version=version,
+      description='filesystem template interpreter',
+      long_description="""\
+""",
+      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      keywords='',
+      author='Jeff Hammel',
+      author_email='jhammel@mozilla.com',
+      url='http://k0s.org/',
+      license='',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          # -*- Extra requirements: -*-
+        'tempita'
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [console_scripts]
+      makeitso = makeitso.main:main
+      """,
+      )