-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdict_release_notes.py
207 lines (177 loc) · 7.14 KB
/
dict_release_notes.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env python3
"""Data Dictionary Release Notes
Generates release notes for ARGOS Data Dictionary.
"""
import csv
from argparse import ArgumentParser, SUPPRESS
import sys
import os
__version__ = "0.1.0"
__status__ = "Production"
def usr_args():
"""User Arguments
User supplied arguments from command line for function
Returns
-------
ArgumentParser objects to be digested by subsequent functions.
"""
parser = ArgumentParser(
add_help=False,
prog='data_sheet_validator',
description="Release Note Generator. "
"Used to generate release notes from two differnt versions.")
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('-o', '--old',
required=True,
help="Directory for old version of dictionary.")
required.add_argument('-n', '--new',
required=True,
help="Directory for new version of dictionary")
optional.add_argument('-v', '--version',
action='version',
version='%(prog)s ' + __version__)
optional.add_argument('-h', '--help',
action='help',
default=SUPPRESS,
help='show this help message and exit')
if len(sys.argv) <= 1:
sys.argv.append('--help')
return parser.parse_args()
def load_tsv(options):
"""Load TSVs
Parameters
----------
options.old: str
An inpit directory string.
options.new: str
An inpit directory string.
Returns
-------
Printout of comparison stats.
"""
counts ={}
readme = []
property_definition = {}
core_property_list = []
non_core_property_list = []
new_readme = []
new_property_definition = {}
new_core_property_list = []
new_non_core_property_list = []
for sheet in os.listdir(options.old):
if 'README' in sheet:
file_path = os.path.join(options.old, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
for row in file:
if row == '\t\t\n':
continue
readme.append(row)
if 'property_definition' in sheet:
file_path = os.path.join(options.old, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
for row in data:
property_definition[row[0]] = row[1:]
if 'core_property_list' in sheet:
file_path = os.path.join(options.old, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
counts['core_property_list'] ={}
for row in data:
core_property_list.append(row)
if row[1] not in counts['core_property_list']:
counts['core_property_list'][row[1]] = 1
else:
counts['core_property_list'][row[1]] += 1
if 'annotation_property_list' in sheet or\
'non_core_property_list' in sheet:
file_path = os.path.join(options.old, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
counts['non_core_property_list'] ={}
for row in data:
non_core_property_list.append(row)
if row[1] not in counts['non_core_property_list']:
counts['non_core_property_list'][row[1]] = 1
else:
counts['non_core_property_list'][row[1]] += 1
for sheet in os.listdir(options.new):
if 'README' in sheet:
file_path = os.path.join(options.new, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
for row in file:
if row == '\t\t\n':
continue
new_readme.append(row)
if 'property_definition.tsv' in sheet:
file_path = os.path.join(options.new, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
for row in data:
new_property_definition[row[0]] = row[1:]
if 'core_property_list' in sheet:
file_path = os.path.join(options.new, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
counts['new_core_property_list'] ={}
for row in data:
new_core_property_list.append(row)
if row[1] not in counts['new_core_property_list']:
counts['new_core_property_list'][row[1]] = 1
else:
counts['new_core_property_list'][row[1]] += 1
if 'annotation_property_list' in sheet or\
'non-core_property_list' in sheet:
file_path = os.path.join(options.new, sheet)
with open(file_path, 'r', encoding='utf-8') as file:
data = csv.reader(file, delimiter='\t')
next(data)
counts['new_non_core_property_list'] ={}
for row in data:
new_non_core_property_list.append(row)
if row[1] not in counts['new_non_core_property_list']:
counts['new_non_core_property_list'][row[1]] = 1
else:
counts['new_non_core_property_list'][row[1]] += 1
print(counts)
removed = []
added = []
# print(new_non_core_property_list == non_core_property_list)
# print(readme == new_readme)
# print(property_definition == new_property_definition)
# print(core_property_list == new_core_property_list)
# print(non_core_property_list == new_non_core_property_list)
# print('\n')
for key in property_definition:
if key not in new_property_definition.keys():
removed.append(key)
# print(f'{key} removed from {options.new}')
for key in new_property_definition:
if key not in property_definition.keys():
added.append(key)
# print(f'{key} added to {options.new}')
print('\nCore Property Sheet Stats:\n Sheet \t Properties')
for key in counts['new_core_property_list']:
print(key, '\t', counts['new_core_property_list'][key] )
print('\nNon Core Property Sheet Stats:\n Sheet \t Properties')
for key in counts['new_non_core_property_list']:
print(key, '\t', counts['new_non_core_property_list'][key] )
print('\n')
print(f'{len(removed)} items removed from the dictionary: {removed}')
print('\n')
print(f'{len(added)} items added to the dictionary: {added}')
def main():
"""
Main function
"""
options = usr_args()
load_tsv(options)
#______________________________________________________________________________#
if __name__ == "__main__":
main()