python-eigen-ingenuity 0.5.7b3__py3-none-any.whl → 0.5.7b4__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.
- modelbuilder/src/assetmodelbuilder.py +2 -1
- modelbuilder/src/configmanager.py +73 -56
- modelbuilder/src/csvcontentsmanager.py +11 -11
- modelbuilder/src/fileanalyser.py +9 -7
- modelbuilder/src/filemanager.py +90 -36
- modelbuilder/src/processors/nodefileprocessor.py +25 -43
- modelbuilder/src/processors/propertymanager.py +28 -20
- modelbuilder/src/processors/relationshipfileprocessor.py +21 -22
- modelbuilder/src/property.py +298 -0
- modelbuilder/src/queries/cypherbuilder.py +7 -5
- modelbuilder/src/queries/query.py +7 -5
- modelbuilder/src/queries/typedefs.py +10 -7
- modelbuilder/src/versionmanager.py +84 -70
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b4.dist-info}/METADATA +1 -1
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b4.dist-info}/RECORD +18 -17
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b4.dist-info}/WHEEL +0 -0
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b4.dist-info}/entry_points.txt +0 -0
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b4.dist-info}/top_level.txt +0 -0
|
@@ -61,7 +61,7 @@ def _convert_sys_argv_(func):
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
@_convert_sys_argv_
|
|
64
|
-
def build(path:str='.', config:str='config.ini', file:str='', query:list=[], preprocess:list=[], postprocess:list=[], delete_all:list=[], separator:str=';',
|
|
64
|
+
def build(path:str='.', config:str='config.ini', configsection:str='', file:str='', query:list=[], preprocess:list=[], postprocess:list=[], delete_all:list=[], separator:str=';',
|
|
65
65
|
start_from:int=1, end_at:int=1, no_versions:bool=False, no_system_properties:bool=False, ignore_nodes:bool=False, skip_duplicates:bool=False,
|
|
66
66
|
no_duplicates:bool=False, allow_blanks:list=[], batch:int=0, auth:bool=False, order:str='qnrc', filetypes:str='qnrc', primary_property:str='', required_labels:list=[],
|
|
67
67
|
required_properties:list=[], database:str='0', verify:bool=False, summarise:bool=False, show_queries:bool=False, show_returns:bool=False,
|
|
@@ -73,6 +73,7 @@ def build(path:str='.', config:str='config.ini', file:str='', query:list=[], pre
|
|
|
73
73
|
## Input Parameters
|
|
74
74
|
path: Location of the input and output files. Default is current folder
|
|
75
75
|
config: Name of the configuration file, default is config.ini in the folder from path parameter
|
|
76
|
+
configsection: Section of the config to use, if not DEFAULT
|
|
76
77
|
database: Database ID (as set in config file). Defaults to first entry
|
|
77
78
|
file: Space separated string list of input files
|
|
78
79
|
query: Space separated string list of queries to run
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
from configparser import ConfigParser, ExtendedInterpolation
|
|
2
2
|
import argparse
|
|
3
3
|
import sys
|
|
4
4
|
import re
|
|
@@ -21,6 +21,7 @@ class ConfigManager:
|
|
|
21
21
|
# Start with input parameters i.e. what files/commands to process, and where to find them
|
|
22
22
|
parser.add_argument('-p', '--path', default='.\\', help='Location of the input and output files. Default is current folder')
|
|
23
23
|
parser.add_argument('-c', '--config', default='config.ini', help='Name of the configuration file, default is config.ini in the folder given by -p')
|
|
24
|
+
parser.add_argument('-cs', '--configsection', default='', help='Section of the config file to use, if not DEFAULT')
|
|
24
25
|
parser.add_argument('-d', '--database', default='0', help='Database ID (as set in config file). Defaults to first entry')
|
|
25
26
|
parser.add_argument('-f', '--file', nargs='+', default='', help='List of input files (space separated, quoted with " where necessary)')
|
|
26
27
|
parser.add_argument('-q', '--query', nargs='+', default='', help='List of queries to run (space separated, quoted with " where necessary)')
|
|
@@ -73,6 +74,7 @@ class ConfigManager:
|
|
|
73
74
|
|
|
74
75
|
self.path = args.path
|
|
75
76
|
self.config_file = args.config
|
|
77
|
+
self.config_section = args.configsection
|
|
76
78
|
self.input_file_list = args.file
|
|
77
79
|
self.inline_query_list = args.query
|
|
78
80
|
self.preprocess_query_list = args.preprocess
|
|
@@ -149,8 +151,9 @@ class ConfigManager:
|
|
|
149
151
|
else:
|
|
150
152
|
settings.disable_azure_auth(True)
|
|
151
153
|
|
|
152
|
-
self.config =
|
|
154
|
+
self.config = ConfigParser(interpolation=ExtendedInterpolation())
|
|
153
155
|
self.config.read(config_file_name)
|
|
156
|
+
self.available_sections = ['DEFAULT'] + self.config.sections()
|
|
154
157
|
|
|
155
158
|
# Now look at controlling the order we process the files
|
|
156
159
|
# First remove illegal and duplicate inputs
|
|
@@ -187,12 +190,15 @@ class ConfigManager:
|
|
|
187
190
|
self.csv_to_labels = lm.validate_labels([args.csvtolabels])
|
|
188
191
|
self.csv_to_property_list = pm.validate_properties(args.csvtoproperties)
|
|
189
192
|
|
|
193
|
+
self.common_section = 'COMMON'
|
|
194
|
+
|
|
190
195
|
def read_query_config(self):
|
|
191
196
|
pass
|
|
192
197
|
|
|
193
198
|
def read_db_config(self):
|
|
199
|
+
database_section = self.common_section
|
|
194
200
|
database_index = None
|
|
195
|
-
database_name_list = self.get_config_value_list(
|
|
201
|
+
database_name_list = self.get_config_value_list(database_section, "DatabaseNames")
|
|
196
202
|
if isinstance(self.db_name, int):
|
|
197
203
|
database_num = self.db_name
|
|
198
204
|
else:
|
|
@@ -217,66 +223,72 @@ class ConfigManager:
|
|
|
217
223
|
|
|
218
224
|
if database_index is not None:
|
|
219
225
|
self.db_connection_dict = {}
|
|
220
|
-
self.db_connection_dict['url'] = self.get_config_value_list(
|
|
221
|
-
self.db_connection_dict['user'] = self.get_config_value_list(
|
|
222
|
-
self.db_connection_dict['password'] = self.get_config_value_list(
|
|
226
|
+
self.db_connection_dict['url'] = self.get_config_value_list(database_section, "urls")[database_index]
|
|
227
|
+
self.db_connection_dict['user'] = self.get_config_value_list(database_section, "users")[database_index]
|
|
228
|
+
self.db_connection_dict['password'] = self.get_config_value_list(database_section, "passwords")[database_index]
|
|
223
229
|
print(f'Connecting to {database_name_list[database_index]}')
|
|
224
230
|
|
|
231
|
+
|
|
225
232
|
def read_version_config(self):
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
233
|
+
version_section = self.common_section
|
|
234
|
+
version_mode = self.get_config_value(version_section, "Versions", "on")
|
|
235
|
+
self.version_labels_list = lm.validate_labels(self.get_config_value_list(version_section, "VersionLabels", "!Current,Version"))
|
|
236
|
+
self.frozen_labels_list = lm.validate_labels(self.get_config_value_list(version_section, "FrozenLabels", ""))
|
|
237
|
+
self.version_labels_list = lm.validate_labels(self.get_config_value_list(version_section, "VersionLabels", "!Current,Version"))
|
|
238
|
+
self.version_prefix = self.get_config_value(version_section, "VersionLabelPrefix", "")
|
|
239
|
+
self.version_counter = pm.validate_properties(self.get_config_value(version_section, "VersionCounterProperty", "versionCount"))
|
|
240
|
+
self.version_number = pm.validate_properties(self.get_config_value(version_section, "VersionNumberProperty", "versionNumber"))
|
|
241
|
+
self.first_version_property = pm.validate_properties(self.get_config_value(version_section, "FirstVersionProperty", "firstVersion"))
|
|
242
|
+
self.last_version_property = pm.validate_properties(self.get_config_value(version_section, "LastVersionProperty", "lastVersion"))
|
|
243
|
+
self.version_relationship = rm.validate_relationships(self.get_config_value(version_section, "VersionRelationship", "has_version"))
|
|
244
|
+
self.next_version_relationship = rm.validate_relationships(self.get_config_value(version_section, "NextVersionRelationship", "next_version"))
|
|
245
|
+
self.version_valid_from_property = pm.validate_properties(self.get_config_value(version_section, "VersionValidFromProperty", "validFrom"))
|
|
246
|
+
self.version_valid_to_property = pm.validate_properties(self.get_config_value(version_section, "VersionValidToProperty", "validTo"))
|
|
247
|
+
|
|
248
|
+
if version_mode.lower() != 'on':
|
|
241
249
|
self.no_version = True
|
|
242
250
|
|
|
243
251
|
def read_csv_config(self):
|
|
244
|
-
self.primary_property =
|
|
245
|
-
self.default_data_type = self.get_config_value(
|
|
246
|
-
self.required_labels_list = lm.combine_required_labels(self.get_config_value_list(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
self.primary_property = {s: self.primary_property_override or self.get_config_value(s, "PrimaryProperty", "node") for s in self.available_sections}
|
|
253
|
+
self.default_data_type = {s: self.get_config_value(s, "DataType", "") for s in self.available_sections}
|
|
254
|
+
self.required_labels_list = {s: lm.combine_required_labels(self.get_config_value_list(s, "RequiredLabels", ""), self.required_labels_override) for s in self.available_sections}
|
|
255
|
+
|
|
256
|
+
self.unique_id_property = {s: self.get_config_value(s, "UniqueIDProperty", "uuid") for s in self.available_sections}
|
|
257
|
+
self.creation_time_property = {s: self.get_config_value(s, "CreationTime", "creationTime") for s in self.available_sections}
|
|
258
|
+
self.update_time_property = {s: self.get_config_value(s, "UpdateTime", "updateTime") for s in self.available_sections}
|
|
259
|
+
|
|
260
|
+
self.label_alias_list = {s: lm.validate_labels(self.get_config_value_list(s, "Labels", "label")) for s in self.available_sections}
|
|
261
|
+
self.node_alias_list = {s: self.get_config_value_list(s, "Nodes", "node") + [self.primary_property[s]] for s in self.available_sections}
|
|
262
|
+
self.from_alias_list = {s: self.get_config_value_list(s, "FromNodes", "from,start") for s in self.available_sections}
|
|
263
|
+
self.from_label_alias_list = {s: lm.validate_labels(self.get_config_value_list(s, "FromLabels", "fromLabel")) for s in self.available_sections}
|
|
264
|
+
self.to_alias_list = {s: self.get_config_value_list(s, "ToNodes", "to,end") for s in self.available_sections}
|
|
265
|
+
self.to_label_alias_list = {s: lm.validate_labels(self.get_config_value_list(s, "ToLabels", "toLabel")) for s in self.available_sections}
|
|
266
|
+
self.relationship_alias_list = {s: rm.validate_relationships(self.get_config_value_list(s, "Relationships", "relationship")) for s in self.available_sections}
|
|
267
|
+
|
|
268
|
+
self.required_properties_dict = {}
|
|
269
|
+
self.unrequired_properties_list = {}
|
|
270
|
+
|
|
271
|
+
self.no_system_properties = self.get_config_value(self.common_section, "SystemProperties", "on").lower() != 'on' or self.no_system_properties
|
|
272
|
+
if self.no_system_properties:
|
|
251
273
|
self.no_version = True
|
|
252
|
-
self.no_system_properties = True
|
|
253
|
-
self.unique_id_property = pm.validate_properties(self.get_config_value("Model", "UniqueIDProperty", "uuid"))
|
|
254
|
-
self.creation_time_property = pm.validate_properties(self.get_config_value("Model", "CreationTime", "creationTime"))
|
|
255
|
-
self.update_time_property = pm.validate_properties(self.get_config_value("Model", "UpdateTime", "updateTime"))
|
|
256
|
-
header_mappings = self.get_config_value_list("Model", "Mappings", "")
|
|
257
|
-
|
|
258
|
-
self.label_alias_list = lm.validate_labels(self.get_config_value_list("Aliases", "Labels", "label"))
|
|
259
|
-
self.node_alias_list = pm.validate_properties(self.get_config_value_list("Aliases", "Nodes", "node") + [self.primary_property])
|
|
260
|
-
self.from_alias_list = pm.validate_properties(self.get_config_value_list("Aliases", "FromNodes", "from,start"))
|
|
261
|
-
self.from_label_alias_list = lm.validate_labels(self.get_config_value_list("Aliases", "FromLabels", "fromLabel"))
|
|
262
|
-
self.to_alias_list = pm.validate_properties(self.get_config_value_list("Aliases", "ToNodes", "to,end"))
|
|
263
|
-
self.to_label_alias_list = lm.validate_labels(self.get_config_value_list("Aliases", "ToLabels", "toLabel"))
|
|
264
|
-
self.relationship_alias_list = rm.validate_relationships(self.get_config_value_list("Aliases", "Relationships", "relationship"))
|
|
265
274
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
header_mappings = {s: self.get_config_value_list(s, "Mappings", "") for s in self.available_sections}
|
|
276
|
+
alias_header_mappings = {s: [i + '->' + self.primary_property[s] for i in self.node_alias_list[s] if i != self.primary_property[s]] for s in self.available_sections}
|
|
277
|
+
self.header_mappings_dict = {}
|
|
278
|
+
self.alias_header_mappings_dict = {}
|
|
279
|
+
|
|
280
|
+
for s in self.available_sections:
|
|
281
|
+
self.required_properties_dict[s], self.unrequired_properties_list[s] = pm.combine_required_properties(self.get_config_value_list(s, "RequiredProperties", ""), [self.required_properties_override], self.default_data_type[s])
|
|
282
|
+
|
|
283
|
+
try:
|
|
284
|
+
self.header_mappings_dict[s] = {i.replace('=', '->').split('->')[0].rstrip(): i.replace('=', '->').split('->')[1].lstrip() for i in header_mappings[s]}
|
|
285
|
+
except:
|
|
286
|
+
self.header_mappings_dict[s] = {}
|
|
287
|
+
|
|
288
|
+
try:
|
|
289
|
+
self.alias_header_mappings_dict[s] = {i.replace('=', '->').split('->')[0].rstrip(): i.replace('=', '->').split('->')[1].lstrip() for i in alias_header_mappings[s]}
|
|
290
|
+
except:
|
|
291
|
+
self.alias_header_mappings_dict[s] = {}
|
|
280
292
|
|
|
281
293
|
def get_error_list(self):
|
|
282
294
|
return self.error_list
|
|
@@ -291,7 +303,6 @@ class ConfigManager:
|
|
|
291
303
|
else:
|
|
292
304
|
self.error_list += [f'No value found for {option} in the configuration file']
|
|
293
305
|
raw_value = ''
|
|
294
|
-
|
|
295
306
|
# Reformat from a single string of comma separated values to a List (of strings)
|
|
296
307
|
# removing leading and trailing spaces while we're at it
|
|
297
308
|
if raw_value:
|
|
@@ -314,6 +325,12 @@ class ConfigManager:
|
|
|
314
325
|
def get_default_path(self):
|
|
315
326
|
return self.path
|
|
316
327
|
|
|
328
|
+
def get_config_section(self):
|
|
329
|
+
return self.config_section
|
|
330
|
+
|
|
331
|
+
def get_available_sections(self):
|
|
332
|
+
return self.available_sections
|
|
333
|
+
|
|
317
334
|
def get_input_file_list(self):
|
|
318
335
|
return self.input_file_list
|
|
319
336
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assetmodelutilities as amu
|
|
2
2
|
import processors.propertymanager as pm
|
|
3
|
-
|
|
3
|
+
from property import Neo4jProperty
|
|
4
4
|
|
|
5
5
|
class CSVContentsManager:
|
|
6
6
|
|
|
@@ -25,16 +25,16 @@ class CSVContentsManager:
|
|
|
25
25
|
header_parts = header.split(':')
|
|
26
26
|
key = header_parts[0].replace('\ufeff', '')
|
|
27
27
|
if len(header_parts) == 3:
|
|
28
|
-
format =
|
|
29
|
-
type =
|
|
28
|
+
format = header_parts[1]
|
|
29
|
+
type = header_parts[2]
|
|
30
30
|
elif len(header_parts) == 2:
|
|
31
31
|
part = header_parts[1]
|
|
32
32
|
if part and part in amu.all_types:
|
|
33
|
-
type =
|
|
33
|
+
type = part
|
|
34
34
|
else:
|
|
35
|
-
format =
|
|
35
|
+
format = part
|
|
36
36
|
if format == '' and default_data_type != '':
|
|
37
|
-
format =
|
|
37
|
+
format = default_data_type
|
|
38
38
|
|
|
39
39
|
return key, format, type
|
|
40
40
|
|
|
@@ -72,8 +72,8 @@ class CSVContentsManager:
|
|
|
72
72
|
self.formats += [this_format]
|
|
73
73
|
self.types += [this_type]
|
|
74
74
|
|
|
75
|
-
self.unmapped_keys =
|
|
76
|
-
self.mapped_keys =
|
|
75
|
+
self.unmapped_keys = unmapped_keys
|
|
76
|
+
self.mapped_keys = mapped_keys
|
|
77
77
|
|
|
78
78
|
def get_row_count(self):
|
|
79
79
|
return len(self.data_list)
|
|
@@ -121,17 +121,17 @@ class CSVContentsManager:
|
|
|
121
121
|
# Return the values in the given row, for the columns in the provided list (skips empty values)
|
|
122
122
|
# Returned as a List (of strings)
|
|
123
123
|
this_row = self.data_list[row_number]
|
|
124
|
-
properties_list = [
|
|
124
|
+
properties_list = [Neo4jProperty(self.mapped_keys[column], this_row[column], self.formats[column]) for column in column_numbers if len(this_row[column])]
|
|
125
125
|
return properties_list
|
|
126
126
|
|
|
127
127
|
def get_property_values_dict(self, row_number, column_numbers, allow_blank_property_list, default_key='', prefix=''):
|
|
128
128
|
this_row = self.data_list[row_number]
|
|
129
129
|
split_values = [this_row[column].split('::') for column in column_numbers]
|
|
130
|
-
this_list = {prefix + (self.mapped_keys[column] or default_key) + self.
|
|
130
|
+
this_list = {prefix + (self.mapped_keys[column] or default_key): Neo4jProperty(prefix + (self.mapped_keys[column] or default_key), this_row[column], self.formats[column]) if len(split_values[count]) == 1 else {prefix + split_values[count][0]: Neo4jProperty(prefix + split_values[count][0], split_values[count][1], self.formats[column])} for count, column in enumerate(column_numbers) if this_row[column] or self.mapped_keys[column] in allow_blank_property_list or allow_blank_property_list == []}
|
|
131
131
|
return this_list
|
|
132
132
|
|
|
133
133
|
def get_property_values_list(self, row_number, column_numbers, default_key='', override_key=''):
|
|
134
134
|
this_row = self.data_list[row_number]
|
|
135
135
|
split_values = [this_row[column].split('::') for column in column_numbers]
|
|
136
|
-
this_list = [
|
|
136
|
+
this_list = [Neo4jProperty((override_key or self.mapped_keys[column] or default_key), this_row[column], self.formats[column]) if len(split_values[count]) == 1 else Neo4jProperty(split_values[count][0], split_values[count][1], self.formats[column]) for count, column in enumerate(column_numbers) if this_row[column]]
|
|
137
137
|
return this_list
|
modelbuilder/src/fileanalyser.py
CHANGED
|
@@ -6,17 +6,19 @@ import assetmodelutilities as amu
|
|
|
6
6
|
|
|
7
7
|
class FileAnalyser():
|
|
8
8
|
|
|
9
|
-
def __init__(self, config):
|
|
9
|
+
def __init__(self, config, section):
|
|
10
10
|
self.separator = config.get_separator()
|
|
11
11
|
self.def_path = config.get_default_path()
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
self.
|
|
13
|
+
header_mappings, alias_mappings = config.get_header_mappings()
|
|
14
|
+
self.header_mappings = header_mappings[section]
|
|
15
|
+
self.alias_mappings = alias_mappings[section]
|
|
16
|
+
self.default_data_type = config.get_default_data_type()[section]
|
|
15
17
|
|
|
16
|
-
self.node_alias = config.get_node_alias()
|
|
17
|
-
self.from_node_alias = config.get_from_alias()
|
|
18
|
-
self.to_node_alias = config.get_to_alias()
|
|
19
|
-
self.relationship_alias = config.get_relationship_alias()
|
|
18
|
+
self.node_alias = config.get_node_alias()[section]
|
|
19
|
+
self.from_node_alias = config.get_from_alias()[section]
|
|
20
|
+
self.to_node_alias = config.get_to_alias()[section]
|
|
21
|
+
self.relationship_alias = config.get_relationship_alias()[section]
|
|
20
22
|
self.ignore_nodes = config.get_ignore_nodes()
|
|
21
23
|
|
|
22
24
|
self.node_types = amu.node_types
|
modelbuilder/src/filemanager.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
|
|
3
2
|
from fileanalyser import FileAnalyser
|
|
4
3
|
from processors.cypherfileprocessor import CypherFileProcessor
|
|
5
4
|
from processors.nodefileprocessor import NodeFileProcessor
|
|
@@ -13,7 +12,6 @@ import os
|
|
|
13
12
|
class FileManager:
|
|
14
13
|
|
|
15
14
|
def __init__(self, config_manager):
|
|
16
|
-
self.fileanalyser = FileAnalyser(config_manager)
|
|
17
15
|
self.config_manager = config_manager
|
|
18
16
|
self.validation_mode = config_manager.in_validation_mode()
|
|
19
17
|
self.report_queries = config_manager.get_show_query()
|
|
@@ -33,19 +31,44 @@ class FileManager:
|
|
|
33
31
|
self.file_not_found_list = []
|
|
34
32
|
self.unrecognised_file_type_list = []
|
|
35
33
|
self.incorrect_file_list = []
|
|
34
|
+
self.incorrect_section_list = []
|
|
36
35
|
self.incomplete_file_list = []
|
|
37
36
|
self.incomplete_file_errors = []
|
|
38
37
|
|
|
39
38
|
# And a list of lists for the queries in specified priority order
|
|
40
39
|
self.valid_file_list = [[], [], [], [], [], []]
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
self.invalid_file_count = 0
|
|
42
|
+
|
|
43
|
+
self.config_section = config_manager.get_config_section()
|
|
44
|
+
self.section = self.config_section
|
|
44
45
|
|
|
45
|
-
self.
|
|
46
|
+
self.file_analysers = {s: FileAnalyser(config_manager, s) for s in config_manager.get_available_sections()}
|
|
47
|
+
self.version_managers = {s: VersionManager(config_manager, s) for s in config_manager.get_available_sections()}
|
|
46
48
|
|
|
49
|
+
def check_section(self, in_file, empty_section_response):
|
|
50
|
+
file = in_file.strip()
|
|
51
|
+
if file.startswith('#'):
|
|
52
|
+
filename = file
|
|
53
|
+
section = None
|
|
54
|
+
else:
|
|
55
|
+
if '[' in file and ']' in file:
|
|
56
|
+
# New section directive found
|
|
57
|
+
section_start = file.index('[')
|
|
58
|
+
section_end = file.index(']')
|
|
59
|
+
section = file[section_start + 1:section_end]
|
|
60
|
+
filename = file[section_end + 1:].strip()
|
|
61
|
+
if filename == '':
|
|
62
|
+
self.section = section or self.config_section
|
|
63
|
+
elif section == '':
|
|
64
|
+
section = empty_section_response
|
|
65
|
+
else:
|
|
66
|
+
section = self.section
|
|
67
|
+
filename = in_file
|
|
47
68
|
|
|
48
|
-
|
|
69
|
+
return filename, section
|
|
70
|
+
|
|
71
|
+
def analyse_a_file(self, filename, section):
|
|
49
72
|
a_file = filename.replace('\n', '')
|
|
50
73
|
a_file_split = a_file.split('.')
|
|
51
74
|
if len(a_file_split) > 1:
|
|
@@ -54,13 +77,19 @@ class FileManager:
|
|
|
54
77
|
file_type = ''
|
|
55
78
|
match file_type:
|
|
56
79
|
case 'csv':
|
|
57
|
-
|
|
80
|
+
if section == None:
|
|
81
|
+
file, this_section = self.check_section(a_file, '')
|
|
82
|
+
else:
|
|
83
|
+
file = a_file
|
|
84
|
+
this_section = section
|
|
85
|
+
self.analyse_csv_file(file, this_section)
|
|
58
86
|
case 'cypher' | 'qry':
|
|
59
87
|
self.analyse_cypher_file(a_file)
|
|
60
88
|
case 'lst':
|
|
61
|
-
self.analyse_lst_file(a_file)
|
|
89
|
+
self.analyse_lst_file(a_file, section)
|
|
62
90
|
case _:
|
|
63
91
|
self.unrecognised_file_type_list.append(a_file)
|
|
92
|
+
self.invalid_file_count += 1
|
|
64
93
|
|
|
65
94
|
def add_file_to_process_list(self, file_processor, file_type):
|
|
66
95
|
if file_type in ['pre', 'pre-file', 'post', 'post-file']:
|
|
@@ -74,18 +103,24 @@ class FileManager:
|
|
|
74
103
|
else:
|
|
75
104
|
info_message(file_processor.get_filename(), ' not processed as requested')
|
|
76
105
|
|
|
77
|
-
def analyse_lst_file(self, filename):
|
|
106
|
+
def analyse_lst_file(self, filename, def_section=''):
|
|
78
107
|
|
|
79
108
|
f_name = amu.find_file(self.config_manager.get_default_path(), filename)
|
|
109
|
+
current_section = self.section
|
|
110
|
+
self.section = def_section
|
|
80
111
|
if f_name is not None:
|
|
81
|
-
|
|
82
|
-
for
|
|
83
|
-
if not
|
|
84
|
-
self.
|
|
85
|
-
|
|
112
|
+
lst_file = open(f_name, 'r')
|
|
113
|
+
for a_file in lst_file:
|
|
114
|
+
if not a_file.startswith('#') and a_file != '\n':
|
|
115
|
+
file, section = self.check_section(a_file, self.config_section)
|
|
116
|
+
if file != '':
|
|
117
|
+
self.analyse_a_file(file, section)
|
|
118
|
+
lst_file.close()
|
|
86
119
|
else:
|
|
87
120
|
warning_message(f'{filename} not found')
|
|
88
121
|
|
|
122
|
+
self.section = current_section
|
|
123
|
+
|
|
89
124
|
def analyse_files(self):
|
|
90
125
|
|
|
91
126
|
message('Checking file types...')
|
|
@@ -133,7 +168,7 @@ class FileManager:
|
|
|
133
168
|
a_file_split = a_file.split(',')
|
|
134
169
|
for a_split_file in a_file_split:
|
|
135
170
|
if a_split_file != '':
|
|
136
|
-
self.analyse_a_file(a_split_file.strip())
|
|
171
|
+
self.analyse_a_file(a_split_file.strip(), None)
|
|
137
172
|
|
|
138
173
|
query_list = self.config_manager.get_inline_query_list()
|
|
139
174
|
for a_query in query_list:
|
|
@@ -165,29 +200,44 @@ class FileManager:
|
|
|
165
200
|
self.add_file_to_process_list(this_file_processor, 'r')
|
|
166
201
|
case 'both':
|
|
167
202
|
self.both_file_list.append(this_file_processor.get_filename())
|
|
203
|
+
self.invalid_file_count += 1
|
|
168
204
|
case 'neither':
|
|
169
205
|
self.neither_file_list.append(this_file_processor.get_filename())
|
|
206
|
+
self.invalid_file_count += 1
|
|
170
207
|
case 'fnf':
|
|
171
208
|
self.file_not_found_list.append(this_file_processor.get_filename())
|
|
209
|
+
self.invalid_file_count += 1
|
|
172
210
|
case 'incorrect file format':
|
|
173
211
|
self.incorrect_file_list.append(this_file_processor.get_filename())
|
|
212
|
+
self.invalid_file_count += 1
|
|
174
213
|
case 'incomplete row(s)':
|
|
175
214
|
self.incomplete_file_list.append([this_file_processor.get_filename(), file_errors])
|
|
215
|
+
self.invalid_file_count += 1
|
|
216
|
+
case 'invalid config section':
|
|
217
|
+
self.incorrect_section_list.append(this_file_processor.get_filename())
|
|
218
|
+
self.invalid_file_count += 1
|
|
176
219
|
case _:
|
|
177
220
|
pass
|
|
178
221
|
|
|
179
|
-
def analyse_csv_file(self, csv_file):
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if this_csv_file_type == 'nodes':
|
|
184
|
-
this_csv_file_processor = NodeFileProcessor(csv_file, self.config_manager, csv_contents)
|
|
185
|
-
elif this_csv_file_type == 'relationships':
|
|
186
|
-
this_csv_file_processor = RelationshipFileProcessor(csv_file, self.config_manager, csv_contents)
|
|
187
|
-
else:
|
|
222
|
+
def analyse_csv_file(self, csv_file, config_section):
|
|
223
|
+
if not config_section:
|
|
224
|
+
config_section = 'DEFAULT'
|
|
225
|
+
if config_section not in self.config_manager.get_available_sections():
|
|
188
226
|
# Use NodeFileProcessor as placeholder. It won't be used, other than to process the errors
|
|
189
|
-
this_csv_file_processor = NodeFileProcessor(csv_file, self.config_manager,
|
|
190
|
-
|
|
227
|
+
this_csv_file_processor = NodeFileProcessor(csv_file, self.config_manager, None, 'DEFAULT')
|
|
228
|
+
self.add_file_to_list(this_csv_file_processor, 'invalid config section', [])
|
|
229
|
+
else:
|
|
230
|
+
# Analyse each of the specified input .csv files to determine if they contain Nodes or Relationships
|
|
231
|
+
# If the file doesn't have a valid combination of columns (or is missing) they are placed in the appropriate list
|
|
232
|
+
this_csv_file_type, csv_contents, file_errors = self.file_analysers[config_section].determine_file_type(csv_file, 'csv')
|
|
233
|
+
if this_csv_file_type == 'nodes':
|
|
234
|
+
this_csv_file_processor = NodeFileProcessor(csv_file, self.config_manager, csv_contents, config_section)
|
|
235
|
+
elif this_csv_file_type == 'relationships':
|
|
236
|
+
this_csv_file_processor = RelationshipFileProcessor(csv_file, self.config_manager, csv_contents, config_section)
|
|
237
|
+
else:
|
|
238
|
+
# Use NodeFileProcessor as placeholder. It won't be used, other than to process the errors
|
|
239
|
+
this_csv_file_processor = NodeFileProcessor(csv_file, self.config_manager, csv_contents, config_section)
|
|
240
|
+
self.add_file_to_list(this_csv_file_processor, this_csv_file_type, file_errors)
|
|
191
241
|
|
|
192
242
|
def analyse_cypher_file(self, query_file):
|
|
193
243
|
this_file_processor = CypherFileProcessor(query_file, self.config_manager)
|
|
@@ -198,19 +248,21 @@ class FileManager:
|
|
|
198
248
|
# Report on the missing or faulty files
|
|
199
249
|
self.process_invalid_files()
|
|
200
250
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
251
|
+
if self.invalid_file_count == 0 or not self.stop_on_failure:
|
|
252
|
+
# Finally, process the files that we can
|
|
253
|
+
self.all_results = QueryResult(False)
|
|
254
|
+
self.all_version_results = QueryResult(False)
|
|
255
|
+
queries_processed = self.process_valid_files(db_connector)
|
|
256
|
+
info_message(f'{queries_processed} queries processed in total')
|
|
257
|
+
self.all_results.print_results('Total updates made: ')
|
|
258
|
+
self.all_version_results.print_results('Total version updates made: ', '')
|
|
208
259
|
|
|
209
260
|
def process_invalid_files(self):
|
|
210
261
|
self.process_not_found_files()
|
|
211
262
|
self.process_unrecognised_file_type_files()
|
|
212
263
|
self.process_incorrect_files()
|
|
213
264
|
self.process_incomplete_files()
|
|
265
|
+
self.process_incorrect_sections()
|
|
214
266
|
self.process_neither_found_files()
|
|
215
267
|
self.process_both_files()
|
|
216
268
|
|
|
@@ -226,6 +278,10 @@ class FileManager:
|
|
|
226
278
|
for file in self.incorrect_file_list:
|
|
227
279
|
error_message(f'{file} is not a correctly formatted .csv file - file not processed')
|
|
228
280
|
|
|
281
|
+
def process_incorrect_sections(self):
|
|
282
|
+
for file in self.incorrect_section_list:
|
|
283
|
+
error_message(f'{file} has an invalid config section - file not processed')
|
|
284
|
+
|
|
229
285
|
def process_incomplete_files(self):
|
|
230
286
|
for file in self.incomplete_file_list:
|
|
231
287
|
error_message(f'{file[0]} has incomplete data in rows {file[1]} - file not processed')
|
|
@@ -273,8 +329,6 @@ class FileManager:
|
|
|
273
329
|
return num_queries
|
|
274
330
|
|
|
275
331
|
def process_file(self, file_to_process, file_processor, db_connector):
|
|
276
|
-
if not self.no_versions:
|
|
277
|
-
self.version_manager.set_db_connector(db_connector)
|
|
278
332
|
node_queries = 0
|
|
279
333
|
num_errors = 0
|
|
280
334
|
error_list = []
|
|
@@ -333,7 +387,7 @@ class FileManager:
|
|
|
333
387
|
version_result = None
|
|
334
388
|
if query.type == 'node':
|
|
335
389
|
if not self.no_versions:
|
|
336
|
-
update_current_node, version_result = self.
|
|
390
|
+
update_current_node, version_result = self.version_managers[query.section].make_new_version_of_node(query, db_connector)
|
|
337
391
|
if update_current_node:
|
|
338
392
|
version_results.combine_results(version_result)
|
|
339
393
|
result = db_connector.execute(query, query_count)
|