ResSimpy.Nexus.DataModels.NexusFile.NexusFile
- class ResSimpy.Nexus.DataModels.NexusFile.NexusFile(location: str | None = None, include_locations: list[str] | None = None, origin: str | None = None, include_objects: list[ResSimpy.Nexus.DataModels.NexusFile.NexusFile] | None = None, file_content_as_list: list[str] | None = None, linked_user: str | None = None, last_modified: datetime | None = None)[source]
Bases:
FileClass to deal with origin and structure of Nexus files and preserve origin of include files.
- location
Path to the original file being opened. Defaults to None.
- Type:
Optional[str]
- include_locations
list of file paths that the file contains. Defaults to None.
- Type:
Optional[list[str]]
- origin
Where the file was opened from. Defaults to None.
- Type:
Optional[str]
- include_objects
The include files but generated as a NexusFile instance. Defaults to None.
- Type:
Optional[list[NexusFile]]
- linked_user
user or owner of the file. Defaults to None
- Type:
Optional[str]
- last_modified
last modified date of the file
- Type:
Optional[datetime]
Public Data Attributes:
object_locationsline_locationsget_flat_list_str_fileget_flat_list_str_file_including_includesinput_file_locationfile_content_as_listInherited from
Filelocationfile_content_as_listidUnique identifier for each Node object.
file_modifiedget_flat_list_str_fileInherited from
FileBaselocationfile_content_as_listget_flat_list_str_fileMethods:
__init__([location, include_locations, ...])generate_file_include_structure(file_path[, ...])Generates a nexus file instance for a provided text file with information storing the included files.
Exports lists of connections from and to for use in network graphs.
iterate_line([file_index, max_depth, ...])Generator object for iterating over a list of strings with nested NexusFile objects in them.
get_full_network([max_depth])Recursively constructs two lists of from and to nodes representing the connections between files.
add_object_locations(obj_uuid, line_indices)Adds a uuid to the object_locations dictionary.
find_which_include_file(flattened_index)Given a line index that relates to a position within the flattened file_as_list from the method get_flat_file_as_list.
add_to_file_as_list(additional_content, index)To add content to the file as list, also updates object numbers and optionally allows user to add several additional new objects.
Removes all associated lines in the file as well as the object locations relating to a list of objects.
remove_from_file_as_list(index[, ...])Remove an entry from the file as list.
insert_comments(additional_content, comments)Adds comments alongside additional content.
Gets the number of object locations for a specified id.
__repr__()Return repr(self).
__eq__(other)Return self==value.
Inherited from
File__init__([location, file_content_as_list])write_to_file([new_file_path])Writes to file specified in self.location the strings contained in the list self.file_content_as_list.
add_object_locations(obj_uuid, line_indices)insert_comments(additional_content, comments)get_object_locations_for_id(obj_id)remove_object_from_file_as_list(...)add_to_file_as_list(additional_content, index)remove_from_file_as_list(index[, ...])find_which_include_file(flattened_index)__repr__()Return repr(self).
__eq__(other)Return self==value.
Inherited from
FileBasewrite_to_file()add_object_locations(obj_uuid, line_indices)insert_comments(additional_content, comments)get_object_locations_for_id(obj_id)remove_object_from_file_as_list(...)add_to_file_as_list(additional_content, index)remove_from_file_as_list(index[, ...])__init__([location, file_content_as_list, ...])__repr__()Return repr(self).
__eq__(other)Return self==value.
- __init__(location: str | None = None, include_locations: list[str] | None = None, origin: str | None = None, include_objects: list[ResSimpy.Nexus.DataModels.NexusFile.NexusFile] | None = None, file_content_as_list: list[str] | None = None, linked_user: str | None = None, last_modified: datetime | None = None) None[source]
- classmethod generate_file_include_structure(file_path: str, origin: str | None = None, recursive: bool = True, skip_arrays: bool = True, top_level_file: bool = True) Self[source]
Generates a nexus file instance for a provided text file with information storing the included files.
- Parameters:
file_path (str) – path to a file
origin (Optional[str], optional) – Where the file was opened from. Defaults to None.
recursive (bool) – Whether the method should recursively drill down multiple layers of include_locations.
skip_arrays (bool) – If set True skips the INCLUDE arrays that come after property array and VALUE
top_level_file (bool) – If set to True, the code assumes this is a ‘top level’ file rather than an included
one. –
- Returns:
NexusFile – a class instance for NexusFile with knowledge of include files
- export_network_lists()[source]
Exports lists of connections from and to for use in network graphs.
- Raises:
ValueError – If the from and to lists are not the same length
- Returns:
tuple[list] – list of to and from file paths where the equivalent indexes relate to a connection
- iterate_line(file_index: FileIndex | None = None, max_depth: int | None = None, parent: NexusFile | None = None, prefix_line: str | None = None, keep_include_references=False) Generator[str, None, None][source]
Generator object for iterating over a list of strings with nested NexusFile objects in them.
- Yields:
str – sequential line from the file.
- get_full_network(max_depth: int | None = None) tuple[list[str | None], list[str | None]][source]
Recursively constructs two lists of from and to nodes representing the connections between files.
- Parameters:
max_depth (Optional[int], optional) – depth of the iteration to construct the network down to. Defaults to None.
- Returns:
tuple[list[str | None], list[str | None]] – two lists of from and to nodes where corresponding indices create an edge within a graph network. e.g. (from_list[i], to_list[i]) is a connection between two files.
- add_object_locations(obj_uuid: UUID, line_indices: list[int]) None[source]
Adds a uuid to the object_locations dictionary. Used for storing the line numbers where objects are stored within the flattened file_as_list.
- Parameters:
obj_uuid (UUID) – unique identifier of the object being created/stored.
line_indices (list[int]) – line number in the flattened file_content_as_list (i.e. from the get_flat_list_str_file method).
- property id: UUID
Unique identifier for each Node object.
- write_to_file(new_file_path: str | None = None) None
Writes to file specified in self.location the strings contained in the list self.file_content_as_list.
- find_which_include_file(flattened_index: int) tuple[ResSimpy.File.File, int][source]
Given a line index that relates to a position within the flattened file_as_list from the method get_flat_file_as_list.
- Parameters:
flattened_index (int) – index in the flattened file as list structure
- Returns:
tuple[File, int] where the first element is the file that the relevant line is in and the second element is the relative index in that file.
- add_to_file_as_list(additional_content: list[str], index: int, additional_objects: dict[uuid.UUID, list[int]] | None = None, comments: str | None = None) None[source]
To add content to the file as list, also updates object numbers and optionally allows user to add several additional new objects.
- Parameters:
additional_content (list[str]) – Additional lines as a list of strings to be added.
index (int) – index to insert the new lines at in the calling flat_file_as_list
additional_objects (Optional[dict[UUID, int]]) – defaults to None. Otherwise, a dictionary keyed with the UUID of the new objects to add as well as the corresponding index of the object in the original calling NexusFile
comments (str | None) – defaults to None. Comments to add in-line to the file.
- remove_object_from_file_as_list(objects_to_remove: list[uuid.UUID]) None[source]
Removes all associated lines in the file as well as the object locations relating to a list of objects.
- remove_from_file_as_list(index: int, objects_to_remove: list[uuid.UUID] | None = None, string_to_remove: str | None = None) None[source]
Remove an entry from the file as list. Also updates existing object locations and removes any specified objects from the object locations dictionary.
- Parameters:
index (int) – index n the calling flat_file_as_list to remove the entry from
objects_to_remove (Optional[list[UUID]]) – list of object id’s to remove from the object locations. Defaults to None
string_to_remove (Optional[str]) – if specified will only remove the listed string from the entry at the index. Defaults to None, which removes the entire entry.
- static insert_comments(additional_content: list[str], comments: str) list[str][source]
Adds comments alongside additional content.
- Parameters:
additional_content (list[str]) – additional lines of the file to be added with a new entry per line.
comments (str) – comments to be added to all lines
- Returns:
list of strings within the content.