MCPcopy
hub / github.com/pyfa-org/Pyfa / getSettings

Method getSettings

service/settings.py:57–82  ·  view source on GitHub ↗
(self, area, defaults=None)

Source from the content-addressed store, hash-verified

55 os.mkdir(self.BASE_PATH)
56
57 def getSettings(self, area, defaults=None):
58 # type: (basestring, dict) -> service.Settings
59 # NOTE: needed to change for tests
60 # TODO: Write to memory with mmap -> https://docs.python.org/2/library/mmap.html
61 settings_obj = self.settings.get(area)
62 if settings_obj is None: # and hasattr(self, 'BASE_PATH'):
63 canonical_path = os.path.join(self.BASE_PATH, area) if hasattr(self, 'BASE_PATH') else ""
64 if not os.path.exists(canonical_path): # path string or empty string.
65 info = {}
66 if defaults:
67 info.update(defaults)
68 else:
69 try:
70 with open(canonical_path, "rb") as f:
71 info = pickle.load(f)
72 for item in defaults:
73 if item not in info:
74 info[item] = defaults[item]
75 except (KeyboardInterrupt, SystemExit):
76 raise
77 except:
78 info = {}
79 info.update(defaults)
80
81 self.settings[area] = settings_obj = Settings(canonical_path, info)
82 return settings_obj
83
84 def saveAll(self):
85 for settings in self.settings.values():

Callers 15

__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80

Calls 3

SettingsClass · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected