4 # ============LICENSE_START=======================================================
6 # ================================================================================
7 # Copyright (C) 2018 AT&T Intellectual Property. All rights
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
28 # Convert word from foo-bar to FooBar
29 # words begining with a digit will be converted to _digit
34 s = s[0].upper() + s[1:]
35 return re.sub(r'(?!^)-([a-zA-Z])', lambda m: m.group(1).upper(), s)
42 print 'yang2props.py <input yang> <output properties>'
45 with open(sys.argv[1], "r") as ins:
47 # if we see a leaf save the name for later
49 match = re.search(r'leaf (\S+)', line)
53 # if we see enum convert the value to enum format and see if it changed
54 # if the value is different write a property entry
56 match = re.search(r'enum "(\S+)";', line)
61 # see if converting to enum changed the string
63 property = "yang."+leaf+"."+enum+"="+val
64 if property not in li:
69 fo = open(sys.argv[2], "wb")
70 fo.write("# yang conversion properties \n")
71 fo.write("# used to convert Enum back to the original yang value \n")
72 fo.write("\n".join(li))