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

Public Member Functions

None __init__ (self, *args, **kwargs)
 loads (self, bytes buff)
 loads_json (self, str json_str)
Config clone (self)
bytes dumps (self)
str dumps_json (self)
 load (self, filename)
int dump (self, filename)
str __str__ (self)
Public Member Functions inherited from ShipGeoConfig.AttrDict
Any __getattr__ (self, str name)
None __setattr__ (self, str name, Any value)
None __init__ (self, *args, **kwargs)

Detailed Description

Definition at line 40 of file ShipGeoConfig.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 41 of file ShipGeoConfig.py.

41 def __init__(self, *args, **kwargs) -> None:
42 super().__init__(*args, **kwargs)
43

Member Function Documentation

◆ __str__()

str ShipGeoConfig.Config.__str__ ( self)

Definition at line 97 of file ShipGeoConfig.py.

97 def __str__(self) -> str:
98 return "ShipGeoConfig:\n " + "\n ".join(
99 [f"{k}: {self[k].__str__()}" for k in sorted(self.keys()) if not k.startswith("_")]
100 )
101
102

◆ clone()

Config ShipGeoConfig.Config.clone ( self)

Reimplemented from ShipGeoConfig.AttrDict.

Definition at line 72 of file ShipGeoConfig.py.

72 def clone(self) -> Config:
73 result = Config()
74 for k, v in self.items():
75 if isinstance(v, AttrDict):
76 result[k] = v.clone()
77 else:
78 result[k] = v
79 return result
80

◆ dump()

int ShipGeoConfig.Config.dump ( self,
filename )

Definition at line 93 of file ShipGeoConfig.py.

93 def dump(self, filename) -> int:
94 with open(os.path.expandvars(filename), "wb") as fh:
95 return fh.write(self.dumps())
96

◆ dumps()

bytes ShipGeoConfig.Config.dumps ( self)

Definition at line 81 of file ShipGeoConfig.py.

81 def dumps(self) -> bytes:
82 return pickle.dumps(self)
83

◆ dumps_json()

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

Definition at line 84 of file ShipGeoConfig.py.

84 def dumps_json(self) -> str:
85 """Serialize config to JSON string"""
86 return json.dumps(self, indent=2, default=str)
87

◆ load()

ShipGeoConfig.Config.load ( self,
filename )

Definition at line 88 of file ShipGeoConfig.py.

88 def load(self, filename):
89 with open(os.path.expandvars(filename), "rb") as fh:
90 self.loads(fh.read())
91 return self
92

◆ loads()

ShipGeoConfig.Config.loads ( self,
bytes buff )

Definition at line 44 of file ShipGeoConfig.py.

44 def loads(self, buff: bytes):
45 rv = pickle.loads(buff)
46 self.clear()
47 self.update(rv)
48 return self
49

◆ loads_json()

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

Definition at line 50 of file ShipGeoConfig.py.

50 def loads_json(self, json_str: str):
51 """Deserialize config from JSON string"""
52
53 def dict_to_attrdict(d):
54 """Recursively convert dict to AttrDict"""
55 if isinstance(d, dict):
56 result = AttrDict()
57 for k, v in d.items():
58 result[k] = dict_to_attrdict(v)
59 return result
60 elif isinstance(d, list):
61 return [dict_to_attrdict(item) for item in d]
62 else:
63 return d
64
65 rv = json.loads(json_str)
66 self.clear()
67 # Convert nested dicts to AttrDict
68 for k, v in rv.items():
69 self[k] = dict_to_attrdict(v)
70 return self
71

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