fosKeyMan
Loading...
Searching...
No Matches
src.backend.foldercontent.FolderContent Class Reference

Handle reading JSON files (userProperties.json and gageSegment.json) from keyfile folders located in activated or deactivated directories. More...

Public Member Functions

 __init__ (self, activated_path, deactivated_path)
 Initialize the FolderContent with paths for activated and deactivated keyfile directories.
 
 edit_sensor_name_for_key (self, key, new_sensor_name)
 Edit the userSensorName for a specified key in the userProperties.json file and synchronize the lastEditDate.
 
 full_text_search (self, search_term, keyfile=None)
 Full-text search inside all JSON files.
 
 get_last_edit_date (self, key)
 Retrieve the lastEditDate from the userProperties.json file of the specified key's ZIP file.
 
 load_json (self, file_path)
 Load and parse a JSON file from within a key file.
 
 read_gage_segment (self, key)
 Read the content of the gageSegment.json file from the specified key's keyfile folder.
 
 read_metadata (self, key)
 Read the content of the metadata.json file from the specified key file.
 
 read_od6ref_file (self, key)
 Read the first line of the .od6ref file from the specified key's keyfile folder.
 
 read_sensor_length_for_key (self, key)
 Read the "sensorLength (m)" value from the .od6ref file in the specified key's folder.
 
 read_sensor_name_for_key (self, key)
 Read the userSensorName from the userProperties.json file in the specified key's folder.
 
 read_user_properties (self, key)
 Read the content of the userProperties.json file from the specified key's folder.
 
 search_in_folder (self, folder_path, search_term)
 Search inside a key file folder for the given search term in the JSON files.
 
 search_in_json (self, data, search_term)
 Recursively search through a JSON for the search term, case-insensitive, with partial matching.
 
 update_metadata (self, key, metadata)
 Update the metadata.json for a given key (serial number).
 

Public Attributes

 activated_path = activated_path
 
 deactivated_path = deactivated_path
 

Detailed Description

Handle reading JSON files (userProperties.json and gageSegment.json) from keyfile folders located in activated or deactivated directories.

Also reads and updates the metadata.json file.

Definition at line 15 of file foldercontent.py.

Constructor & Destructor Documentation

◆ __init__()

src.backend.foldercontent.FolderContent.__init__ ( self,
activated_path,
deactivated_path )

Initialize the FolderContent with paths for activated and deactivated keyfile directories.

Parameters
activated_path(str): The path to the directory containing activated keyfiles.
deactivated_path(str): The path to the directory containing deactivated keyfiles.

Definition at line 20 of file foldercontent.py.

Member Function Documentation

◆ edit_sensor_name_for_key()

src.backend.foldercontent.FolderContent.edit_sensor_name_for_key ( self,
key,
new_sensor_name )

Edit the userSensorName for a specified key in the userProperties.json file and synchronize the lastEditDate.

Parameters
key(str): The key whose userSensorName needs to be updated.
new_sensor_name(str): The new sensor name to set.
Returns
(bool): True if the update was successful, False otherwise.

Definition at line 203 of file foldercontent.py.

◆ full_text_search()

src.backend.foldercontent.FolderContent.full_text_search ( self,
search_term,
keyfile = None )

Full-text search inside all JSON files.

Parameters
search_term(str): The term to search within the JSON files.
keyfile(str or None): The specific key for keyfile to search within. If None, search in all keyfile folders.
Returns
(list of tuples): A list of (keyfile name, matching content) tuples where the search term was found.

Definition at line 96 of file foldercontent.py.

Here is the call graph for this function:

◆ get_last_edit_date()

src.backend.foldercontent.FolderContent.get_last_edit_date ( self,
key )

Retrieve the lastEditDate from the userProperties.json file of the specified key's ZIP file.

Parameters
key(str): The name of the key to locate its corresponding ZIP file.
Returns
(datetime or None): The lastEditDate as a datetime object, or None if not found or not valid.

Definition at line 174 of file foldercontent.py.

Here is the call graph for this function:

◆ load_json()

src.backend.foldercontent.FolderContent.load_json ( self,
file_path )

Load and parse a JSON file from within a key file.

Parameters
file_path(str): The path to the JSON or binary file.
Returns
(dict or None): A dictionary containing the parsed JSON data, or None if the file could not be read.

