spinetoolbox.project_items.importer.importer
¶
Contains Importer project item class.
authors: |
|
---|---|
date: | 10.6.2019 |
Module Contents¶
-
class
spinetoolbox.project_items.importer.importer.
Importer
(name, description, mappings, x, y, toolbox, project, logger, cancel_on_error=True)[source]¶ Bases:
spinetoolbox.project_item.ProjectItem
Importer class.
Parameters: - name (str) – Project item name
- description (str) – Project item description
- mappings (list) – List where each element contains two dicts (path dict and mapping dict)
- x (float) – Initial icon scene X coordinate
- y (float) – Initial icon scene Y coordinate
- toolbox (ToolboxUI) – QMainWindow instance
- project (SpineToolboxProject) – the project this item belongs to
- logger (LoggerInterface) – a logger instance
- cancel_on_error (bool) – if True the item’s execution will stop on import error
-
make_signal_handler_dict
(self)[source]¶ Returns a dictionary of all shared signals and their handlers. This is to enable simpler connecting and disconnecting.
-
restore_selections
(self)[source]¶ Restores selections into shared widgets when this project item is selected.
-
save_selections
(self)[source]¶ Saves selections in shared widgets for this project item into instance variables.
-
update_name_label
(self)[source]¶ Update Importer properties tab name label. Used only when renaming project items.
-
_handle_import_editor_clicked
(self, checked=False)[source]¶ Opens Import editor for the file selected in list view.
-
_handle_files_double_clicked
(self, index)[source]¶ Opens Import editor for the double clicked index.
-
get_connector
(self, importee)[source]¶ Shows a QDialog to select a connector for the given source file. Mimics similar routine in spine_io.widgets.import_widget.ImportDialog
Parameters: importee (str) – Path to file acting as an importee Returns: Asynchronous data reader class for the given importee
-
select_connector_type
(self, index)[source]¶ Opens dialog to select connector type for the given index.
-
get_settings
(self, importee)[source]¶ Returns the mapping dictionary for the file in given path.
Parameters: importee (str) – Absolute path to a file, whose mapping is queried Returns: Mapping dictionary for the requested importee or an empty dict if not found Return type: dict
-
save_settings
(self, settings, importee)[source]¶ - Updates an existing mapping or adds a new mapping
- (settings) after closing the import preview window.
Parameters: - settings (dict) – Updated mapping (settings) dictionary
- importee (str) – Absolute path to a file, whose mapping has been updated
-
_preview_destroyed
(self, importee)[source]¶ Destroys preview widget instance for the given importee.
Parameters: importee (str) – Absolute path to a file, whose preview widget is destroyed
-
update_file_model
(self, items)[source]¶ Adds given list of items to the file model. If None or an empty list is given, the model is cleared.
Parameters: items (set) – Set of absolute file paths
-
_prepare_importer_program
(self, importer_args)[source]¶ Prepares an execution manager instance for running importer_process.py in a QProcess.
If app is not frozen, the Python to run it is the python that was used in starting the app.
If app is frozen, we are running the importer_program application found in application install directory.
Parameters: importer_args (list) – Arguments for the importer_program. Source file paths, their mapping specs, URLs downstream, logs directory, cancel_on_error Returns: True if preparing the program succeeded, False otherwise. Return type: bool
-
_handle_importer_program_process_finished
(self, exit_code)[source]¶ Handles the return value from importer program when it has finished. Emits a signal to indicate that this Importer has been executed.
Parameters: exit_code (int) – Process return value. 0: success, !0: failure
-
python_exists
(self, program)[source]¶ Checks that Python is set up correctly in Settings. This executes ‘python -V’ in a QProcess and if the process finishes successfully, the python is ready to be used.
Parameters: program (str) – Python executable that is currently set in Settings Returns: True if Python is found, False otherwise Return type: bool
-
_notify_if_duplicate_file_paths
(self, file_list)[source]¶ Adds a notification if file_list contains duplicate entries.
-
static
upgrade_from_no_version_to_version_1
(item_name, old_item_dict, old_project_dir)[source]¶ Converts mappings to a list, where each element contains two dictionaries, the serialized path dictionary and the mapping dictionary for the file in that path.
-
static
deserialize_mappings
(mappings, project_path)[source]¶ Returns mapping settings as dict with absolute paths as keys.
Parameters: - mappings (list) – List where each element contains two dictionaries (path dict and mapping dict)
- project_path (str) – Path to project directory
Returns: Dictionary with absolute paths as keys and mapping settings as values
Return type: dict
-
static
serialize_mappings
(mappings, project_path)[source]¶ Returns a list of mappings, where each element contains two dictionaries, the ‘serialized’ path in a dictionary and the mapping dictionary.
Parameters: - mappings (dict) – Dictionary with mapping specifications
- project_path (str) – Path to project directory
Returns: List where each element contains two dictionaries.
Return type: list