diff --git a/.gitignore b/.gitignore index 2d0cfb0716..689fed0fd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .pyenv +generated/ target .api.deps Cargo.lock diff --git a/Makefile b/Makefile index 94ed3ba6c9..d836a2f89e 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ $(PYTHON): $(MAKO_RENDER): $(PYTHON) $(API_DEPS): $(API_SHARED_INFO) $(API_DEPS_TPL) $(MAKO_RENDER) - $(TPL) --data-files $(API_SHARED_INFO) --var SHARED_INFO_FILE=$(API_SHARED_INFO) $(API_DEPS_TPL) > $@ + $(TPL) -io $(API_DEPS_TPL) --data-files $(API_SHARED_INFO) > $@ api-deps: $(API_DEPS) diff --git a/etc/api/shared.yaml b/etc/api/shared.yaml index 7980e44b26..93f404d589 100644 --- a/etc/api/shared.yaml +++ b/etc/api/shared.yaml @@ -6,6 +6,8 @@ directories: common: ../ # where are all the API meta files api_base: ./etc/api + # all mako source files + mako_src: ./src/mako api: list: - name: youtube diff --git a/etc/bin/mako-render b/etc/bin/mako-render index bcb82a1ce4..e4d62f1a59 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -257,47 +257,64 @@ def _exit(): def cmdline(argv=None): - parser = ArgumentParser("usage: %prog [FILENAME]") - parser.add_argument("--var", default=[], action="append", - help="variable (can be used multiple times, use name=value)") - parser.add_argument("--data-files", default=[], action="append", + parser = ArgumentParser("mako-render") + parser.add_argument("--var", nargs="*", default=[], + help="variable (can be used multiple times, use NAME=VALUE)") + parser.add_argument("--data-files", nargs="*", default=[], help="data file (can be used multiple times, use path[=namespace])") - parser.add_argument("--template-dir", default=[], action="append", + parser.add_argument("--template-dir", nargs="*", default=[], help="Directory to use for template lookup (multiple " "directories may be provided). If not given then if the " "template is read from stdin, the value defaults to be " "the current directory, otherwise it defaults to be the " "parent directory of the file provided.") - parser.add_argument('input', nargs='?', default='-') + parser.add_argument('-io', nargs="+", + help="input and ouptut pairs. can be used multiple times, use TEMPLATE_FILE_IN=[OUTPUT_FILE])") options = parser.parse_args(argv) - if options.input == '-': - lookup_dirs = options.template_dir or ["."] - lookup = TemplateLookup(lookup_dirs) - try: - template = Template(sys.stdin.read(), lookup=lookup) - except: - _exit() - else: - filename = options.input - if not isfile(filename): - raise SystemExit("error: can't find %s" % filename) - lookup_dirs = options.template_dir or [dirname(filename)] - lookup = TemplateLookup(lookup_dirs) - try: - template = Template(filename=filename, lookup=lookup) - except: - _exit() + if len(options.io) == 0: + options.io.append('-') + options.io = [varsplit(v) for v in options.io] datafiles = [varsplit(var) for var in options.data_files] data = load_data(datafiles) - data = dict((k, DictObject(v)) for k, v in data.items()) - data.update(dict([varsplit(var) for var in options.var])) - - try: - print(template.render(**data)) - except: - _exit() + data_converted = dict((k, DictObject(v)) for k, v in data.items() if isinstance(v, dict)) + data_converted.update((k, v) for k, v in data.items() if not isinstance(v, dict)) + data_converted.update(dict([varsplit(var) for var in options.var])) + del data + + seen_stdin = False + for input_file, output_file in options.io: + if input_file == '-': + assert not seen_stdin, "STDIN (-) can only be named once" + seen_stdin = True + lookup_dirs = options.template_dir or ["."] + lookup = TemplateLookup(lookup_dirs) + try: + template = Template(sys.stdin.read(), lookup=lookup) + except: + _exit() + else: + if not isfile(input_file): + raise SystemExit("error: can't find %s" % input_file) + lookup_dirs = options.template_dir or [dirname(input_file)] + lookup = TemplateLookup(lookup_dirs) + try: + template = Template(filename=input_file, lookup=lookup) + except: + _exit() + + try: + result = template.render(**data_converted) + if output_file: + fh = open(output_file, "wb") + fh.write(result) + fh.close() + else: + print(result) + except: + _exit() + # end for each input file if __name__ == "__main__": diff --git a/src/mako/cargo.toml.mako b/src/mako/cargo.toml.mako new file mode 100644 index 0000000000..6344f34991 --- /dev/null +++ b/src/mako/cargo.toml.mako @@ -0,0 +1,21 @@ +[package] + +name = "youtube3-dev" +version = "0.0.1" +authors = ["Sebastian Thiel "] +description = "A library to facilitate interacting with your youtube account" +repository = "https://github.com/Byron/youtube-rs" +license = "MIT" +keywords = ["youtube", "google", "protocol"] + +[dependencies] +# Just to get hyper to work ! +openssl = "= 0.4.3" +# Just to get hyper to work ! +cookie = "= 0.1.13" +hyper = "*" +rustc-serialize = "*" +yup-oauth2 = "*" + +[dev-dependencies] +yup-hyper-mock = "*" diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 544707d499..32acf2556c 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -10,9 +10,12 @@ api_clean = api_name + '-clean' api_info.append((api_name, api_clean, gen_root)) %>\ -${gen_root}: ${directories.api_base}/${a.name}/${a.version}/${a.name}-api.json ${SHARED_INFO_FILE} +${gen_root}: ${directories.api_base}/${a.name}/${a.version}/${a.name}-api.json $(API_SHARED_INFO) + @mkdir -p $@ + $(TPL) -io ${directories.mako_src}/cargo.toml.mako=$@/cargo.toml --data-files $^ + ${api_name}: ${gen_root} - @echo TODO ${api_name} command + ${api_clean}: -rm -Rf ${gen_root} % endfor