MCPcopy
hub / github.com/pyload/pyload / saveConfig

Method saveConfig

module/ConfigParser.py:219–244  ·  view source on GitHub ↗

saves config to filename

(self, config, filename)

Source from the content-addressed store, hash-verified

217 # dest[section] = config[section]
218
219 def saveConfig(self, config, filename):
220 """saves config to filename"""
221 with open(filename, "wb") as f:
222 chmod(filename, 0600)
223 f.write("version: %i \n" % CONF_VERSION)
224 for section in sorted(config.iterkeys()):
225 f.write('\n%s - "%s":\n' % (section, config[section]["desc"]))
226
227 for option, data in sorted(config[section].items(), key=lambda _x: _x[0]):
228 if option in ("desc", "outline"):
229 continue
230
231 if isinstance(data["value"], list):
232 value = "[ \n"
233 for x in data["value"]:
234 value += "\t\t" + str(x) + ",\n"
235 value += "\t\t]\n"
236 else:
237 if type(data["value"]) in (str, unicode):
238 value = data["value"] + "\n"
239 else:
240 value = str(data["value"]) + "\n"
241 try:
242 f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value))
243 except UnicodeEncodeError:
244 f.write('\t%s %s : "%s" = %s' % (data["type"], option, data["desc"], value.encode("utf8")))
245
246 def cast(self, typ, value):
247 """cast value to given format"""

Callers 2

saveMethod · 0.95
ConfigParser.pyFile · 0.45

Calls 5

chmodFunction · 0.90
itemsMethod · 0.80
writeMethod · 0.45
iterkeysMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected