otlmow-template 0.10__tar.gz → 0.11rc2__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.10 → otlmow_template-0.11rc2}/PKG-INFO +3 -2
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template/SubsetTemplateCreator.py +92 -19
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/PKG-INFO +3 -2
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/requires.txt +1 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/pyproject.toml +2 -1
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/LICENSE +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/README.md +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template/CsvTemplateCreator.py +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template/ExcelTemplateCreator.py +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template/Exceptions/MissingTypeUriException.py +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template/__init__.py +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/SOURCES.txt +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/dependency_links.txt +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/top_level.txt +0 -0
- {otlmow_template-0.10 → otlmow_template-0.11rc2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: otlmow_template
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11rc2
|
|
4
4
|
Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
|
|
5
5
|
License: GNU GENERAL PUBLIC LICENSE
|
|
6
6
|
Version 3, 29 June 2007
|
|
@@ -699,6 +699,7 @@ Description-Content-Type: text/markdown
|
|
|
699
699
|
License-File: LICENSE
|
|
700
700
|
Requires-Dist: otlmow-converter>=1.7
|
|
701
701
|
Requires-Dist: otlmow-modelbuilder>=0.25
|
|
702
|
+
Requires-Dist: universalasync>=0.4.0
|
|
702
703
|
|
|
703
704
|
# OTLMOW-Template
|
|
704
705
|
[](https://pypi.org/project/otlmow-template/)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import asyncio
|
|
1
2
|
import csv
|
|
2
3
|
import logging
|
|
3
4
|
import ntpath
|
|
4
5
|
import os
|
|
5
6
|
import site
|
|
6
7
|
import tempfile
|
|
8
|
+
from asyncio import sleep
|
|
7
9
|
from pathlib import Path
|
|
8
10
|
|
|
9
11
|
|
|
@@ -20,6 +22,7 @@ from otlmow_model.OtlmowModel.BaseClasses.OTLObject import dynamic_create_instan
|
|
|
20
22
|
from otlmow_model.OtlmowModel.Helpers.generated_lists import get_hardcoded_relation_dict
|
|
21
23
|
from otlmow_modelbuilder.OSLOCollector import OSLOCollector
|
|
22
24
|
from otlmow_modelbuilder.SQLDataClasses.OSLOClass import OSLOClass
|
|
25
|
+
from universalasync import async_to_sync_wraps
|
|
23
26
|
|
|
24
27
|
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
25
28
|
|
|
@@ -40,7 +43,8 @@ class SubsetTemplateCreator:
|
|
|
40
43
|
collector.collect_all(include_abstract=True)
|
|
41
44
|
return collector
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
@async_to_sync_wraps
|
|
47
|
+
async def generate_template_from_subset(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
|
|
44
48
|
ignore_relations: bool = True, filter_attributes_by_subset: bool = True,
|
|
45
49
|
**kwargs):
|
|
46
50
|
tempdir = Path(tempfile.gettempdir()) / 'temp-otlmow'
|
|
@@ -48,24 +52,28 @@ class SubsetTemplateCreator:
|
|
|
48
52
|
os.makedirs(tempdir)
|
|
49
53
|
test = ntpath.basename(path_to_template_file_and_extension)
|
|
50
54
|
temporary_path = Path(tempdir) / test
|
|
51
|
-
|
|
55
|
+
await sleep(0)
|
|
56
|
+
instantiated_attributes = (await self.generate_basic_template(
|
|
52
57
|
path_to_subset=path_to_subset, temporary_path=temporary_path, ignore_relations=ignore_relations,
|
|
53
58
|
path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
54
59
|
filter_attributes_by_subset=filter_attributes_by_subset, **kwargs))
|
|
60
|
+
await sleep(0)
|
|
55
61
|
extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
|
|
56
62
|
if extension == '.xlsx':
|
|
57
|
-
self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
63
|
+
await self.alter_excel_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
58
64
|
temporary_path=temporary_path,
|
|
59
65
|
path_to_subset=path_to_subset, instantiated_attributes=instantiated_attributes,
|
|
60
66
|
**kwargs)
|
|
61
67
|
elif extension == '.csv':
|
|
62
|
-
self.determine_multiplicity_csv(
|
|
68
|
+
await self.determine_multiplicity_csv(
|
|
69
|
+
path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
63
70
|
path_to_subset=path_to_subset,
|
|
64
71
|
instantiated_attributes=instantiated_attributes,
|
|
65
72
|
temporary_path=temporary_path,
|
|
66
73
|
**kwargs)
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
@async_to_sync_wraps
|
|
76
|
+
async def generate_basic_template(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
|
|
69
77
|
temporary_path: Path, ignore_relations: bool = True, **kwargs):
|
|
70
78
|
list_of_otl_objectUri = None
|
|
71
79
|
if kwargs is not None:
|
|
@@ -105,19 +113,21 @@ class SubsetTemplateCreator:
|
|
|
105
113
|
DotnotationHelper.clear_list_of_list_attributes(instance)
|
|
106
114
|
|
|
107
115
|
converter = OtlmowConverter()
|
|
108
|
-
converter.from_objects_to_file(file_path=temporary_path,
|
|
116
|
+
await converter.from_objects_to_file(file_path=temporary_path,
|
|
109
117
|
sequence_of_objects=otl_objects, **kwargs)
|
|
110
118
|
path_is_split = kwargs.get('split_per_type', True)
|
|
111
119
|
extension = os.path.splitext(path_to_template_file_and_extension)[-1].lower()
|
|
112
120
|
instantiated_attributes = []
|
|
113
121
|
if path_is_split is False or extension == '.xlsx':
|
|
114
|
-
instantiated_attributes = converter.from_file_to_objects(file_path=temporary_path,
|
|
122
|
+
instantiated_attributes = await converter.from_file_to_objects(file_path=temporary_path,
|
|
115
123
|
path_to_subset=path_to_subset)
|
|
116
|
-
return instantiated_attributes
|
|
124
|
+
return list(instantiated_attributes)
|
|
117
125
|
|
|
118
126
|
@classmethod
|
|
119
|
-
|
|
127
|
+
@async_to_sync_wraps
|
|
128
|
+
async def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
|
|
120
129
|
instantiated_attributes: list, temporary_path, **kwargs):
|
|
130
|
+
await sleep(0)
|
|
121
131
|
generate_choice_list = kwargs.get('generate_choice_list', False)
|
|
122
132
|
add_geo_artefact = kwargs.get('add_geo_artefact', False)
|
|
123
133
|
add_attribute_info = kwargs.get('add_attribute_info', False)
|
|
@@ -125,28 +135,39 @@ class SubsetTemplateCreator:
|
|
|
125
135
|
amount_of_examples = kwargs.get('amount_of_examples', 0)
|
|
126
136
|
if add_attribute_info and amount_of_examples == 0:
|
|
127
137
|
amount_of_examples = 1
|
|
138
|
+
await sleep(0)
|
|
128
139
|
wb = load_workbook(temporary_path)
|
|
129
140
|
wb.create_sheet('Keuzelijsten')
|
|
130
141
|
# Volgorde is belangrijk! Eerst rijen verwijderen indien nodig dan choice list toevoegen,
|
|
131
142
|
# staat namelijk vast op de kolom en niet het attribuut in die kolom
|
|
132
143
|
if add_geo_artefact is False:
|
|
144
|
+
await sleep(0)
|
|
133
145
|
cls.remove_geo_artefact_excel(workbook=wb)
|
|
134
146
|
if generate_choice_list:
|
|
135
|
-
|
|
147
|
+
await sleep(0)
|
|
148
|
+
await cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
|
|
136
149
|
path_to_subset=path_to_subset)
|
|
150
|
+
await sleep(0)
|
|
137
151
|
cls.add_mock_data_excel(workbook=wb, rows_of_examples=amount_of_examples)
|
|
152
|
+
await cls.add_type_uri_choice_list_in_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
|
|
138
153
|
if highlight_deprecated_attributes:
|
|
154
|
+
await sleep(0)
|
|
139
155
|
cls.check_for_deprecated_attributes(workbook=wb, instantiated_attributes=instantiated_attributes)
|
|
140
156
|
if add_attribute_info:
|
|
141
|
-
|
|
142
|
-
|
|
157
|
+
await sleep(0)
|
|
158
|
+
await cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
|
|
159
|
+
await sleep(0)
|
|
160
|
+
await cls.design_workbook_excel(workbook=wb)
|
|
161
|
+
await sleep(0)
|
|
143
162
|
wb.save(path_to_template_file_and_extension)
|
|
144
163
|
file_location = os.path.dirname(temporary_path)
|
|
145
164
|
[f.unlink() for f in Path(file_location).glob("*") if f.is_file()]
|
|
146
165
|
|
|
147
|
-
|
|
166
|
+
@async_to_sync_wraps
|
|
167
|
+
async def determine_multiplicity_csv(self, path_to_template_file_and_extension: Path, path_to_subset: Path,
|
|
148
168
|
instantiated_attributes: list, temporary_path: Path, **kwargs):
|
|
149
169
|
path_is_split = kwargs.get('split_per_type', True)
|
|
170
|
+
await sleep(0)
|
|
150
171
|
if path_is_split is False:
|
|
151
172
|
self.alter_csv_template(path_to_template_file_and_extension=path_to_template_file_and_extension,
|
|
152
173
|
temporary_path=temporary_path, path_to_subset=path_to_subset, **kwargs)
|
|
@@ -174,24 +195,71 @@ class SubsetTemplateCreator:
|
|
|
174
195
|
return converter_path / 'settings_otlmow_converter.json'
|
|
175
196
|
|
|
176
197
|
@classmethod
|
|
177
|
-
|
|
198
|
+
@async_to_sync_wraps
|
|
199
|
+
async def add_type_uri_choice_list_in_excel(cls, workbook, instantiated_attributes):
|
|
200
|
+
for sheet in workbook:
|
|
201
|
+
await sleep(0)
|
|
202
|
+
if sheet.title == 'Keuzelijsten':
|
|
203
|
+
break
|
|
204
|
+
type_uri_found = False
|
|
205
|
+
for row in sheet.iter_rows(min_row=1, max_row=1):
|
|
206
|
+
for cell in row:
|
|
207
|
+
if cell.value == 'typeURI':
|
|
208
|
+
type_uri_found = True
|
|
209
|
+
break
|
|
210
|
+
if type_uri_found:
|
|
211
|
+
break
|
|
212
|
+
if not type_uri_found:
|
|
213
|
+
continue
|
|
214
|
+
|
|
215
|
+
await sleep(0)
|
|
216
|
+
sheet_name = sheet.title
|
|
217
|
+
type_uri = ''
|
|
218
|
+
if sheet_name.startswith('http'):
|
|
219
|
+
type_uri = sheet_name
|
|
220
|
+
else:
|
|
221
|
+
split_name = sheet_name.split("#")
|
|
222
|
+
subclass_name = split_name[1]
|
|
223
|
+
|
|
224
|
+
possible_classes = [x for x in instantiated_attributes if x.typeURI.endswith(subclass_name)]
|
|
225
|
+
if len(possible_classes) == 1:
|
|
226
|
+
type_uri = possible_classes[0].typeURI
|
|
227
|
+
|
|
228
|
+
if type_uri == '':
|
|
229
|
+
continue
|
|
230
|
+
|
|
231
|
+
data_validation = DataValidation(type="list", formula1=f'"{type_uri}"', allow_blank=True)
|
|
232
|
+
await sleep(0)
|
|
233
|
+
for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=1):
|
|
234
|
+
for cell in rows:
|
|
235
|
+
column = cell.column
|
|
236
|
+
sheet.add_data_validation(data_validation)
|
|
237
|
+
data_validation.add(f'{get_column_letter(column)}2:{get_column_letter(column)}1000')
|
|
238
|
+
|
|
239
|
+
@classmethod
|
|
240
|
+
@async_to_sync_wraps
|
|
241
|
+
async def design_workbook_excel(cls, workbook):
|
|
178
242
|
for sheet in workbook:
|
|
179
243
|
dim_holder = DimensionHolder(worksheet=sheet)
|
|
180
244
|
for col in range(sheet.min_column, sheet.max_column + 1):
|
|
245
|
+
await sleep(0)
|
|
181
246
|
dim_holder[get_column_letter(col)] = ColumnDimension(sheet, min=col, max=col, width=25)
|
|
182
247
|
sheet.column_dimensions = dim_holder
|
|
183
248
|
|
|
184
249
|
@classmethod
|
|
185
|
-
|
|
250
|
+
@async_to_sync_wraps
|
|
251
|
+
async def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
|
|
186
252
|
dotnotation_module = DotnotationHelper()
|
|
187
253
|
for sheet in workbook:
|
|
188
254
|
if sheet == workbook['Keuzelijsten']:
|
|
189
255
|
break
|
|
190
256
|
filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
|
|
257
|
+
await sleep(0)
|
|
191
258
|
single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
|
|
192
259
|
sheet.insert_rows(1)
|
|
193
260
|
for rows in sheet.iter_rows(min_row=2, max_row=2, min_col=1):
|
|
194
261
|
for cell in rows:
|
|
262
|
+
await sleep(0)
|
|
195
263
|
if cell.value == 'typeURI':
|
|
196
264
|
value = 'De URI van het object volgens https://www.w3.org/2001/XMLSchema#anyURI .'
|
|
197
265
|
elif cell.value.find('[DEPRECATED]') != -1:
|
|
@@ -254,16 +322,19 @@ class SubsetTemplateCreator:
|
|
|
254
322
|
sheet.delete_cols(cell.column)
|
|
255
323
|
|
|
256
324
|
@classmethod
|
|
257
|
-
|
|
325
|
+
@async_to_sync_wraps
|
|
326
|
+
async def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
|
|
258
327
|
choice_list_dict = {}
|
|
259
328
|
dotnotation_module = DotnotationHelper()
|
|
260
329
|
for sheet in workbook:
|
|
330
|
+
await sleep(0)
|
|
261
331
|
if sheet == workbook['Keuzelijsten']:
|
|
262
332
|
break
|
|
263
333
|
filter_uri = SubsetTemplateCreator.find_uri_in_sheet(sheet)
|
|
264
334
|
single_attribute = next(x for x in instantiated_attributes if x.typeURI == filter_uri)
|
|
265
335
|
for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=2):
|
|
266
336
|
for cell in rows:
|
|
337
|
+
await sleep(0)
|
|
267
338
|
if cell.value.find('[DEPRECATED]') != -1:
|
|
268
339
|
strip = cell.value.split(' ')
|
|
269
340
|
dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
|
|
@@ -271,7 +342,7 @@ class SubsetTemplateCreator:
|
|
|
271
342
|
else:
|
|
272
343
|
dotnotation_attribute = dotnotation_module.get_attribute_by_dotnotation(single_attribute,
|
|
273
344
|
cell.value)
|
|
274
|
-
|
|
345
|
+
await sleep(0)
|
|
275
346
|
if issubclass(dotnotation_attribute.field, KeuzelijstField):
|
|
276
347
|
name = dotnotation_attribute.field.naam
|
|
277
348
|
valid_options = [v.invulwaarde for k, v in dotnotation_attribute.field.options.items()
|
|
@@ -286,12 +357,14 @@ class SubsetTemplateCreator:
|
|
|
286
357
|
allowBlank=True)
|
|
287
358
|
sheet.add_data_validation(data_val)
|
|
288
359
|
data_val.add(f'{get_column_letter(cell.column)}2:{get_column_letter(cell.column)}1000')
|
|
360
|
+
|
|
361
|
+
await sleep(0)
|
|
289
362
|
if issubclass(dotnotation_attribute.field, BooleanField):
|
|
290
|
-
data_validation = DataValidation(type="list", formula1='"TRUE,FALSE
|
|
363
|
+
data_validation = DataValidation(type="list", formula1='"TRUE,FALSE,"', allow_blank=True)
|
|
291
364
|
column = cell.column
|
|
292
365
|
sheet.add_data_validation(data_validation)
|
|
293
366
|
data_validation.add(f'{get_column_letter(column)}2:{get_column_letter(column)}1000')
|
|
294
|
-
|
|
367
|
+
|
|
295
368
|
|
|
296
369
|
@classmethod
|
|
297
370
|
def add_mock_data_excel(cls, workbook, rows_of_examples: int):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: otlmow_template
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11rc2
|
|
4
4
|
Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
|
|
5
5
|
License: GNU GENERAL PUBLIC LICENSE
|
|
6
6
|
Version 3, 29 June 2007
|
|
@@ -699,6 +699,7 @@ Description-Content-Type: text/markdown
|
|
|
699
699
|
License-File: LICENSE
|
|
700
700
|
Requires-Dist: otlmow-converter>=1.7
|
|
701
701
|
Requires-Dist: otlmow-modelbuilder>=0.25
|
|
702
|
+
Requires-Dist: universalasync>=0.4.0
|
|
702
703
|
|
|
703
704
|
# OTLMOW-Template
|
|
704
705
|
[](https://pypi.org/project/otlmow-template/)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "otlmow_template"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.11-rc2"
|
|
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"
|
|
@@ -31,6 +31,7 @@ requires-python = ">=3.9"
|
|
|
31
31
|
dependencies = [
|
|
32
32
|
'otlmow-converter >= 1.7',
|
|
33
33
|
'otlmow-modelbuilder >= 0.25',
|
|
34
|
+
'universalasync>=0.4.0'
|
|
34
35
|
]
|
|
35
36
|
|
|
36
37
|
[tool.setuptools.packages.find]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{otlmow_template-0.10 → otlmow_template-0.11rc2}/otlmow_template.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|