diff options
author | lukegleeson <luke.gleeson@est.tech> | 2022-02-10 10:58:29 +0000 |
---|---|---|
committer | lukegleeson <luke.gleeson@est.tech> | 2022-03-03 11:05:23 +0000 |
commit | 0cbc448573409a43eb3bf7b4c9cb49d418a4c999 (patch) | |
tree | 82410672196d6a53b012add69cf82577cab71f04 /cps-ri/src/main/resources/yangResourceCsvGenerator.py | |
parent | 304b9f319cddad71a77f6bbffb8c18f63b7f5ee2 (diff) |
Update dmi-registry yang to support cmHandle State
- Added dmi-registry@2022-02-10 which contains the new dmi-registry yang model to support the cmHandle State.
- Added changelog 12 which removes previous dmi-registries from the db
- Added changelog 13 which adds new dmi-registry
- Edited yangResourceCsvGenerator.py so that it generates for each argument given and does not generate the module_name and revision for dmi-registry@2021-12-13.
- Updated rollback for changeset 11.1
Issue-ID: CPS-874
Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Change-Id: I4ab949f0bc00a52376b42a5ac8a33d397eefcedf
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 |