diff --git a/Makefile b/Makefile index 9f54140ccb..f1e22452de 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: json-to-xml clean help api-deps rebuild-apis +.PHONY: json-to-xml clean help api-deps rebuild-apis license .SUFFIXES: include Makefile.helpers @@ -7,14 +7,14 @@ VENV := virtualenv VENV_DIR := .pyenv PYTHON := $(VENV_DIR)/bin/python PIP := $(VENV_DIR)/bin/pip -MAKO_RENDER := ./etc/bin/mako-render +MAKO_RENDER := etc/bin/mako-render TPL := $(PYTHON) $(MAKO_RENDER) MAKO_SRC = src/mako API_DEPS_TPL = $(MAKO_SRC)/deps.mako API_DEPS = .api.deps -API_SHARED_INFO = ./etc/api/shared.yaml -API_JSON_FILES = $(shell find ./etc -type f -name '*-api.json') +API_SHARED_INFO = etc/api/shared.yaml +API_JSON_FILES = $(shell find etc -type f -name '*-api.json') MAKO_LIB_DIR = $(MAKO_SRC)/lib MAKO_LIB_FILES = $(shell find $(MAKO_LIB_DIR) -type f -name '*.mako' -or -name '*.py') @@ -26,6 +26,7 @@ help: $(info api-deps - generate a file to tell make what API file dependencies will be) $(info rebuild-apis - clear out all generated apis, and regenerate them) $(info help-api - show all api targets to build individually) + $(info license - regenerate the main license file) $(PYTHON): virtualenv $(VENV_DIR) @@ -40,6 +41,11 @@ api-deps: $(API_DEPS) include $(API_DEPS) +LICENSE.md: $(MAKO_SRC)/LICENSE.md.mako $(API_SHARED_INFO) + $(TPL) -io $<=$@ --data-files $(API_SHARED_INFO) + +license: LICENSE.md + rebuild-apis: clean-apis apis clean: clean-apis diff --git a/etc/api/shared.yaml b/etc/api/shared.yaml index fed2e4156b..e82eb9e638 100644 --- a/etc/api/shared.yaml +++ b/etc/api/shared.yaml @@ -16,6 +16,7 @@ api: templates: # all output directories are relative to the one set for the respective API - source: README.md + - source: LICENSE.md - source: cargo.toml # output_dir: optional - not there if unset cargo: @@ -23,7 +24,14 @@ cargo: repo_base_url: https://github.com/Byron/google-apis-rs doc_base_url: http://byron.github.io/google-apis-rs authors: + # don't forget to possibly add them to copyright authors - Sebastian Thiel keywords: [google, protocol, web, api] # All APIs should live in the same repository repository_url: https://github.com/Byron/google-apis-rs + +copyright: + # should at some point be 2015-2016 ... + years: '2015' + authors: + - 'Sebastian Thiel' diff --git a/etc/bin/mako-render b/etc/bin/mako-render index 2150eaf5fb..84b3a99c67 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -308,13 +308,14 @@ def cmdline(argv=None): try: result = template.render(**data_converted) if output_file: - if not os.path.isdir(dirname(output_file)): - os.makedirs(dirname(output_file)) + dir = dirname(output_file) + if dir and not os.path.isdir(dir): + os.makedirs(dir) fh = open(output_file, "wb") - fh.write(result) + fh.write(result.encode('utf-8')) fh.close() else: - print(result) + print(result.encode('utf-8')) except: _exit() # end for each input file diff --git a/src/mako/LICENSE.md.mako b/src/mako/LICENSE.md.mako new file mode 100644 index 0000000000..85eee7a881 --- /dev/null +++ b/src/mako/LICENSE.md.mako @@ -0,0 +1,26 @@ +## -*- coding: utf-8 -*- +The MIT License (MIT) +===================== + +Copyright © `${copyright.years}` ${', '.join("`%s`" % a for a in copyright.authors)} + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the “Software”), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/mako/README.md.mako b/src/mako/README.md.mako new file mode 100644 index 0000000000..81758ca48a --- /dev/null +++ b/src/mako/README.md.mako @@ -0,0 +1,5 @@ +<%! import util %>\ +<%namespace name="lib" file="lib/lib.mako"/>\ +The `${util.library_name(name, version)}` library allows access to all features of *${canonicalName}*. + +<%lib:docs /> \ No newline at end of file diff --git a/src/mako/deps.mako b/src/mako/deps.mako index a1bd62ebff..4dc6e7ceec 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -1,15 +1,13 @@ # DO NOT EDIT ! # This file was generated automatically by '${self.uri}' # DO NOT EDIT ! -## ${util.to_api_version('v3')} -## here <%util:to_api_version v="v3"/> + <%api_info=[]%>\ % for a in api.list: <% import util - version = util.to_api_version(a.version) - gen_root = directories.output + '/' + a.name + version - api_name = a.name + version + gen_root = directories.output + '/' + a.name + util.to_api_version(a.version) + api_name = util.library_name(a.name, a.version) api_clean = api_name + '-clean' # source, destination of individual output files sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + i.get('output_dir', '') + '/' + i.source) diff --git a/src/mako/lib/lib.mako b/src/mako/lib/lib.mako new file mode 100644 index 0000000000..788120fea4 --- /dev/null +++ b/src/mako/lib/lib.mako @@ -0,0 +1,3 @@ +<%def name="docs()">\ +TODO: Library level fully fledged documentation, incuding **summary** and **usage**. + \ No newline at end of file diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index e871dc52ea..a069146c98 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -11,3 +11,7 @@ def rdc(s): def to_api_version(v): assert len(v) >= 2 and v[0] == 'v' return v[1:] + +# build a full library name (non-canonical) +def library_name(name, version): + return name + to_api_version(version)