Merge pull request #166 from lbryio/daemon-settings-yml

.yml daemon settings file
This commit is contained in:
Jack Robison 2016-09-16 01:22:20 -04:00 committed by GitHub
commit a9e4343775
5 changed files with 56 additions and 17 deletions

View file

@ -112,6 +112,8 @@ init:
C:\Python27\Scripts\pip.exe install googlefinance==0.7 C:\Python27\Scripts\pip.exe install googlefinance==0.7
C:\Python27\Scripts\pip.exe install pyyaml==3.12
C:\Python27\Scripts\pip.exe install git+https://github.com/lbryio/lbryum.git C:\Python27\Scripts\pip.exe install git+https://github.com/lbryio/lbryum.git
cd C:\projects\lbry cd C:\projects\lbry

View file

@ -1,11 +1,12 @@
import base64 import base64
import distutils.version import distutils.version
import random import random
import os
import json
import yaml
from lbrynet.core.cryptoutils import get_lbry_hash_obj from lbrynet.core.cryptoutils import get_lbry_hash_obj
blobhash_length = get_lbry_hash_obj().digest_size * 2 # digest_size is in bytes, and blob hashes are hex encoded blobhash_length = get_lbry_hash_obj().digest_size * 2 # digest_size is in bytes, and blob hashes are hex encoded
@ -46,3 +47,33 @@ def deobfuscate(obfustacated):
def obfuscate(plain): def obfuscate(plain):
return base64.b64encode(plain).encode('rot13') return base64.b64encode(plain).encode('rot13')
settings_decoders = {
'.json': json.loads,
'.yml': yaml.load
}
settings_encoders = {
'.json': json.dumps,
'.yml': yaml.safe_dump
}
def load_settings(path):
ext = os.path.splitext(path)[1]
f = open(path, 'r')
data = f.read()
f.close()
decoder = settings_decoders.get(ext, False)
assert decoder is not False, "Unknown settings format .%s" % ext
return decoder(data)
def save_settings(path, settings):
ext = os.path.splitext(path)[1]
encoder = settings_encoders.get(ext, False)
assert encoder is not False, "Unknown settings format .%s" % ext
f = open(path, 'w')
f.write(encoder(settings))
f.close()

View file

@ -198,7 +198,18 @@ class LBRYDaemon(jsonrpc.JSONRPC):
log.info("Couldn't make download directory, using home") log.info("Couldn't make download directory, using home")
default_download_directory = os.path.expanduser("~") default_download_directory = os.path.expanduser("~")
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.json') old_conf_path = os.path.join(self.db_dir, 'daemon_settings.json')
self.daemon_conf = os.path.join(self.db_dir, 'daemon_settings.yml')
if os.path.isfile(old_conf_path):
log.info("Migrating .json config file to .yml")
tmp_settings = utils.load_settings(old_conf_path)
utils.save_settings(self.daemon_conf, tmp_settings)
try:
os.remove(old_conf_path)
log.info("Cleaned up old config file")
except:
log.warning("Failed to remove old config file")
self.default_settings = { self.default_settings = {
'run_on_startup': False, 'run_on_startup': False,
@ -226,9 +237,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
} }
if os.path.isfile(self.daemon_conf): if os.path.isfile(self.daemon_conf):
f = open(self.daemon_conf, "r") loaded_settings = utils.load_settings(self.daemon_conf)
loaded_settings = json.loads(f.read())
f.close()
missing_settings = {} missing_settings = {}
removed_settings = {} removed_settings = {}
for k in self.default_settings.keys(): for k in self.default_settings.keys():
@ -268,9 +277,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
log.info("Lowering name cache time") log.info("Lowering name cache time")
self.session_settings['cache_time'] = DEFAULT_CACHE_TIME self.session_settings['cache_time'] = DEFAULT_CACHE_TIME
f = open(self.daemon_conf, "w") utils.save_settings(self.daemon_conf, self.session_settings)
f.write(json.dumps(self.session_settings))
f.close()
self.run_on_startup = self.session_settings['run_on_startup'] self.run_on_startup = self.session_settings['run_on_startup']
self.data_rate = self.session_settings['data_rate'] self.data_rate = self.session_settings['data_rate']
@ -940,9 +947,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
self.search_timeout = self.session_settings['search_timeout'] self.search_timeout = self.session_settings['search_timeout']
self.cache_time = self.session_settings['cache_time'] self.cache_time = self.session_settings['cache_time']
f = open(self.daemon_conf, "w") utils.save_settings(self.daemon_conf, self.session_settings)
f.write(json.dumps(self.session_settings))
f.close()
return defer.succeed(True) return defer.succeed(True)
@ -1406,9 +1411,7 @@ class LBRYDaemon(jsonrpc.JSONRPC):
startup_scripts = self.startup_scripts startup_scripts = self.startup_scripts
self.startup_scripts = self.session_settings['startup_scripts'] = remaining_scripts self.startup_scripts = self.session_settings['startup_scripts'] = remaining_scripts
f = open(self.daemon_conf, "w") utils.save_settings(self.daemon_conf, self.session_settings)
f.write(json.dumps(self.session_settings))
f.close()
for script in startup_scripts: for script in startup_scripts:
if script['script_name'] == 'migrateto025': if script['script_name'] == 'migrateto025':

View file

@ -28,3 +28,4 @@ wsgiref==0.1.2
zope.interface==4.1.3 zope.interface==4.1.3
base58==0.2.2 base58==0.2.2
googlefinance==0.7 googlefinance==0.7
pyyaml==3.12

View file

@ -44,7 +44,8 @@ requires = [
'six==1.9.0', 'six==1.9.0',
'base58', 'base58',
'googlefinance', 'googlefinance',
'requests_futures' 'requests_futures',
'PyYAML'
] ]
console_scripts = [ console_scripts = [
@ -273,7 +274,8 @@ elif platform == WINDOWS:
'wsgiref', 'wsgiref',
'zope.interface', 'zope.interface',
'os', 'os',
'pkg_resources' 'pkg_resources',
'yaml'
], ],
'excludes': ['distutils', 'collections.sys', 'collections._weakref', 'collections.abc', 'excludes': ['distutils', 'collections.sys', 'collections._weakref', 'collections.abc',
'Tkinter', 'tk', 'tcl', 'PyQt4', 'nose', 'mock' 'Tkinter', 'tk', 'tcl', 'PyQt4', 'nose', 'mock'