3 # Copyright 2016 Einar Nilsen-Nygaard [https://gist.github.com/einarnn]
4 # Update Copyright 2021 highstreet technologies GmbH
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # The script renames yang modules with filename with schema "<module-name>.yang"
19 # to filenames with schema name "<module-name>@<revision>.yang" as used by
20 # netconf-server and netconf-client impelementstions to distingligh the
21 # yang modules already by its filename avoiding parsing the yang module getting
24 from pyang import repository, context
28 parser = argparse.ArgumentParser(description='rename a list of yang model files by the revision information')
29 parser.add_argument('yang_files', type=str, nargs='+',
30 help='list of yang files')
31 args = parser.parse_args()
33 repos = repository.FileRepository(".")
34 for fname in args.yang_files:
35 targ_module = os.path.basename(fname).split(".")[0]
36 if '@' in targ_module:
37 targ_module = targ_module.split('@')[0]
38 ctx = context.Context(repos)
41 ctx.add_module(fname, text)
42 for ((m,r), v) in ctx.modules.items():
44 targ_dir = os.path.dirname(fname)
46 os.rename(fname,targ_module+'@'+r+'.yang')
48 os.rename(fname,targ_dir+'/'+targ_module+'@'+r+'.yang')