def getConfig():
try:
with open('%s/visionarypm.conf' % path) as f:
config = json.loads(f.read().strip())
if config['oLen'] < 16 or config['oLen'] > 64 or config['cost'] < 10 or config['cost'] > 20 or config['nwords'] > 16 or config['nwords'] < 4:
exit('Invalid config! Please delete the configuration file (%s) and a new one will be generated on the next run.' % (path + '/visionarypm.conf'))
return config, 1
except IOError:
config = get_defaults()
autosave = safe_input('Do you want to save this config? (Y/n) ').lower()
if autosave == 'yes' or autosave == 'y' or autosave == '':
print('\nAutosaving configuration...')
try:
with open('%s/visionarypm.conf' % path, 'a') as f:
f.write(json.dumps(config))
return config, 1
except:
print(color('Autosaving failed! [Permission denied]\n', Fore.RED))
print('In order to save these settings, place %s' % color(json.dumps(config), Fore.YELLOW))
print('in %s' % (color('%s/visionarypm.conf' % path, Fore.YELLOW)))
return config, 0
except (KeyError, json.decoder.JSONDecodeError):
exit('Invalid config! Please delete the configuration file (%s) and a new one will be generated on the next run.' % (path + '/visionarypm.conf'))
评论列表
文章目录