MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / ensureNamecoinOptions

Function ensureNamecoinOptions

src/namecoin.py:270–319  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

268# Ensure all namecoin options are set, by setting those to default values
269# that aren't there.
270def ensureNamecoinOptions ():
271 if not BMConfigParser().has_option (configSection, "namecoinrpctype"):
272 BMConfigParser().set (configSection, "namecoinrpctype", "namecoind")
273 if not BMConfigParser().has_option (configSection, "namecoinrpchost"):
274 BMConfigParser().set (configSection, "namecoinrpchost", "localhost")
275
276 hasUser = BMConfigParser().has_option (configSection, "namecoinrpcuser")
277 hasPass = BMConfigParser().has_option (configSection, "namecoinrpcpassword")
278 hasPort = BMConfigParser().has_option (configSection, "namecoinrpcport")
279
280 # Try to read user/password from .namecoin configuration file.
281 defaultUser = ""
282 defaultPass = ""
283 nmcFolder = lookupNamecoinFolder ()
284 nmcConfig = nmcFolder + "namecoin.conf"
285 try:
286 nmc = open (nmcConfig, "r")
287
288 while True:
289 line = nmc.readline ()
290 if line == "":
291 break
292 parts = line.split ("=")
293 if len (parts) == 2:
294 key = parts[0]
295 val = parts[1].rstrip ()
296
297 if key == "rpcuser" and not hasUser:
298 defaultUser = val
299 if key == "rpcpassword" and not hasPass:
300 defaultPass = val
301 if key == "rpcport":
302 defaults.namecoinDefaultRpcPort = val
303
304 nmc.close ()
305 except IOError:
306 logger.error("%s unreadable or missing, Namecoin support deactivated", nmcConfig)
307 except Exception as exc:
308 logger.warning("Error processing namecoin.conf", exc_info=True)
309
310 # If still nothing found, set empty at least.
311 if (not hasUser):
312 BMConfigParser().set (configSection, "namecoinrpcuser", defaultUser)
313 if (not hasPass):
314 BMConfigParser().set (configSection, "namecoinrpcpassword", defaultPass)
315
316 # Set default port now, possibly to found value.
317 if (not hasPort):
318 BMConfigParser().set (configSection, "namecoinrpcport",
319 defaults.namecoinDefaultRpcPort)

Callers 2

loadConfigFunction · 0.90
runMethod · 0.90

Calls 4

BMConfigParserClass · 0.90
lookupNamecoinFolderFunction · 0.85
setMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected