@ -28,7 +28,7 @@ except ImportError:
import os . path
from asterisk_processor import AsteriskProcessor
from optparse import Option Parser
from argparse import ArgumentParser as Arg Parser
from swagger_model import ResourceListing
from transform import Transform
@ -42,55 +42,61 @@ def rel(file):
"""
return os . path . join ( TOPDIR , file )
WIKI_PREFIX = ' Asterisk 21 '
API_TRANSFORMS = [
Transform ( rel ( ' api.wiki.mustache ' ) ,
' doc/rest-api/ %s {{ name_title}} REST API.wiki ' % WIKI_PREFIX ) ,
Transform ( rel ( ' res_ari_resource.c.mustache ' ) ,
' res/res_ari_ {{ c_name}}.c ' ) ,
Transform ( rel ( ' ari_resource.h.mustache ' ) ,
' res/ari/resource_ {{ c_name}}.h ' ) ,
Transform ( rel ( ' ari_resource.c.mustache ' ) ,
' res/ari/resource_ {{ c_name}}.c ' , overwrite = False ) ,
]
RESOURCES_TRANSFORMS = [
Transform ( rel ( ' models.wiki.mustache ' ) ,
' doc/rest-api/ %s REST Data Models.wiki ' % WIKI_PREFIX ) ,
Transform ( rel ( ' ari.make.mustache ' ) , ' res/ari.make ' ) ,
Transform ( rel ( ' ari_model_validators.h.mustache ' ) ,
' res/ari/ari_model_validators.h ' ) ,
Transform ( rel ( ' ari_model_validators.c.mustache ' ) ,
' res/ari/ari_model_validators.c ' ) ,
]
def main ( argv ) :
parser = OptionParser ( usage = " Usage % prog [resources.json] [destdir] " )
( options , args ) = parser . parse_args ( argv )
if len ( args ) != 3 :
parser . error ( " Wrong number of arguments " )
description = (
' Command line utility to export ARI documentation to markdown '
)
parser = ArgParser ( description = description )
parser . add_argument ( ' --resources ' , type = str , default = " rest-api/resources.json " ,
help = " resources.json file to process " , required = False )
parser . add_argument ( ' --source-dir ' , type = str , default = " . " ,
help = " Asterisk source directory " , required = False )
parser . add_argument ( ' --dest-dir ' , type = str , default = " doc/rest-api " ,
help = " Destination directory " , required = False )
parser . add_argument ( ' --docs-prefix ' , type = str , default = " ../ " ,
help = " Prefix to apply to links " , required = False )
args = parser . parse_args ( )
if not args :
return
source = args [ 1 ]
dest_dir = args [ 2 ]
renderer = pystache . Renderer ( search_dirs = [ TOPDIR ] , missing_tags = ' strict ' )
processor = AsteriskProcessor ( wiki_prefix = WIKI_PREFIX )
processor = AsteriskProcessor ( wiki_prefix = args . docs_prefix )
API_TRANSFORMS = [
Transform ( rel ( ' api.wiki.mustache ' ) ,
' %s / {{ name_title}}_REST_API.md ' % args . dest_dir ) ,
Transform ( rel ( ' res_ari_resource.c.mustache ' ) ,
' res/res_ari_ {{ c_name}}.c ' ) ,
Transform ( rel ( ' ari_resource.h.mustache ' ) ,
' res/ari/resource_ {{ c_name}}.h ' ) ,
Transform ( rel ( ' ari_resource.c.mustache ' ) ,
' res/ari/resource_ {{ c_name}}.c ' , overwrite = False ) ,
]
RESOURCES_TRANSFORMS = [
Transform ( rel ( ' models.wiki.mustache ' ) ,
' %s /_Asterisk_REST_Data_Models.md ' % args . dest_dir ) ,
Transform ( rel ( ' ari.make.mustache ' ) , ' res/ari.make ' ) ,
Transform ( rel ( ' ari_model_validators.h.mustache ' ) ,
' res/ari/ari_model_validators.h ' ) ,
Transform ( rel ( ' ari_model_validators.c.mustache ' ) ,
' res/ari/ari_model_validators.c ' ) ,
]
# Build the models
base_dir = os . path . dirname ( source )
resources = ResourceListing ( ) . load_file ( source , processor )
base_dir = os . path . dirname ( args. re sources )
resources = ResourceListing ( ) . load_file ( args. re sources , processor )
for api in resources . apis :
api . load_api_declaration ( base_dir , processor )
# Render the templates
for api in resources . apis :
for transform in API_TRANSFORMS :
transform . render ( renderer , api , dest_dir )
transform . render ( renderer , api , args. source _dir)
for transform in RESOURCES_TRANSFORMS :
transform . render ( renderer , resources , dest_dir )
transform . render ( renderer , resources , args. source _dir)
if __name__ == " __main__ " :
sys . exit ( main ( sys . argv ) or 0 )