Definition at line 78 of file foldercontent.py.

Here is the caller graph for this function:

◆ read_gage_segment()

src.backend.foldercontent.FolderContent.read_gage_segment ( self,
key )

Read the content of the gageSegment.json file from the specified key's keyfile folder.

Similar to read_user_properties, this method checks if the key's keyfile folder exists in the activated or deactivated directories and attempts to load the 'gageSegment.json' file from within the folder.

Parameters
key(str): The name of the key to locate its corresponding key file folder.
Returns
(dict or None): A dictionary containing the parsed JSON data, or None if the file does not exist.

Definition at line 46 of file foldercontent.py.

Here is the call graph for this function:

◆ read_metadata()

src.backend.foldercontent.FolderContent.read_metadata ( self,
key )

Read the content of the metadata.json file from the specified key file.

Parameters
keyThe name of the key to locate its corresponding folder.
Returns
: A dictionary containing the parsed JSON data, or an empty dict if the file does not exist.

Definition at line 240 of file foldercontent.py.

◆ read_od6ref_file()

src.backend.foldercontent.FolderContent.read_od6ref_file ( self,
key )

Read the first line of the .od6ref file from the specified key's keyfile folder.

Parameters
key(str): The name of the key to locate its corresponding folder.
Returns
(dict or None): A dictionary containing the parsed JSON data, or None if the file does not exist.

Definition at line 63 of file foldercontent.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_sensor_length_for_key()

src.backend.foldercontent.FolderContent.read_sensor_length_for_key ( self,
key )

Read the "sensorLength (m)" value from the .od6ref file in the specified key's folder.

Parameters
key(str): The name of the key to locate its corresponding folder.
Returns
(float or None): The value of "sensorLength (m)" if it exists, or None otherwise.

Definition at line 228 of file foldercontent.py.

Here is the call graph for this function:

◆ read_sensor_name_for_key()

src.backend.foldercontent.FolderContent.read_sensor_name_for_key ( self,
key )

Read the userSensorName from the userProperties.json file in the specified key's folder.

Parameters
key(str): The name of the key to locate its corresponding folder.
Returns
(str or None): The value of userSensorName if it exists, or None otherwise.

Definition at line 191 of file foldercontent.py.

Here is the call graph for this function:

◆ read_user_properties()

src.backend.foldercontent.FolderContent.read_user_properties ( self,
key )

Read the content of the userProperties.json file from the specified key's folder.

The method checks if the key's folder exists in the activated or deactivated directories, and attempts to load the 'userProperties.json' file from within the folder.

Parameters
key(str): The name of the key to locate its corresponding key file folder.
Returns
(dict or None): A dictionary containing the parsed JSON data, or None if the file does not exist.

Definition at line 29 of file foldercontent.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_in_folder()

src.backend.foldercontent.FolderContent.search_in_folder ( self,
folder_path,
search_term )

Search inside a key file folder for the given search term in the JSON files.

Parameters
folder_path(str): The path to the key file.
search_term(str): The term to search for.
Returns
(tuple or None): The serial number and matching content if the search term is found, None otherwise.

Definition at line 122 of file foldercontent.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_in_json()

src.backend.foldercontent.FolderContent.search_in_json ( self,
data,
search_term )

Recursively search through a JSON for the search term, case-insensitive, with partial matching.

Parameters
data(dict or list): The JSON data to search through.
search_term(str): The term to search for.
Returns
(list): A list of matching key-value pairs if the search term is found, otherwise an empty list.

Definition at line 149 of file foldercontent.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_metadata()

src.backend.foldercontent.FolderContent.update_metadata ( self,
key,
metadata )

Update the metadata.json for a given key (serial number).

Parameters
keyThe name of the key to locate its corresponding folder.
metadataDictionary to save.

Definition at line 260 of file foldercontent.py.

Member Data Documentation

◆ activated_path

src.backend.foldercontent.FolderContent.activated_path = activated_path

Definition at line 26 of file foldercontent.py.

◆ deactivated_path

src.backend.foldercontent.FolderContent.deactivated_path = deactivated_path

Definition at line 27 of file foldercontent.py.


The documentation for this class was generated from the following file: