diff options
author | Bruno Sakoto <bruno.sakoto@bell.ca> | 2022-03-03 23:28:44 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-03-03 23:28:44 +0000 |
commit | df4ca87b955e54180046b25294913b5fca5a1270 (patch) | |
tree | 31049954c5d5464fc8152fe3daf3344f066a557f /cps-ri/src/main/resources/yangResourceCsvGenerator.py | |
parent | 41334d39a359adf72dca034eb7ddd7536d04b9c3 (diff) | |
parent | 0cbc448573409a43eb3bf7b4c9cb49d418a4c999 (diff) |
Merge "Update dmi-registry yang to support cmHandle State"
Diffstat (limited to 'cps-ri/src/main/resources/yangResourceCsvGenerator.py')
-rw-r--r-- | cps-ri/src/main/resources/yangResourceCsvGenerator.py | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/cps-ri/src/main/resources/yangResourceCsvGenerator.py b/cps-ri/src/main/resources/yangResourceCsvGenerator.py index 9a4077bbd2..3a076d4378 100644 --- a/cps-ri/src/main/resources/yangResourceCsvGenerator.py +++ b/cps-ri/src/main/resources/yangResourceCsvGenerator.py @@ -18,21 +18,49 @@ import csv +import datetime import hashlib import sys +import re yang_source = '' checksum = '' +regexForModuleName = '(?<=module)(.*)(?={)' +regexForRevision = '(?<=revision)(.*)(?={)' -for yang_source in sys.argv[1:]: - checksum = hashlib.sha256(str(yang_source).encode()).hexdigest() +def main(): + for yang_source in sys.argv[1:]: + checksum = hashlib.sha256(str(yang_source).encode()).hexdigest() -with open('changelog/db/changes/data/yang-models/' + yang_source + '.yang') as content: - dmiRegistry = content.read() + with open('changelog/db/changes/data/yang-models/' + yang_source + '.yang', 'r') as content: + dmiRegistry = content.read() -# open the file in the write mode -with open('changelog/db/changes/data/dmi/generated-csv/generated_yang_resource_' + yang_source + '.csv', 'w', newline='') \ - as file: - writer = csv.writer(file, delimiter='|') - writer.writerow(["name", "content", "checksum"]) - writer.writerow([yang_source + '.yang', dmiRegistry, checksum]) + try: + latestRevision = re.search(regexForRevision, dmiRegistry).group(0).replace('\"','').strip() + except: + print("ERROR IN in yangResourceCsvGenerator.py: Unable to find revision for " + yang_source + '.yang') + + try: + module_name = re.search(regexForModuleName, dmiRegistry).group(0).strip() + except: + print("ERROR IN in yangResourceCsvGenerator.py: Unable to find module name for " + yang_source + '.yang') + + #If true, file was created after module_name and revision columns were added to yang-resources table + writeWithModuleNameAndRevision = yang_source != 'dmi-registry@2021-12-13' + + try: + # open the file in the write mode + with open('changelog/db/changes/data/dmi/generated-csv/generated_yang_resource_' + yang_source + '.csv', 'w', newline='') \ + as file: + writer = csv.writer(file, delimiter='|') + if(writeWithModuleNameAndRevision): + writer.writerow(["name", "content", "checksum", "module_name", "revision"]) + writer.writerow([yang_source + '.yang', dmiRegistry, checksum, module_name, latestRevision]) + else: + writer.writerow(["name", "content", "checksum"]) + writer.writerow([yang_source + '.yang', dmiRegistry, checksum]) + except: + print("ERROR IN in yangResourceCsvGenerator.py: Unable to write to changelog/db/changes/data/dmi/generated-csv/generated_yang_resource_" + yang_source + ".csv") + + +main()
\ No newline at end of file |