Skip to content

Commit e2c51f5

Browse files
committed
added three letter country code for tsi dccs
1 parent 04243a1 commit e2c51f5

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

tests/excel_export.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import os
22
import json
33
import logging
44
import openpyxl
@@ -18,7 +18,7 @@
1818
"countryfile-sheet" : "Validation Results", "countryfile-startrow" : 4,
1919
"countryfile-ccc" : "G2",
2020
"countryfile-constants" : {
21-
"H2" : "Validation Cycle #",
21+
"H2" : "Validation Cycle #",
2222
"J2" : "Validation Period Text"
2323
}
2424
}
@@ -27,14 +27,14 @@ def main(args):
2727
workbook = _get_or_create_xlsx(args.filename, config['sheet'])
2828
workbook[config['sheet']].delete_rows(2, amount=1000)
2929

30-
file_entry_handlers = [] # List of objects that handle matching files
30+
file_entry_handlers = [] # List of objects that handle matching files
3131
file_entry_handlers.append(lambda entry : _append_row( workbook[config['sheet']], entry ) )
3232

3333
if args.country_template is not None:
34-
try:
34+
try:
3535
countryFileGenerator = CountryFileGenerator(args.country_template)
3636
file_entry_handlers.append( lambda entry: countryFileGenerator.addEntry(entry) )
37-
except:
37+
except:
3838
logging.error('Country file template was given but could not be loaded')
3939
raise
4040
return -1
@@ -58,9 +58,9 @@ def _append_row(sheet, value_dict):
5858

5959

6060
def _get_or_create_xlsx(filename, sheet_to_use='Codes'):
61-
try:
61+
try:
6262
wb = openpyxl.load_workbook(filename)
63-
except:
63+
except:
6464
wb = openpyxl.Workbook()
6565
wb.active.title = sheet_to_use
6666
wb.active.append(config['column_titles'])
@@ -72,36 +72,38 @@ def _get_or_create_xlsx(filename, sheet_to_use='Codes'):
7272
return wb
7373

7474
def _matching_files(directory):
75-
certificate_types = ['TEST','VAC','REC']
76-
75+
certificate_types = ['TEST','VAC','REC','MULTI']
76+
7777
for ctype in certificate_types:
7878
for match in glob(str(Path(directory,'*' , f'{ctype}*.png'))):
7979
version = match.split(os.sep)[-2]
80-
yield { 'type':ctype,
81-
'country':directory,
82-
'version':version,
80+
yield { 'type':ctype,
81+
'country':directory,
82+
'version':version,
8383
'url' : config['base_url']+match.replace(os.sep,'/'),
8484
'file' : Path(match).name }
8585

8686
for ctype in certificate_types:
8787
for match in glob(str(Path(directory, '*' ,'specialcases' , f'{ctype}*.png'))):
8888
version = match.split(os.sep)[-3]
89-
yield { 'type':f'{ctype} SpecialCase',
90-
'country':directory,
91-
'version':version,
89+
yield { 'type':f'{ctype} SpecialCase',
90+
'country':directory,
91+
'version':version,
9292
'url' : config['base_url']+match.replace(os.sep,'/'),
9393
'file' : Path(match).name }
9494

9595

9696
def _get_country_directories():
97-
# A country directory is any directory that has a name of exactly 2 letters
98-
return [ dirname for dirname in glob('??') if dirname.isalpha() ]
97+
# A country directory is any directory that has a name of exactly 2 or 3 letters
98+
twoLetters = [dirname for dirname in glob('??') if dirname.isalpha()]
99+
threeLetters = [dirname for dirname in glob('???') if dirname.isalpha()]
100+
return twoLetters+threeLetters
99101

100-
class CountryFileGenerator:
101-
'''Generates country files from a template. In order to do so, must first collect
102+
class CountryFileGenerator:
103+
'''Generates country files from a template. In order to do so, must first collect
102104
reference data from source'''
103105

104-
def __init__(self, template_file_name):
106+
def __init__(self, template_file_name):
105107
self.countries = set(config["countryfile-participants"])
106108
self.template_file_name = template_file_name
107109
self.wb = openpyxl.load_workbook(template_file_name)
@@ -110,15 +112,15 @@ def __init__(self, template_file_name):
110112

111113
def addEntry(self, entry):
112114
#self.countries |= set([entry['country']])
113-
sheet = self.wb[config["countryfile-sheet"]]
115+
sheet = self.wb[config["countryfile-sheet"]]
114116

115117
sheet[f"D{self.current_row}"] = entry["url"]
116118
sheet[f"E{self.current_row}"] = entry["file"]
117119
sheet[f"F{self.current_row}"] = "y" if entry["type"].endswith("SpecialCase") else "n"
118120
sheet[f"G{self.current_row}"] = entry["country"]
119121
sheet[f"H{self.current_row}"] = entry["version"]
120122
sheet[f"I{self.current_row}"] = entry["type"]
121-
123+
122124
self.current_row += 1
123125

124126

@@ -129,20 +131,20 @@ def finalize(self):
129131
logging.info(f"Saving country file for {country}")
130132
sheet = self.wb[config["countryfile-sheet"]]
131133
sheet[config["countryfile-ccc"]] = country
132-
for cell,value in config["countryfile-constants"].items():
134+
for cell,value in config["countryfile-constants"].items():
133135
sheet[cell] = value
134136
self.wb.save(f"{base_file_name}_{country}.xlsx")
135137

136138
if __name__ == '__main__':
137-
try:
139+
try:
138140
import coloredlogs
139141
coloredlogs.install()
140142
except:
141143
pass # If we don't have colored logs, it's not important
142144

143145
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
144146

145-
try:
147+
try:
146148
config = json.load(open('config.json'))
147149
logging.info('Loaded config.json')
148150
except:

0 commit comments

Comments
 (0)