Scott Baker | d87c02a | 2018-10-29 16:24:29 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import os |
| 18 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
| 19 | |
| 20 | # These assume a traditional CORD/SEBA hierarchy is checked out using `repo` |
| 21 | |
| 22 | SCRIPT_DIR=os.path.dirname(os.path.realpath(__file__)) |
| 23 | BASE_DIR=os.path.join(SCRIPT_DIR,"..","..","..") |
Matteo Scandolo | e157680 | 2019-03-06 15:23:40 -0800 | [diff] [blame] | 24 | SERVICES_DIR=os.path.join(BASE_DIR,"orchestration","xos-services") |
Scott Baker | d87c02a | 2018-10-29 16:24:29 -0700 | [diff] [blame] | 25 | CORE_XPROTO=os.path.join(BASE_DIR,"orchestration","xos","xos","core","models","core.xproto") |
| 26 | TARGET=os.path.join(BASE_DIR,"orchestration","xos","lib","xos-genx","xosgenx","targets","fieldlist.xtarget") |
| 27 | |
| 28 | def get_all_xproto(): |
| 29 | xprotos=[] |
| 30 | for service_name in os.listdir(SERVICES_DIR): |
| 31 | if service_name.startswith("."): |
| 32 | continue |
| 33 | service_path = os.path.join(SERVICES_DIR, service_name) |
| 34 | if not os.path.isdir(service_path): |
| 35 | continue |
| 36 | models_dir = os.path.join(service_path, "xos", "synchronizer", "models") |
| 37 | if not os.path.isdir(models_dir): |
| 38 | continue |
| 39 | for xproto_name in os.listdir(models_dir): |
| 40 | if xproto_name.startswith("."): |
| 41 | continue |
| 42 | if not xproto_name.endswith(".xproto"): |
| 43 | continue |
| 44 | xproto_pathname = os.path.join(models_dir, xproto_name) |
| 45 | xprotos.append(xproto_pathname) |
| 46 | return xprotos |
| 47 | |
| 48 | xprotos = get_all_xproto() + [CORE_XPROTO] |
| 49 | args = XOSProcessorArgs(files=xprotos, |
| 50 | target=TARGET, |
| 51 | verbosity=1 |
| 52 | ) |
| 53 | output = XOSProcessor.process(args) |