move config to data folder, fixes #171
This commit is contained in:
parent
0e87b10079
commit
b05618f50a
7 changed files with 61 additions and 43 deletions
|
|
@ -12,30 +12,35 @@ base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file_
|
|||
static_path = os.path.join(base_dir, 'static')
|
||||
updates_path = os.path.normpath(os.path.join(base_dir, '..', 'updates'))
|
||||
|
||||
oml_config_path = os.path.join(base_dir, 'config.json')
|
||||
|
||||
config_path = os.path.normpath(os.path.join(base_dir, '..', 'config'))
|
||||
if not os.path.exists(config_path):
|
||||
os.makedirs(config_path)
|
||||
|
||||
db_path = os.path.join(config_path, 'data.db')
|
||||
log_path = os.path.join(config_path, 'debug.log')
|
||||
icons_db_path = os.path.join(config_path, 'icons.db')
|
||||
key_path = os.path.join(config_path, 'node.key')
|
||||
ssl_cert_path = os.path.join(config_path, 'node.ssl.crt')
|
||||
ssl_key_path = os.path.join(config_path, 'tor', 'private_key')
|
||||
oml_data_path = os.path.join(base_dir, 'config.json')
|
||||
|
||||
|
||||
if os.path.exists(oml_config_path):
|
||||
with open(oml_config_path) as fd:
|
||||
data_path = os.path.normpath(os.path.join(base_dir, '..', 'data'))
|
||||
if not os.path.exists(data_path):
|
||||
config_path = os.path.normpath(os.path.join(base_dir, '..', 'config'))
|
||||
if os.path.exists(config_path):
|
||||
data_path = config_path
|
||||
else:
|
||||
os.makedirs(data_path)
|
||||
|
||||
db_path = os.path.join(data_path, 'data.db')
|
||||
log_path = os.path.join(data_path, 'debug.log')
|
||||
icons_db_path = os.path.join(data_path, 'icons.db')
|
||||
key_path = os.path.join(data_path, 'node.key')
|
||||
ssl_cert_path = os.path.join(data_path, 'node.ssl.crt')
|
||||
ssl_key_path = os.path.join(data_path, 'tor', 'private_key')
|
||||
|
||||
|
||||
if os.path.exists(oml_data_path):
|
||||
with open(oml_data_path) as fd:
|
||||
config = json.load(fd)
|
||||
else:
|
||||
config = {}
|
||||
|
||||
preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences'])
|
||||
ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui'])
|
||||
preferences = pdict(os.path.join(data_path, 'preferences.json'), config['user']['preferences'])
|
||||
ui = pdict(os.path.join(data_path, 'ui.json'), config['user']['ui'])
|
||||
|
||||
server = pdict(os.path.join(config_path, 'server.json'))
|
||||
server = pdict(os.path.join(data_path, 'server.json'))
|
||||
server_defaults = {
|
||||
'port': 9842,
|
||||
'address': '127.0.0.1',
|
||||
|
|
@ -52,7 +57,7 @@ for key in server_defaults:
|
|||
if key not in server:
|
||||
server[key] = server_defaults[key]
|
||||
|
||||
release = pdict(os.path.join(config_path, 'release.json'))
|
||||
release = pdict(os.path.join(data_path, 'release.json'))
|
||||
|
||||
if os.path.exists(key_path):
|
||||
with open(key_path, 'rb') as fd:
|
||||
|
|
|
|||
|
|
@ -362,7 +362,7 @@ def upgrade_db(old, new=None):
|
|||
)''')
|
||||
run_sql('CREATE INDEX idx_scrape_added ON scrape (added)')
|
||||
if old <= '20151118-346-7e86e68':
|
||||
old_key = os.path.join(settings.config_path, 'node.ssl.key')
|
||||
old_key = os.path.join(settings.data_path, 'node.ssl.key')
|
||||
if os.path.exists(old_key):
|
||||
os.unlink(old_key)
|
||||
if settings.OLD_USER_ID:
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ class TorDaemon(Thread):
|
|||
self.start()
|
||||
|
||||
def create_torrc(self):
|
||||
defaults = os.path.join(settings.config_path, 'torrc-defaults')
|
||||
torrc = os.path.join(settings.config_path, 'torrc')
|
||||
defaults = os.path.join(settings.data_path, 'torrc-defaults')
|
||||
torrc = os.path.join(settings.data_path, 'torrc')
|
||||
if not os.path.exists(defaults):
|
||||
with open(defaults, 'w') as fd:
|
||||
fd.write('''
|
||||
|
|
@ -44,7 +44,7 @@ CookieAuthentication 1
|
|||
fd.write('''
|
||||
DataDirectory {base}/TorData
|
||||
DirReqStatistics 0
|
||||
'''.strip().format(base=settings.config_path))
|
||||
'''.strip().format(base=settings.data_path))
|
||||
return defaults, torrc
|
||||
|
||||
def run(self):
|
||||
|
|
@ -85,7 +85,7 @@ class Tor(object):
|
|||
|
||||
def connect(self):
|
||||
self.connected = False
|
||||
self.dir = os.path.join(settings.config_path, 'tor')
|
||||
self.dir = os.path.join(settings.data_path, 'tor')
|
||||
connected = False
|
||||
for port in (9831, 9151):
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ def get_latest_release():
|
|||
return release
|
||||
|
||||
def download():
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
if not os.path.exists(os.path.join(settings.data_path, 'release.json')):
|
||||
return True
|
||||
release = get_latest_release()
|
||||
if release:
|
||||
|
|
@ -116,7 +116,7 @@ def download():
|
|||
def install(stop=True):
|
||||
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
|
||||
return True
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
if not os.path.exists(os.path.join(settings.data_path, 'release.json')):
|
||||
return True
|
||||
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
|
||||
release = json.load(fd)
|
||||
|
|
@ -147,7 +147,7 @@ def install(stop=True):
|
|||
if os.path.exists(module_tar):
|
||||
os.unlink(module_tar)
|
||||
return False
|
||||
shutil.copy(os.path.join(settings.updates_path, 'release.json'), os.path.join(settings.config_path, 'release.json'))
|
||||
shutil.copy(os.path.join(settings.updates_path, 'release.json'), os.path.join(settings.data_path, 'release.json'))
|
||||
if stop:
|
||||
subprocess.call(['./ctl', 'stop'])
|
||||
subprocess.call(['./ctl', 'postupdate', '-o', old_version, '-n', new_version])
|
||||
|
|
@ -161,7 +161,7 @@ def update_available():
|
|||
return True
|
||||
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
|
||||
return False
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
if not os.path.exists(os.path.join(settings.data_path, 'release.json')):
|
||||
return False
|
||||
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
|
||||
release = json.load(fd)
|
||||
|
|
@ -221,7 +221,7 @@ def getVersion(data):
|
|||
get_latest_release()
|
||||
if not os.path.exists(os.path.join(settings.updates_path, 'release.json')):
|
||||
return response
|
||||
if not os.path.exists(os.path.join(settings.config_path, 'release.json')):
|
||||
if not os.path.exists(os.path.join(settings.data_path, 'release.json')):
|
||||
return response
|
||||
with open(os.path.join(settings.updates_path, 'release.json')) as fd:
|
||||
release = json.load(fd)
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ def init(data):
|
|||
}
|
||||
'''
|
||||
response = {}
|
||||
if os.path.exists(settings.oml_config_path):
|
||||
with open(settings.oml_config_path) as fd:
|
||||
if os.path.exists(settings.oml_data_path):
|
||||
with open(settings.oml_data_path) as fd:
|
||||
config = json.load(fd)
|
||||
else:
|
||||
config = {}
|
||||
|
|
@ -74,7 +74,7 @@ def resetUI(data):
|
|||
takes {
|
||||
}
|
||||
'''
|
||||
ui_json = os.path.join(settings.config_path, 'ui.json')
|
||||
ui_json = os.path.join(settings.data_path, 'ui.json')
|
||||
if os.path.exists(ui_json):
|
||||
os.unlink(ui_json)
|
||||
settings.ui = settings.pdict(ui_json, settings.config['user']['ui'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue