otlmow-template 0.10__py3-none-any.whl → 0.11rc2__py3-none-any.whl

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.
@@ -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
- def generate_template_from_subset(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
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
- instantiated_attributes = (self.generate_basic_template(
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(path_to_template_file_and_extension=path_to_template_file_and_extension,
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
- def generate_basic_template(self, path_to_subset: Path, path_to_template_file_and_extension: Path,
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
- def alter_excel_template(cls, path_to_template_file_and_extension: Path, path_to_subset: Path,
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
- cls.add_choice_list_excel(workbook=wb, instantiated_attributes=instantiated_attributes,
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
- cls.add_attribute_info_excel(workbook=wb, instantiated_attributes=instantiated_attributes)
142
- cls.design_workbook_excel(workbook=wb)
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
- def determine_multiplicity_csv(self, path_to_template_file_and_extension: Path, path_to_subset: Path,
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
- def design_workbook_excel(cls, workbook):
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
- def add_attribute_info_excel(cls, workbook, instantiated_attributes: list):
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
- def add_choice_list_excel(cls, workbook, instantiated_attributes: list, path_to_subset: Path):
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,-"', allow_blank=True)
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
- sheet.add_data_validation(data_validation)
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
1
+ Metadata-Version: 2.2
2
2
  Name: otlmow_template
3
- Version: 0.10
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
  [![PyPI](https://img.shields.io/pypi/v/otlmow-template?label=latest%20release)](https://pypi.org/project/otlmow-template/)
@@ -0,0 +1,10 @@
1
+ otlmow_template/CsvTemplateCreator.py,sha256=PQq2zGmliWk0N9bhYNB7ZEa8PWV16OTbvoHh3--qCMs,7538
2
+ otlmow_template/ExcelTemplateCreator.py,sha256=wW-7Uq2Gzr1vHYMO1I7TtqZSBTVFFSWotHvjwzCelV4,10853
3
+ otlmow_template/SubsetTemplateCreator.py,sha256=bm_09LyZc4IY1jxx2ptJZ0553W8QeUYuqHF34rvN0Yc,27819
4
+ otlmow_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
6
+ otlmow_template-0.11rc2.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
+ otlmow_template-0.11rc2.dist-info/METADATA,sha256=nBwN3iqwVAHEq7K2V9jQATSzADad0WkKAzXLfAInj9c,44040
8
+ otlmow_template-0.11rc2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
9
+ otlmow_template-0.11rc2.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
+ otlmow_template-0.11rc2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- otlmow_template/CsvTemplateCreator.py,sha256=PQq2zGmliWk0N9bhYNB7ZEa8PWV16OTbvoHh3--qCMs,7538
2
- otlmow_template/ExcelTemplateCreator.py,sha256=wW-7Uq2Gzr1vHYMO1I7TtqZSBTVFFSWotHvjwzCelV4,10853
3
- otlmow_template/SubsetTemplateCreator.py,sha256=FQNaOp-3_EelKijpOBT5KjwZ3X30yD5K9xpmY0euDLo,25225
4
- otlmow_template/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
6
- otlmow_template-0.10.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
7
- otlmow_template-0.10.dist-info/METADATA,sha256=0FveCcFEZtR8CqXMNDG0VPhWurSVOtXOtEzsfPMfsik,44000
8
- otlmow_template-0.10.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
9
- otlmow_template-0.10.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
10
- otlmow_template-0.10.dist-info/RECORD,,