commonlib-reader 1.0.8__tar.gz → 1.0.9__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: commonlib-reader
3
- Version: 1.0.8
3
+ Version: 1.0.9
4
4
  Summary: Reader for Equinor commonlib api.
5
5
  License: MIT
6
6
  Author: Åsmund Våge Fannemel
@@ -1,4 +1,4 @@
1
- from typing import List
1
+ from typing import List, Union
2
2
 
3
3
  from commonlib_reader.utils import attributes_list_to_dict, get_code
4
4
 
@@ -75,6 +75,29 @@ class Facility:
75
75
  def __str__(self):
76
76
  return f"Facility: {self.identity}, Name: {self.name}, Description: {self.description}"
77
77
 
78
+ @staticmethod
79
+ def get_inst_code(facility: Union[str, int]) -> str:
80
+ """
81
+ Retrieves the STID installation code for the given facility identifier.
82
+ If the facility is not a STID facility, it recursively retrieves the installation code of its parent facility.
83
+
84
+ Parameters:
85
+ facility (str or int): The facility identifier, which can be a STID plant code, SAP code, or governmental facility name.
86
+ Returns:
87
+ str: The installation code corresponding to the facility.
88
+ Raises:
89
+ ValueError: If no facility is found for the provided identifier.
90
+ """
91
+
92
+ f = Facility(facility)
93
+ if isinstance(f, Facility):
94
+ if f.isSTID():
95
+ return f.STID
96
+ else:
97
+ return Facility.get_inst_code(f.ParentFacility)
98
+
99
+ raise ValueError(f"No facility found for {facility}")
100
+
78
101
  @classmethod
79
102
  def get_all_facilities(cls) -> List["Facility"]:
80
103
  """
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "commonlib-reader"
3
- version = "1.0.8"
3
+ version = "1.0.9"
4
4
  description = "Reader for Equinor commonlib api."
5
5
  authors = [
6
6
  { name = "Åsmund Våge Fannemel", email = "asmf@equinor.com" }