python-eigen-ingenuity-nocli 0.5.6__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.
Files changed (44) hide show
  1. eigeningenuity/__init__.py +29 -0
  2. eigeningenuity/assetmodel.py +433 -0
  3. eigeningenuity/auth.py +178 -0
  4. eigeningenuity/core/__init__.py +236 -0
  5. eigeningenuity/elastic.py +171 -0
  6. eigeningenuity/events.py +88 -0
  7. eigeningenuity/historian.py +786 -0
  8. eigeningenuity/historianmulti.py +481 -0
  9. eigeningenuity/settings.py +87 -0
  10. eigeningenuity/smartdash.py +103 -0
  11. eigeningenuity/sql.py +132 -0
  12. eigeningenuity/util.py +548 -0
  13. modelbuilder/__init__.py +7 -0
  14. modelbuilder/src/__init__.py +0 -0
  15. modelbuilder/src/assetmodelbuilder.py +164 -0
  16. modelbuilder/src/assetmodelcsvwriter.py +31 -0
  17. modelbuilder/src/assetmodelutilities.py +51 -0
  18. modelbuilder/src/configmanager.py +500 -0
  19. modelbuilder/src/connectors/__init__.py +0 -0
  20. modelbuilder/src/connectors/boltconnector.py +108 -0
  21. modelbuilder/src/connectors/dbconnectors.py +40 -0
  22. modelbuilder/src/connectors/genericconnector.py +30 -0
  23. modelbuilder/src/connectors/httpsconnector.py +132 -0
  24. modelbuilder/src/csvcontentsmanager.py +135 -0
  25. modelbuilder/src/csvwriter.py +305 -0
  26. modelbuilder/src/fileanalyser.py +91 -0
  27. modelbuilder/src/filemanager.py +400 -0
  28. modelbuilder/src/messages.py +61 -0
  29. modelbuilder/src/processors/__init__.py +0 -0
  30. modelbuilder/src/processors/cypherfileprocessor.py +73 -0
  31. modelbuilder/src/processors/labelmanager.py +133 -0
  32. modelbuilder/src/processors/nodefileprocessor.py +282 -0
  33. modelbuilder/src/processors/propertymanager.py +129 -0
  34. modelbuilder/src/processors/relationshipfileprocessor.py +285 -0
  35. modelbuilder/src/processors/relationshipmanager.py +31 -0
  36. modelbuilder/src/queries/__init__.py +0 -0
  37. modelbuilder/src/queries/cypherbuilder.py +323 -0
  38. modelbuilder/src/queries/query.py +82 -0
  39. modelbuilder/src/queries/typedefs.py +180 -0
  40. modelbuilder/src/versionmanager.py +356 -0
  41. python_eigen_ingenuity_nocli-0.5.6.dist-info/METADATA +30 -0
  42. python_eigen_ingenuity_nocli-0.5.6.dist-info/RECORD +44 -0
  43. python_eigen_ingenuity_nocli-0.5.6.dist-info/WHEEL +5 -0
  44. python_eigen_ingenuity_nocli-0.5.6.dist-info/top_level.txt +2 -0
@@ -0,0 +1,164 @@
1
+ import sys, os, functools, inspect
2
+
3
+ # Add current dir to python path to allow relative imports
4
+ current_dir = os.path.dirname(os.path.abspath(__file__))
5
+ sys.path.append(current_dir)
6
+
7
+ from configmanager import ConfigManager
8
+ from connectors.dbconnectors import ConnectionManager
9
+ from filemanager import FileManager
10
+
11
+ import sys
12
+ import inspect
13
+ import functools
14
+
15
+ # Take Arguments passed to build function and convert them to sys args to use the cli tool from script
16
+ def _convert_sys_argv_(func):
17
+ @functools.wraps(func)
18
+ def wrapper(*args, **kwargs):
19
+ # Get the function signature
20
+ sig = inspect.signature(func)
21
+
22
+ # Create an empty list to hold the sys.argv entries
23
+ argv_entries = []
24
+
25
+ # Get the arguments passed by position
26
+ args_dict = dict(zip(sig.parameters, args))
27
+
28
+ # Loop through the parameters in the function signature
29
+ for param_name, param in sig.parameters.items():
30
+ param_name_cleaned = param_name.replace('_', '')
31
+
32
+ # Check if the parameter is provided as a keyword argument
33
+ if param_name in kwargs:
34
+ arg_value = kwargs[param_name]
35
+ # Check if the parameter is provided as a positional argument
36
+ elif param_name in args_dict:
37
+ arg_value = args_dict[param_name]
38
+ else:
39
+ continue # Skip if not provided
40
+
41
+ # If parameter is a boolean, handle it as store_true action
42
+ if param.annotation == bool:
43
+ if arg_value: # If True, add only the flag
44
+ argv_entries.append(f"--{param_name_cleaned}")
45
+ else: # If False, skip adding this argument
46
+ continue
47
+ elif param.annotation == list:
48
+ argv_entries.extend([f"--{param_name_cleaned}"])
49
+ argv_entries.extend(arg_value)
50
+ else:
51
+ # For non-boolean parameters, add the value
52
+ argv_entries.extend([f"--{param_name_cleaned}", str(arg_value)])
53
+
54
+ # Extend sys.argv with the generated entries
55
+ sys.argv.extend(argv_entries)
56
+
57
+ # Call the original function
58
+ return func(*args, **kwargs)
59
+
60
+ return wrapper
61
+
62
+
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=';',
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
+ 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
+ required_properties:list=[], database:str='0', verify:bool=False, summarise:bool=False, show_queries:bool=False, show_returns:bool=False,
68
+ write_queries:str='', write_returns:str='', display_rate='auto', create_node_csv_file:bool=False, node_labels:list=[], node_properties:list=[],
69
+ csv_file_suffix:str='', create_relationship_csv_file:bool=False, csv_to_labels:list=[], csv_to_properties:str=''):
70
+ """The main model builder tools, features a suite of options that allow for importing, exporting, building and updating neo4j data models
71
+
72
+ Args:
73
+ ## Input Parameters
74
+ path: Location of the input and output files. Default is current folder
75
+ config: Name of the configuration file, default is config.ini in the folder from path parameter
76
+ database: Database ID (as set in config file). Defaults to first entry
77
+ file: Space separated string list of input files
78
+ query: Space separated string list of queries to run
79
+ preprocess: Command(s) to execute before processing input files
80
+ postprocess: Command(s) to execute after processing input files
81
+ delete_all: Lists of labels to identify nodes to delete before processing any files
82
+
83
+ ## Change the behaviour of the processing away from the default
84
+ separator: The separator used in the csv files. Default is a semi-colon ';'
85
+ start_from: The first query to process in a .csv file. No effect on cypher files. Default is 1
86
+ end_at: The last query to process in a .csv file. No effect on cypher files. Default is last query in the file
87
+ no_versions: Suppress creation of version nodes
88
+ no_system_properties: Suppress creation of system properties on nodes and relationships. Implies -nov
89
+ ignore_nodes: Treat node columns in relationship files as relationship properties
90
+ skip_duplicates: Don't create a version node if there are no changes. Same as -nod
91
+ allow_blanks: List of properties to create even if blank
92
+ batch: Number of queries to batch together when processing a node .csv file, significantly improves performance
93
+ auth: Enable Azure Authentication
94
+ order: Order in which to process the input files. Default is qnrc
95
+ filetypes: File types to process. Default is all
96
+
97
+ # Override values in the config file
98
+ primary_property: Primary property
99
+ required_labels: Required labels - appended to contents of config; use !Label to remove
100
+ required_properties: Required properties - appended to contents of config; use !property to remove
101
+
102
+ # What output is required
103
+ verify: Display the generated queries, but do not process them
104
+ summarise: Show a summary of the queries, but do not process them
105
+ show_queries: Display the queries as they are processed. No effect if -v present
106
+ show_returns: Display data from any RETURN clause
107
+ write_queries: Name of a file to record the processed queries. No effect if -v present
108
+ write_returns: Name of a file to record the results of the queries. No effect if -v present
109
+ display_rate: Set the frequency of progress update messages. No effect if -v present
110
+
111
+ # Control of the CSV writer
112
+ create_node_csv_file: Create Node csv file(s) from Asset Model'
113
+ node_labels: Lists of labels to identify nodes to write to csv file'
114
+ node_properties: Primary property of nodes'
115
+ csv_file_suffix: Suffix to use in the output Node .csv file'
116
+ create_relationship_csv_file: Create Relationship csv file(s) from Asset Model'
117
+ csv_to_labels: Lists of labels to identify to nodes to write to csv file'
118
+ csv_to_properties: Primary property of To nodes'
119
+
120
+ Returns:
121
+ Boolean for Sucess/Failure. If any queries failed gives False. Logs are printed to terminal during running. TBE
122
+ """
123
+ _asset_model_builder_()
124
+
125
+
126
+ def _asset_model_builder_():
127
+ # Create a configuration manager which will read the command line parameters and the contents of the settings file
128
+ # Any errors are stored in a List, which are then displayed to the user
129
+ config_manager = ConfigManager()
130
+ if config_manager.get_error_count() > 0:
131
+ sys.exit()
132
+
133
+ config_manager.read_csv_config()
134
+ if config_manager.get_error_count() > 0:
135
+ sys.exit()
136
+
137
+ output_file = config_manager.get_query_output()
138
+
139
+ # Read the data needed to create version nodes and relationships
140
+ config_manager.reset_errors()
141
+ config_manager.read_version_config()
142
+ if config_manager.get_error_count() > 0:
143
+ sys.exit()
144
+
145
+ # Create a csv file Manager to process all the input files
146
+ file_manager = FileManager(config_manager)
147
+ file_manager.analyse_files()
148
+
149
+ # Create a connection to the database
150
+ config_manager.reset_errors()
151
+ config_manager.read_db_config()
152
+ if config_manager.get_error_count() > 0:
153
+ sys.exit()
154
+ connection_manager = ConnectionManager(config_manager)
155
+ db_connector = connection_manager.get_db_connector()
156
+
157
+ # And process the generated queries
158
+ file_manager.process_files(db_connector)
159
+
160
+ connection_manager.close()
161
+
162
+
163
+ if __name__ == "__main__":
164
+ _asset_model_builder_()
@@ -0,0 +1,31 @@
1
+ import sys
2
+ from configmanager import ConfigManager
3
+ from connectors.dbconnectors import ConnectionManager
4
+ from filemanager import FileManager
5
+ from csvwriter import CSVFileWriter
6
+
7
+ if __name__ == "__main__":
8
+
9
+ # Create a configuration manager which will read the command line parameters and the contents of the settings file
10
+ # Any errors are stored in a List, which are then displayed to the user
11
+ config_manager = ConfigManager()
12
+ if config_manager.get_error_count() > 0:
13
+ sys.exit()
14
+
15
+ config_manager.read_csv_config()
16
+ if config_manager.get_error_count() > 0:
17
+ sys.exit()
18
+
19
+ # Create a connection to the database
20
+ config_manager.reset_errors()
21
+ config_manager.read_version_config()
22
+ config_manager.read_db_config()
23
+ if config_manager.get_error_count() > 0:
24
+ sys.exit()
25
+ connection_manager = ConnectionManager(config_manager)
26
+ db_connector = connection_manager.get_db_connector()
27
+
28
+ csv_generator = CSVFileWriter(config_manager, db_connector)
29
+ csv_generator.write_csv_files()
30
+
31
+ connection_manager.close()
@@ -0,0 +1,51 @@
1
+ from pathlib import Path
2
+ import datetime
3
+ from datetime import timezone
4
+ import re
5
+
6
+ # Define special types that are used by the Neo4j importer
7
+ # They are also used in Java asset model builder
8
+ # Could add these to the config file at some point, but they are unlikely to change
9
+ node_types = ['ID']
10
+ from_types = ['START_ID']
11
+ to_types = ['END_ID']
12
+ relation_types = ['TYPE']
13
+ label_types = ['LABEL', 'ALABEL']
14
+ all_types = node_types + from_types + to_types + relation_types + label_types
15
+
16
+
17
+ def find_file(path, filename):
18
+ # try the provided path file first, then with the current path. Otherwise, return None to indicate file not found
19
+ if Path(path + filename).is_file():
20
+ full_name = path + filename
21
+ elif Path(filename).is_file():
22
+ full_name = filename
23
+ else:
24
+ full_name = None
25
+ return full_name
26
+
27
+ def get_formatted_time_now():
28
+ now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%dT%H:%M:%S.%f%z")
29
+ return now
30
+
31
+ def get_formatted_time_now_noms():
32
+ now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%dT%H:%M:%S%z")
33
+ return now
34
+
35
+ def get_formatted_future_time():
36
+ future = datetime.datetime(2199, 12, 31).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
37
+ return future
38
+
39
+ def get_time_for_filename():
40
+ now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%d %H-%M-%S-%f")[0:-3]
41
+ return now
42
+
43
+ def validate(input, prefix = ''):
44
+ output = f'{prefix}{input}'
45
+ if input:
46
+ if input.startswith('`!'):
47
+ output = f'{prefix}{input}`'
48
+ elif ''.join(re.findall("[A-Za-z0-9_]", input)) != input or ''.join(re.findall("[A-Za-z]", input[0])) != input[0]:
49
+ output = f'{prefix}`{input.replace("`","``")}`'
50
+
51
+ return output