-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathdevice_api.py
52 lines (42 loc) · 1.61 KB
/
device_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
from TypeGenerator import TypeGenerator
import pprint
import re
import os
def write(gen_file, gen_str):
gen_file.write("%s\n" %(gen_str))
#end write
class DeviceApiGenerator(object):
def __init__(self, xsd_parser, xsd_root, ident_dict, metadata_dict):
self._xsd_parser = xsd_parser
self._xsd_root = xsd_root
self._ident_dict = ident_dict
self._metadata_dict = metadata_dict
# [<tenant>,...]")
self._FQ_NAME_TENANT_IDX = 0
#end __init__
def Generate(self, gen_filepath_pfx):
# Grab directory where to generate (if not locally)
gen_filename_pfx = os.path.basename(gen_filepath_pfx)
gendir = os.path.dirname(gen_filepath_pfx)
if gendir:
gendir = gendir + '/'
# class defn used by both rest-api client and server
# create a package for autogenerated code
self._generate_package(gendir)
# These produce classes/files per type
self._generate_common_classes(gen_filepath_pfx)
#end Generate
def _generate_package(self, gendir):
gen_file = self._xsd_parser.makeFile(gendir + "__init__.py")
#end _generate_package
def _generate_common_classes(self, gen_filepath_pfx):
# XSD types to python classes
type_genr = TypeGenerator(self._xsd_parser)
type_genr.setLanguage('py')
type_genr.generate(self._xsd_root, None, gen_filepath_pfx + "_xsd.py",
genStandAlone = False, openapi_dict={})
#end _generate_common_classes
#end class DeviceApiGenerator