python-eigen-ingenuity 0.5.7b3__py3-none-any.whl → 0.5.7b5__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.
- eigeningenuity/__init__.py +2 -2
- eigeningenuity/auth.py +66 -42
- eigeningenuity/historianmulti.py +2 -10
- eigeningenuity/settings.py +30 -1
- eigeningenuity/util.py +18 -7
- 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.7b5.dist-info}/METADATA +1 -1
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b5.dist-info}/RECORD +23 -22
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b5.dist-info}/WHEEL +0 -0
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b5.dist-info}/entry_points.txt +0 -0
- {python_eigen_ingenuity-0.5.7b3.dist-info → python_eigen_ingenuity-0.5.7b5.dist-info}/top_level.txt +0 -0
eigeningenuity/__init__.py
CHANGED
|
@@ -23,7 +23,7 @@ from eigeningenuity.events import get_eventlog
|
|
|
23
23
|
from eigeningenuity.assetmodel import get_assetmodel
|
|
24
24
|
from eigeningenuity.smartdash import get_smartdash
|
|
25
25
|
from eigeningenuity.sql import get_sql
|
|
26
|
-
from eigeningenuity.settings import set_azure_client_id,
|
|
26
|
+
from eigeningenuity.settings import set_azure_tenant_id, set_azure_client_id, set_azure_client_secret, disable_azure_auth, disable_auth_token_cache, clear_auth_token_cache, set_api_token, set_auth_scope
|
|
27
27
|
|
|
28
|
-
__all__ = ["get_historian", "get_historian_multi", "get_assetmodel", "get_elastic", "get_sql", "get_eventlog", "get_smartdash", "list_historians", "EigenServer", "set_azure_client_id", "
|
|
28
|
+
__all__ = ["get_historian", "get_historian_multi", "get_assetmodel", "get_elastic", "get_sql", "get_eventlog", "get_smartdash", "list_historians", "EigenServer", "set_azure_tenant_id", "set_azure_client_id", "set_azure_client_secret", "disable_azure_auth", "disable_auth_token_cache", "clear_auth_token_cache", "set_api_token", "set_auth_scope"]
|
|
29
29
|
__version__ = pkg_resources.require("python-eigen-ingenuity")[0].version
|
eigeningenuity/auth.py
CHANGED
|
@@ -19,6 +19,7 @@ def decrypt(data,key):
|
|
|
19
19
|
def _authenticate_azure_user(baseurl):
|
|
20
20
|
global url
|
|
21
21
|
url = baseurl
|
|
22
|
+
|
|
22
23
|
if settings._token_cache_enabled_:
|
|
23
24
|
global cache
|
|
24
25
|
try:
|
|
@@ -43,54 +44,77 @@ def _authenticate_azure_user(baseurl):
|
|
|
43
44
|
|
|
44
45
|
tenant_id = settings._azure_tenant_id_
|
|
45
46
|
client_id = settings._azure_client_id_
|
|
47
|
+
client_secret = settings._azure_client_secret_
|
|
46
48
|
authority = f'https://login.microsoftonline.com/{tenant_id}'
|
|
47
|
-
scope=[f"{baseurl}/user_impersonation"]
|
|
48
|
-
|
|
49
|
-
app = msal.PublicClientApplication(
|
|
50
|
-
client_id=client_id,
|
|
51
|
-
authority=authority,
|
|
52
|
-
token_cache=cache
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
result=None
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
50
|
+
if client_secret: # USE CLIENT_CREDENTIALS FLOW
|
|
51
|
+
scope=[f"{baseurl}/.default"]
|
|
52
|
+
# Create a confidential client application
|
|
53
|
+
app = msal.ConfidentialClientApplication(
|
|
54
|
+
client_id,
|
|
55
|
+
authority=authority,
|
|
56
|
+
client_credential=client_secret
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Acquire a token
|
|
60
|
+
result = app.acquire_token_for_client(scopes=scope)
|
|
61
|
+
|
|
62
|
+
if "access_token" in result:
|
|
63
|
+
access_token = (result["access_token"])
|
|
64
|
+
else:
|
|
65
|
+
print("Error acquiring token:")
|
|
66
|
+
print(result.get("error"))
|
|
67
|
+
print(result.get("error_description"))
|
|
68
|
+
print(result.get("correlation_id")) # You might want to save this in case of reporting a bug
|
|
69
|
+
|
|
70
|
+
else: # USE INTERACTIVE FLOW
|
|
71
|
+
|
|
72
|
+
scope=[f"{baseurl}/{settings._auth_scope_}"]
|
|
73
|
+
|
|
74
|
+
app = msal.PublicClientApplication(
|
|
75
|
+
client_id=client_id,
|
|
76
|
+
authority=authority,
|
|
77
|
+
token_cache=cache
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# We now check the cache to see
|
|
81
|
+
# whether we already have some accounts that the end user already used to sign in before.
|
|
82
|
+
accounts = app.get_accounts()
|
|
83
|
+
if accounts:
|
|
84
|
+
account = 0
|
|
85
|
+
# If so, you could then somehow display these accounts and let end user choose
|
|
86
|
+
if len(accounts) >= 2:
|
|
87
|
+
print("Found Multiple Users in Cache")
|
|
88
|
+
while True:
|
|
89
|
+
for idx,a in enumerate(accounts):
|
|
90
|
+
print(f'{idx}: {a["username"]}')
|
|
91
|
+
try:
|
|
92
|
+
account = int(input("Enter the number of the account you want to use:\n"))
|
|
93
|
+
if account not in list(range(len(accounts))):
|
|
94
|
+
print("That is not a valid option!")
|
|
95
|
+
else:
|
|
96
|
+
break
|
|
97
|
+
except:
|
|
71
98
|
print("That is not a valid option!")
|
|
72
|
-
else:
|
|
73
|
-
break
|
|
74
|
-
except:
|
|
75
|
-
print("That is not a valid option!")
|
|
76
99
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
100
|
+
# Assuming the end user chose this one
|
|
101
|
+
chosen = accounts[account]
|
|
102
|
+
# Now let's try to find a token in cache for this account
|
|
103
|
+
result = app.acquire_token_silent(scope, account=chosen)
|
|
81
104
|
|
|
82
105
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
106
|
+
if not result:
|
|
107
|
+
# So no suitable token exists in cache. Let's get a new one from Azure AD.
|
|
108
|
+
settings.clear_auth_token_cache()
|
|
109
|
+
result = app.acquire_token_interactive(scope,auth_uri_callback=_backup_auth_azure_user)
|
|
87
110
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
if "access_token" in result:
|
|
112
|
+
access_token = (result["access_token"]) # Yay!
|
|
113
|
+
else:
|
|
114
|
+
print("Error acquiring token:")
|
|
115
|
+
print(result.get("error"))
|
|
116
|
+
print(result.get("error_description"))
|
|
117
|
+
print(result.get("correlation_id")) # You may need this when reporting a bug
|
|
94
118
|
|
|
95
119
|
# Make requests to the Java API using the obtained access token
|
|
96
120
|
return {
|
|
@@ -127,7 +151,7 @@ def _backup_auth_azure_user(_uri):
|
|
|
127
151
|
|
|
128
152
|
|
|
129
153
|
authority = f'https://login.microsoftonline.com/{settings._azure_tenant_id_}'
|
|
130
|
-
scope=[f"{baseurl}/
|
|
154
|
+
scope=[f"{baseurl}/{settings._auth_scope_}"]
|
|
131
155
|
client_id = settings._azure_client_id_
|
|
132
156
|
|
|
133
157
|
|
eigeningenuity/historianmulti.py
CHANGED
|
@@ -17,11 +17,7 @@ eigeningenuity.core) or a full URL to a JSON Bridge Historian instance.
|
|
|
17
17
|
print(asctime(time.gmtime(dp['timestamp'])), dp['value'])
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
-
import
|
|
21
|
-
import math
|
|
22
|
-
import logging
|
|
23
|
-
import csv
|
|
24
|
-
import requests
|
|
20
|
+
import requests, warnings
|
|
25
21
|
from urllib.parse import quote as urlquote
|
|
26
22
|
from typing import Union
|
|
27
23
|
from datetime import datetime
|
|
@@ -32,10 +28,6 @@ from eigeningenuity.core import get_default_server, EigenServer
|
|
|
32
28
|
from eigeningenuity.util import force_list, time_to_epoch_millis, EigenException, \
|
|
33
29
|
multi_response_to_df, merge_tags_from_response, update_keys, _do_historian_multi_request, format_output
|
|
34
30
|
|
|
35
|
-
from urllib3.exceptions import InsecureRequestWarning
|
|
36
|
-
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
|
37
|
-
|
|
38
|
-
|
|
39
31
|
class HistorianMulti (object):
|
|
40
32
|
"""A Historian which talks the Eigen Historian Json Bridge protocol.
|
|
41
33
|
"""
|
|
@@ -460,7 +452,7 @@ def createPoint(value:Union[int,float],timestamp:Union[int,str,datetime],status:
|
|
|
460
452
|
raise EigenException("Bad Status Parameter, must be 'OK' or 'BAD'")
|
|
461
453
|
return {"value": value, "timestamp": timestamp, "status": status}
|
|
462
454
|
|
|
463
|
-
def get_historian_multi(eigenserver
|
|
455
|
+
def get_historian_multi(eigenserver = None, default_historian = None) -> HistorianMulti:
|
|
464
456
|
"""Instantiate a historian object for the given instance.
|
|
465
457
|
|
|
466
458
|
Args:
|
eigeningenuity/settings.py
CHANGED
|
@@ -5,7 +5,9 @@ _token_cache_enabled_ = True
|
|
|
5
5
|
_azure_auth_enabled_ = True
|
|
6
6
|
_azure_tenant_id_ = os.getenv("EIGEN_INGENUITY_TENANT_ID", "74efa022-e6d6-42ad-bc15-edc76c525bde")
|
|
7
7
|
_azure_client_id_ = os.getenv("EIGEN_INGENUITY_CLIENT_ID", "c2b9aa13-e178-4dde-bc2c-b6cc4c8391d2")
|
|
8
|
+
_azure_client_secret_ = os.getenv("EIGEN_INGENUITY_CLIENT_SECRET", None)
|
|
8
9
|
_api_token_value_ = os.getenv("EIGEN_INGENUITY_API_TOKEN", False)
|
|
10
|
+
_auth_scope_ = os.getenv("EIGEN_INGNEUITY_AUTH_SCOPE","user_impersonation")
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
def clear_auth_token_cache():
|
|
@@ -65,7 +67,7 @@ def set_azure_client_id(id):
|
|
|
65
67
|
Set the Client ID of the App registration for the eigenserver. This value required for Azure authentication, but the use of the EIGEN_INGENUITY_TENANT_ID environmental variable can be used as an alternative way of setting it.
|
|
66
68
|
|
|
67
69
|
Args:
|
|
68
|
-
id: The ID of your
|
|
70
|
+
id: The ID of your service principal in Azure. This can be found at portal.azure.com. (Default points to our DEMO Instance)
|
|
69
71
|
|
|
70
72
|
Returns:
|
|
71
73
|
None
|
|
@@ -73,6 +75,19 @@ def set_azure_client_id(id):
|
|
|
73
75
|
global _azure_client_id_
|
|
74
76
|
_azure_client_id_ = id
|
|
75
77
|
|
|
78
|
+
def set_azure_client_secret(secret):
|
|
79
|
+
"""
|
|
80
|
+
Set the Client ID of the App registration for the eigenserver. This value required for Azure authentication via CLIENT_CREDENTIALS flow, but not for the USER_CREDENTIALS flow, but the use of the EIGEN_INGENUITY_CLIENT_SECRET environmental variable can be used as an alternative way of setting it.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
secret: The value of the client secret of your service principal in Azure. This can be found at portal.azure.com. (Default points to our DEMO Instance)
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
None
|
|
87
|
+
"""
|
|
88
|
+
global _azure_client_secret_
|
|
89
|
+
_azure_client_secret_ = secret
|
|
90
|
+
|
|
76
91
|
def set_api_token(token):
|
|
77
92
|
"""
|
|
78
93
|
Set the API token for the eigenserver. This value is required to access our secured endpoints, but the use of the EIGEN_INGENUITY_API_TOKEN environmental variable can be used as an alternative way of setting it.
|
|
@@ -85,3 +100,17 @@ def set_api_token(token):
|
|
|
85
100
|
"""
|
|
86
101
|
global _api_token_value_
|
|
87
102
|
_api_token_value_ = token
|
|
103
|
+
|
|
104
|
+
def set_auth_scope(scope):
|
|
105
|
+
"""
|
|
106
|
+
Set the Scope to be requested from the Azure App registration. This is only required if your IT has implemented a non-standard scope.
|
|
107
|
+
This value must match the one configured in the eigen dashboards app registration in your Azure, if you are unsure of what is should be, ask yoeu system administrator. The use of the EIGEN_INGENUITY_AUTH_SCOPE environmental variable can be used as an alternative way of setting it.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
scope: The value of the required scope. Defaults to 'user_impersonation'.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
None
|
|
114
|
+
"""
|
|
115
|
+
global _auth_scope_
|
|
116
|
+
_auth_scope_ = scope
|
eigeningenuity/util.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import sys, os, json, time, requests, csv, logging
|
|
1
|
+
import sys, os, json, time, requests, csv, logging, warnings
|
|
3
2
|
from datetime import datetime
|
|
4
3
|
from dateparser import parse
|
|
5
4
|
import pandas as pd
|
|
@@ -11,6 +10,13 @@ from requests.exceptions import ConnectionError
|
|
|
11
10
|
from eigeningenuity.auth import _authenticate_azure_user
|
|
12
11
|
import eigeningenuity.settings as settings
|
|
13
12
|
|
|
13
|
+
from urllib3.exceptions import InsecureRequestWarning
|
|
14
|
+
|
|
15
|
+
# Suppress only the single InsecureRequestWarning from urllib3
|
|
16
|
+
warnings.simplefilter('ignore', InsecureRequestWarning)
|
|
17
|
+
# Suppress only the single InsecureRequestWarning from urllib3
|
|
18
|
+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
|
19
|
+
|
|
14
20
|
def _do_eigen_json_request(requesturl,auth,**params):
|
|
15
21
|
|
|
16
22
|
headers = {}
|
|
@@ -516,11 +522,16 @@ def _reformat_multi_response(original_dict):
|
|
|
516
522
|
reformatted_dict = {}
|
|
517
523
|
|
|
518
524
|
for key, value in original_dict.items():
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
525
|
+
if type(value) == list:
|
|
526
|
+
reformatted_dict = value
|
|
527
|
+
elif key == "dataPoint" or key == "dataPoints":
|
|
528
|
+
reformatted_dict = value
|
|
529
|
+
else:
|
|
530
|
+
# Extract the list of data points from either 'dataPoints' or 'dataPoint' key
|
|
531
|
+
data_points = value.get('dataPoints') or value.get('dataPoint') or value
|
|
532
|
+
# Assign the data points list directly to the top-level key
|
|
533
|
+
reformatted_dict[key] = data_points
|
|
534
|
+
|
|
524
535
|
return reformatted_dict
|
|
525
536
|
|
|
526
537
|
def format_output(output,response,tags,timestamps=False):
|
|
@@ -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
|