-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_status_config.py
executable file
·91 lines (72 loc) · 2.6 KB
/
update_status_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Authors:
# - Stefan Profanter ([email protected])
#
import logging
import argparse
from profile import *
import json
from status import ImplementationStatus
import codecs
import os
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('-c', '--config',
metavar="<configFile>",
default='server.status.json',
help='status.json file describing the implementation status of specific conformance units')
parser.add_argument('--profiles',
metavar="<profilesFile>",
type=argparse.FileType('rb'),
default='./CTT/ServerProjects/Standard/uaprofiles.xml',
help='uaprofiles.xml file which contains all the possible profiles and conformance units')
parser.add_argument('-v', '--verbose', action='count',
default=1,
help='Make the script more verbose. Can be applied up to 4 times')
args = parser.parse_args()
# Set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
verbosity = 0
if args.verbose:
verbosity = int(args.verbose)
if (verbosity == 1):
logging.basicConfig(level=logging.ERROR)
elif (verbosity == 2):
logging.basicConfig(level=logging.WARNING)
elif (verbosity == 3):
logging.basicConfig(level=logging.INFO)
elif (verbosity >= 4):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.CRITICAL)
profiles = Profiles()
profiles.parseFile(args.profiles)
if os.path.exists(args.config):
with codecs.open(args.config, "r", encoding='utf-8') as configFile:
fileContent = configFile.read()
status = json.loads(fileContent)
else:
status = {}
addedNewUnits = False
for group in profiles.conformanceGroups:
if not group.name in status:
status[group.name] = {}
map = status[group.name]
for unit in group.conformanceUnits:
if not unit.name in map:
map[unit.name] = ImplementationStatus.UNKNOWN
addedNewUnits = True
if addedNewUnits:
with open(args.config, 'w') as outfile:
json.dump(status, outfile, indent=4, sort_keys=True)
logger.warning("New units have been added to the config. Please update their status. They are marked as unknown.")
else:
logger.info("Your config is up-to-date")
exit(0)