otlmow-template 0.11rc1__tar.gz → 0.11rc3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/PKG-INFO +1 -1
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/SubsetTemplateCreator.py +112 -19
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/PKG-INFO +1 -1
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/pyproject.toml +1 -1
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/LICENSE +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/README.md +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/CsvTemplateCreator.py +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/ExcelTemplateCreator.py +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/Exceptions/MissingTypeUriException.py +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/__init__.py +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/SOURCES.txt +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/dependency_links.txt +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/requires.txt +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/top_level.txt +0 -0
- {otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/setup.cfg +0 -0
{otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template/SubsetTemplateCreator.py
RENAMED
|
@@ -52,10 +52,12 @@ class SubsetTemplateCreator:
|
|
|
52
52
|
os.makedirs(tempdir)
|
|
53
53
|
test = ntpath.basename(path_to_template_file_and_extension)
|
|
54
54
|
temporary_path = Path(tempdir) / test
|
|
55
|
+
await sleep(0)
|
|
55
56
|
instantiated_attributes = (await self.generate_basic_template(
|
|
56
57
|
path_to_subset=path_to_subset, temporary_path=temporary_path, ignore_relations=ignore_relations,
|
|
57
58
|
path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
58
59
|
filter_attributes_by_subset=filter_attributes_by_subset, **kwargs))
|
|
60
|
+
await sleep(0)
|
|
59
61
|
extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
|
|
60
62
|
if extension == '.xlsx':
|
|
61
63
|
await self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
@@ -95,6 +97,7 @@ class SubsetTemplateCreator:
|
|
|
95
97
|
continue
|
|
96
98
|
for _ in range(generate_dummy_records):
|
|
97
99
|
instance = dynamic_create_instance_from_uri(class_object.objectUri, model_directory=model_directory)
|
|
100
|
+
await sleep(0)
|
|
98
101
|
if instance is None:
|
|
99
102
|
continue
|
|
100
103
|
attributen = collector.find_attributes_by_class(class_object)
|
|
@@ -110,6 +113,7 @@ class SubsetTemplateCreator:
|
|
|
110
113
|
|
|
111
114
|
DotnotationHelper.clear_list_of_list_attributes(instance)
|
|
112
115
|
|
|
116
|
+
await sleep(0)
|
|
113
117
|
converter = OtlmowConverter()
|
|
114
118
|
await converter.from_objects_to_file(file_path=temporary_path,
|
|
115
119
|
sequence_of_objects=otl_objects, **kwargs)
|
|
@@ -117,14 +121,15 @@ class SubsetTemplateCreator:
|
|
|
117
121
|
extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
|
|
118
122
|
instantiated_attributes = []
|
|
119
123
|
if path_is_split is False or extension == '.xlsx':
|
|
120
|
-
instantiated_attributes = converter.from_file_to_objects(file_path=temporary_path,
|
|
124
|
+
instantiated_attributes = await converter.from_file_to_objects(file_path=temporary_path,
|
|
121
125
|
path_to_subset=path_to_subset)
|
|
122
|
-
return instantiated_attributes
|
|
126
|
+
return list(instantiated_attributes)
|
|
123
127
|
|
|
124
128
|
@classmethod
|
|
125
129
|
@async_to_sync_wraps
|
|
126
130
|
async def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
|
|
127
131
|
instantiated_attributes: list, temporary_path, **kwargs):
|
|
132
|
+
await sleep(0)
|
|
128
133
|
generate_choice_list = kwargs.get('generate_choice_list', False)
|
|
129
134
|
add_geo_artefact = kwargs.get('add_geo_artefact', False)
|
|
130
135
|
add_attribute_info = kwargs.get('add_attribute_info', False)
|
|
@@ -138,16 +143,25 @@ class SubsetTemplateCreator:
|
|
|
138
143
|
# Volgorde is belangrijk! Eerst rijen verwijderen indien nodig dan choice list toevoegen,
|
|
139
144
|
# staat namelijk vast op de kolom en niet het attribuut in die kolom
|
|
140
145
|
if add_geo_artefact is False:
|
|
146
|
+
await sleep(0)
|
|
141
147
|
cls.remove_geo_artefact_excel(workbook=wb)
|
|
142
148
|
if generate_choice_list:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
await sleep(0)
|
|
150
|
+
await cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
|
|
151
|
+
path_to_subset=path_to_subset, add_attribute_info=add_attribute_info)
|
|
152
|
+
await sleep(0)
|
|
153
|
+
cls.add_mock_data_excel(workbook=wb, rows_of_examples=amount_of_examples) # remove dummy rows if needed
|
|
154
|
+
|
|
155
|
+
await cls.custom_exel_fixes(workbook=wb, instantiated_attributes=instantiated_attributes,
|
|
156
|
+
add_attribute_info=add_attribute_info)
|
|
157
|
+
await sleep(0)
|
|
146
158
|
if highlight_deprecated_attributes:
|
|
159
|
+
await sleep(0)
|
|
147
160
|
cls.check_for_deprecated_attributes(workbook=wb, instantiated_attributes=instantiated_attributes)
|
|
148
161
|
if add_attribute_info:
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
await sleep(0)
|
|
163
|
+
await cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
|
|
164
|
+
await sleep(0)
|
|
151
165
|
wb.save(path_to_template_file_and_extension)
|
|
152
166
|
file_location = os.path.dirname(temporary_path)
|
|
153
167
|
[f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
|
|
@@ -184,24 +198,94 @@ class SubsetTemplateCreator:
|
|
|
184
198
|
return converter_path / 'settings_otlmow_converter.json'
|
|
185
199
|
|
|
186
200
|
@classmethod
|
|
187
|
-
|
|
201
|
+
@async_to_sync_wraps
|
|
202
|
+
async def add_type_uri_choice_list_in_excel(cls, sheet, instantiated_attributes, add_attribute_info: bool):
|
|
203
|
+
starting_row = '3' if add_attribute_info else '2'
|
|
204
|
+
await sleep(0)
|
|
205
|
+
if sheet.title == 'Keuzelijsten':
|
|
206
|
+
return
|
|
207
|
+
type_uri_found = False
|
|
208
|
+
for row in sheet.iter_rows(min_row=1, max_row=1):
|
|
209
|
+
for cell in row:
|
|
210
|
+
if cell.value == 'typeURI':
|
|
211
|
+
type_uri_found = True
|
|
212
|
+
break
|
|
213
|
+
if type_uri_found:
|
|
214
|
+
break
|
|
215
|
+
if not type_uri_found:
|
|
216
|
+
return
|
|
217
|
+
|
|
218
|
+
await sleep(0)
|
|
219
|
+
sheet_name = sheet.title
|
|
220
|
+
type_uri = ''
|
|
221
|
+
if sheet_name.startswith('http'):
|
|
222
|
+
type_uri = sheet_name
|
|
223
|
+
else:
|
|
224
|
+
split_name = sheet_name.split("#")
|
|
225
|
+
subclass_name = split_name[1]
|
|
226
|
+
|
|
227
|
+
possible_classes = [x for x in instantiated_attributes if x.typeURI.endswith(subclass_name)]
|
|
228
|
+
if len(possible_classes) == 1:
|
|
229
|
+
type_uri = possible_classes[0].typeURI
|
|
230
|
+
|
|
231
|
+
if type_uri == '':
|
|
232
|
+
return
|
|
233
|
+
|
|
234
|
+
data_validation = DataValidation(type="list", formula1=f'"{type_uri}"', allow_blank=True)
|
|
235
|
+
await sleep(0)
|
|
236
|
+
for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=1):
|
|
237
|
+
for cell in rows:
|
|
238
|
+
await sleep(0)
|
|
239
|
+
column = cell.column
|
|
240
|
+
sheet.add_data_validation(data_validation)
|
|
241
|
+
data_validation.add(f'{get_column_letter(column)}{starting_row}:{get_column_letter(column)}1000')
|
|
242
|
+
|
|
243
|
+
@classmethod
|
|
244
|
+
@async_to_sync_wraps
|
|
245
|
+
async def custom_exel_fixes(cls, workbook, instantiated_attributes, add_attribute_info: bool):
|
|
188
246
|
for sheet in workbook:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
247
|
+
await sleep(0)
|
|
248
|
+
await cls.set_fixed_column_width(sheet=sheet, width=25)
|
|
249
|
+
await cls.add_type_uri_choice_list_in_excel(sheet=sheet, instantiated_attributes=instantiated_attributes,
|
|
250
|
+
add_attribute_info=add_attribute_info)
|
|
251
|
+
await cls.remove_asset_versie(sheet=sheet)
|
|
252
|
+
|
|
253
|
+
@classmethod
|
|
254
|
+
@async_to_sync_wraps
|
|
255
|
+
async def remove_asset_versie(cls, sheet):
|
|
256
|
+
for row in sheet.iter_rows(min_row=1, max_row=1, min_col=4):
|
|
257
|
+
for cell in row:
|
|
258
|
+
await sleep(0)
|
|
259
|
+
if cell.value is None or not cell.value.startswith('assetVersie'):
|
|
260
|
+
continue
|
|
261
|
+
for rows in sheet.iter_rows(min_row=row, max_row=row, min_col=2, max_col=1000):
|
|
262
|
+
for c in rows:
|
|
263
|
+
await sleep(0)
|
|
264
|
+
c.value = ''
|
|
193
265
|
|
|
194
266
|
@classmethod
|
|
195
|
-
|
|
267
|
+
@async_to_sync_wraps
|
|
268
|
+
async def set_fixed_column_width(cls, sheet, width: int):
|
|
269
|
+
dim_holder = DimensionHolder(worksheet=sheet)
|
|
270
|
+
for col in range(sheet.min_column, sheet.max_column + 1):
|
|
271
|
+
await sleep(0)
|
|
272
|
+
dim_holder[get_column_letter(col)] = ColumnDimension(sheet, min=col, max=col, width=width)
|
|
273
|
+
sheet.column_dimensions = dim_holder
|
|
274
|
+
|
|
275
|
+
@classmethod
|
|
276
|
+
@async_to_sync_wraps
|
|
277
|
+
async def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
|
|
196
278
|
dotnotation_module = DotnotationHelper()
|
|
197
279
|
for sheet in workbook:
|
|
198
280
|
if sheet == workbook['Keuzelijsten']:
|
|
199
281
|
break
|
|
200
282
|
filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
|
|
283
|
+
await sleep(0)
|
|
201
284
|
single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
|
|
202
285
|
sheet.insert_rows(1)
|
|
203
286
|
for rows in sheet.iter_rows(min_row=2, max_row=2, min_col=1):
|
|
204
287
|
for cell in rows:
|
|
288
|
+
await sleep(0)
|
|
205
289
|
if cell.value == 'typeURI':
|
|
206
290
|
value = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
|
|
207
291
|
elif cell.value.find('[DEPRECATED]') != -1:
|
|
@@ -264,16 +348,21 @@ class SubsetTemplateCreator:
|
|
|
264
348
|
sheet.delete_cols(cell.column)
|
|
265
349
|
|
|
266
350
|
@classmethod
|
|
267
|
-
|
|
351
|
+
@async_to_sync_wraps
|
|
352
|
+
async def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path,
|
|
353
|
+
add_attribute_info: bool=False):
|
|
268
354
|
choice_list_dict = {}
|
|
355
|
+
starting_row = '3' if add_attribute_info else '2'
|
|
269
356
|
dotnotation_module = DotnotationHelper()
|
|
270
357
|
for sheet in workbook:
|
|
358
|
+
await sleep(0)
|
|
271
359
|
if sheet == workbook['Keuzelijsten']:
|
|
272
360
|
break
|
|
273
361
|
filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
|
|
274
362
|
single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
|
|
275
363
|
for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=2):
|
|
276
364
|
for cell in rows:
|
|
365
|
+
await sleep(0)
|
|
277
366
|
if cell.value.find('[DEPRECATED]') != -1:
|
|
278
367
|
strip = cell.value.split(' ')
|
|
279
368
|
dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
|
|
@@ -281,7 +370,7 @@ class SubsetTemplateCreator:
|
|
|
281
370
|
else:
|
|
282
371
|
dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
|
|
283
372
|
cell.value)
|
|
284
|
-
|
|
373
|
+
await sleep(0)
|
|
285
374
|
if issubclass(dotnotation_attribute.field, KeuzelijstField):
|
|
286
375
|
name = dotnotation_attribute.field.naam
|
|
287
376
|
valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
|
|
@@ -295,13 +384,17 @@ class SubsetTemplateCreator:
|
|
|
295
384
|
data_val = DataValidation(type="list", formula1=f"Keuzelijsten!{start_range}:{end_range}",
|
|
296
385
|
allowBlank=True)
|
|
297
386
|
sheet.add_data_validation(data_val)
|
|
298
|
-
data_val.add(f'{get_column_letter(cell.column)}
|
|
387
|
+
data_val.add(f'{get_column_letter(cell.column)}{starting_row}:'
|
|
388
|
+
f'{get_column_letter(cell.column)}1000')
|
|
389
|
+
|
|
390
|
+
await sleep(0)
|
|
299
391
|
if issubclass(dotnotation_attribute.field, BooleanField):
|
|
300
|
-
data_validation = DataValidation(type="list", formula1='"TRUE,FALSE
|
|
392
|
+
data_validation = DataValidation(type="list", formula1='"TRUE,FALSE,"', allow_blank=True)
|
|
301
393
|
column = cell.column
|
|
302
394
|
sheet.add_data_validation(data_validation)
|
|
303
|
-
data_validation.add(f'{get_column_letter(column)}
|
|
304
|
-
|
|
395
|
+
data_validation.add(f'{get_column_letter(column)}{starting_row}:'
|
|
396
|
+
f'{get_column_letter(column)}1000')
|
|
397
|
+
|
|
305
398
|
|
|
306
399
|
@classmethod
|
|
307
400
|
def add_mock_data_excel(cls, workbook, rows_of_examples: int):
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "otlmow_template"
|
|
7
|
-
version = "0.11-
|
|
7
|
+
version = "0.11-rc3"
|
|
8
8
|
authors = [{name = "David Vlaminck", email = "david.vlaminck@mow.vlaanderen.be"},
|
|
9
9
|
{name = "Jasper Berton", email = "jasperberton1@telenet.be"},]
|
|
10
10
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{otlmow_template-0.11rc1 → otlmow_template-0.11rc3}/otlmow_template.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|