2 # Asterisk -- An open source telephony toolkit.
4 # Copyright (C) 2013, Digium, Inc.
6 # David M. Lee, II <dlee@digium.com>
8 # See http://www.asterisk.org for more information about
9 # the Asterisk project. Please do not directly contact
10 # any of the maintainers of this project for assistance;
11 # the project provides a web site, mailing lists and IRC
12 # channels for your use.
14 # This program is free software, distributed under the terms of
15 # the GNU General Public License Version 2. See the LICENSE file
16 # at the top of the source tree.
24 print >> sys.stderr, "Pystache required. Please sudo pip install pystache."
29 from asterisk_processor import AsteriskProcessor
30 from optparse import OptionParser
31 from swagger_model import *
32 from transform import Transform
34 TOPDIR = os.path.dirname(os.path.abspath(__file__))
38 """Helper to get a file relative to the script's directory
40 @parm file: Relative file path.
42 return os.path.join(TOPDIR, file)
44 WIKI_PREFIX = 'Asterisk 13'
47 Transform(rel('api.wiki.mustache'),
48 'doc/rest-api/%s {{name_title}} REST API.wiki' % WIKI_PREFIX),
49 Transform(rel('res_ari_resource.c.mustache'),
50 'res/res_ari_{{c_name}}.c'),
51 Transform(rel('ari_resource.h.mustache'),
52 'res/ari/resource_{{c_name}}.h'),
53 Transform(rel('ari_resource.c.mustache'),
54 'res/ari/resource_{{c_name}}.c', overwrite=False),
57 RESOURCES_TRANSFORMS = [
58 Transform(rel('models.wiki.mustache'),
59 'doc/rest-api/%s REST Data Models.wiki' % WIKI_PREFIX),
60 Transform(rel('ari.make.mustache'), 'res/ari.make'),
61 Transform(rel('ari_model_validators.h.mustache'),
62 'res/ari/ari_model_validators.h'),
63 Transform(rel('ari_model_validators.c.mustache'),
64 'res/ari/ari_model_validators.c'),
69 parser = OptionParser(usage="Usage %prog [resources.json] [destdir]")
71 (options, args) = parser.parse_args(argv)
74 parser.error("Wrong number of arguments")
78 renderer = pystache.Renderer(search_dirs=[TOPDIR], missing_tags='strict')
79 processor = AsteriskProcessor(wiki_prefix=WIKI_PREFIX)
82 base_dir = os.path.dirname(source)
83 resources = ResourceListing().load_file(source, processor)
84 for api in resources.apis:
85 api.load_api_declaration(base_dir, processor)
87 # Render the templates
88 for api in resources.apis:
89 for transform in API_TRANSFORMS:
90 transform.render(renderer, api, dest_dir)
91 for transform in RESOURCES_TRANSFORMS:
92 transform.render(renderer, resources, dest_dir)
94 if __name__ == "__main__":
95 sys.exit(main(sys.argv) or 0)