# HG changeset patch # User Jeff Hammel # Date 1292303019 28800 # Node ID 044ac9e0b29ce1a42915e0c74537c4a445840dae # Parent fbf19940fa97612496a3d6b9d2685223974af8cd add a non-working example with an include clause diff -r fbf19940fa97 -r 044ac9e0b29c examples/include-example.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/include-example.txt Mon Dec 13 21:03:39 2010 -0800 @@ -0,0 +1,5 @@ +#!/usr/bin/env makeitso + +I am including a file: + +{{include(example.txt)}} diff -r fbf19940fa97 -r 044ac9e0b29c makeitso/makeitso.py --- a/makeitso/makeitso.py Tue Nov 30 09:23:46 2010 -0800 +++ b/makeitso/makeitso.py Mon Dec 13 21:03:39 2010 -0800 @@ -21,7 +21,6 @@ tempita_location = 'http://bitbucket.org/ianb/tempita/raw-file/tip/tempita/' def cleanup(): - # remove temporary net module directory if 'tempdir' in globals(): shutil.remove(tempdir) @@ -80,6 +79,19 @@ cmdstr = ' '.join(command) raise SystemExit("Command `%s` exited with code %d" % (cmdstr, code)) +def base_uri(uri): + if '://' in uri: + return 'uri'.rsplit('/', 1)[0] + return os.path.dirname(os.path.abspath('me')) + +def include(uri): + f, headers = urllib.urlretrieve(uri) + return file(f).read() + +### functions for variables + +defaults = {'include': include} + def get_missing(name_error): """ This is a horrible hack because python doesn't do the proper thing @@ -126,7 +138,7 @@ if shebang_re.match(content): content = os.linesep.join(content.splitlines()[1:]) - variables = variables or {} + variables = variables or defaults.copy() template = tempita.Template(content) missing = missing_variables(template, variables) if missing: @@ -180,7 +192,7 @@ return # template variables - variables = {} + variables = defaults.copy() _vars = [] _args = [] for arg in args: @@ -197,15 +209,16 @@ for arg in args: print invocation(arg, **variables) else: - print invocation('[URL]', **variables) + print invocation('[URI]', **variables) return # get the content if args: for arg in args: - f, headers = urllib.urlretrieve(arg) - content = file(f).read() - print substitute(content, variables=variables) + var_copy = variables.copy() + var_copy['here'] = base_uri(arg) + content = include(arg) + print substitute(content, variables=var_copy) else: content = sys.stdin.read() print substitute(content, variables=variables)