FairShip
Loading...
Searching...
No Matches
ShipGeoConfig.Config Class Reference
Inheritance diagram for ShipGeoConfig.Config:
Collaboration diagram for ShipGeoConfig.Config:

Public Member Functions

None __init__ (self, *args, **kwargs)
 
def loads (self, bytes buff)
 
def loads_json (self, str json_str)
 
Config clone (self)
 
bytes dumps (self)
 
str dumps_json (self)
 
def load (self, filename)
 
int dump (self, filename)
 
str __str__ (self)
 
None __init__ (self, *args, **kwargs)
 
AttrDict clone (self)
 

Detailed Description

Definition at line 32 of file ShipGeoConfig.py.

Constructor & Destructor Documentation

◆ __init__()

None ShipGeoConfig.Config.__init__ (   self,
args,
**  kwargs 
)

Reimplemented from ShipGeoConfig.AttrDict.

Definition at line 33 of file ShipGeoConfig.py.

33 def __init__(self, *args, **kwargs) -> None:
34 super().__init__(*args, **kwargs)
35

Member Function Documentation

◆ __str__()

str ShipGeoConfig.Config.__str__ (   self)

Definition at line 89 of file ShipGeoConfig.py.

89 def __str__(self) -> str:
90 return "ShipGeoConfig:\n " + "\n ".join(
91 [f"{k}: {self[k].__str__()}" for k in sorted(self.keys()) if not k.startswith("_")]
92 )
93
94

◆ clone()

Config ShipGeoConfig.Config.clone (   self)

Reimplemented from ShipGeoConfig.AttrDict.

Definition at line 64 of file ShipGeoConfig.py.

64 def clone(self) -> Config:
65 result = Config()
66 for k, v in self.items():
67 if isinstance(v, AttrDict):
68 result[k] = v.clone()
69 else:
70 result[k] = v
71 return result
72

◆ dump()

int ShipGeoConfig.Config.dump (   self,
  filename 
)

Definition at line 85 of file ShipGeoConfig.py.

85 def dump(self, filename) -> int:
86 with open(os.path.expandvars(filename), "wb") as fh:
87 return fh.write(self.dumps())
88
int open(const char *, int)
Opens a file descriptor.

◆ dumps()

bytes ShipGeoConfig.Config.dumps (   self)

Definition at line 73 of file ShipGeoConfig.py.

73 def dumps(self) -> bytes:
74 return pickle.dumps(self)
75

◆ dumps_json()

str ShipGeoConfig.Config.dumps_json (   self)
Serialize config to JSON string

Definition at line 76 of file ShipGeoConfig.py.

76 def dumps_json(self) -> str:
77 """Serialize config to JSON string"""
78 return json.dumps(self, indent=2, default=str)
79

◆ load()

def ShipGeoConfig.Config.load (   self,
  filename 
)

Definition at line 80 of file ShipGeoConfig.py.

80 def load(self, filename):
81 with open(os.path.expandvars(filename), "rb") as fh:
82 self.loads(fh.read())
83 return self
84

◆ loads()

def ShipGeoConfig.Config.loads (   self,
bytes  buff 
)

Definition at line 36 of file ShipGeoConfig.py.

36 def loads(self, buff: bytes):
37 rv = pickle.loads(buff)
38 self.clear()
39 self.update(rv)
40 return self
41

◆ loads_json()

def ShipGeoConfig.Config.loads_json (   self,
str  json_str 
)
Deserialize config from JSON string

Definition at line 42 of file ShipGeoConfig.py.

42 def loads_json(self, json_str: str):
43 """Deserialize config from JSON string"""
44
45 def dict_to_attrdict(d):
46 """Recursively convert dict to AttrDict"""
47 if isinstance(d, dict):
48 result = AttrDict()
49 for k, v in d.items():
50 result[k] = dict_to_attrdict(v)
51 return result
52 elif isinstance(d, list):
53 return [dict_to_attrdict(item) for item in d]
54 else:
55 return d
56
57 rv = json.loads(json_str)
58 self.clear()
59 # Convert nested dicts to AttrDict
60 for k, v in rv.items():
61 self[k] = dict_to_attrdict(v)
62 return self
63

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