move config to data folder, fixes #171

This commit is contained in:
j 2016-01-18 12:04:20 +05:30
parent 0e87b10079
commit b05618f50a
7 changed files with 61 additions and 43 deletions

15
ctl
View file

@ -10,9 +10,18 @@ BASE=`pwd`
SYSTEM=`uname -s`
PLATFORM=`uname -m`
DATA="$BASE/data"
if [ ! -e "$DATA" ] && [ -e "$BASE/config" ]; then
#mv "$BASE/config" "$DATA"
DATA="$BASE/config"
else
if [ ! -e "$BASE/data/release.json" ] && [ -e "$BASE/config/release.json" ]; then
mv "$BASE/config/release.json" "$BASE/data/release.json"
fi
fi
if [ ! -e $PID ]; then
if [ -e "$BASE/config/tor/hostname" ]; then
onion=$(cat "$BASE/config/tor/hostname")
if [ -e "$DATA/tor/hostname" ]; then
onion=$(cat "$DATA/tor/hostname")
id=${onion/.onion/}
PID="/tmp/$NAME.$USER.$id.pid"
fi
@ -44,7 +53,7 @@ fi
PYTHONPATH="$PLATFORM_ENV/lib/python3.4/site-packages:$SHARED_ENV/lib/python3.4/site-packages:$BASE/$NAME"
export PYTHONPATH
oxCACHE="$BASE/config/ox"
oxCACHE="$DATA/ox"
export oxCACHE
#must be called to update commands in $PATH

22
install
View file

@ -20,8 +20,10 @@ class Install(Thread):
status = {}
failed = False
def __init__(self, target):
def __init__(self, target, base_url=None):
self.target = target
if base_url:
self.base_url = base_url
Thread.__init__(self)
self.daemon = True
self.start()
@ -90,18 +92,19 @@ class Install(Thread):
self.failed = True
return
target = self.target
target = os.path.normpath(os.path.join(os.path.abspath(target)))
target = os.path.normpath(os.path.abspath(target))
makedirs(target)
os.chdir(target)
release = self.get_release()
self.status['release'] = release
for module in release['modules']:
print("Installing Open Media Library:")
for module in sorted(release['modules']):
self.status['installing'] = module
self.status['progress'] = 0
self.status['size'] = 0
package_tar = release['modules'][module]['name']
url = self.url(package_tar)
package_tar = os.path.join(self.target, package_tar)
package_tar = os.path.join(target, package_tar)
self.download(url, package_tar)
tar = tarfile.open(package_tar)
tar.extractall()
@ -110,13 +113,14 @@ class Install(Thread):
os.symlink('openmedialibrary/ctl', 'ctl')
self.status['progress'] = 0
self.status['installing'] = 'setup'
if sys.platform.startswith('linux'):
os.system('./ctl install_launcher')
makedirs('config')
with open('config/release.json', 'w') as fd:
json.dump(release, fd, indent=2)
makedirs('updates')
os.system('./ctl setup')
release_path = 'data/release.json'
makedirs('data')
with open(release_path, 'w') as fd:
json.dump(release, fd, indent=2)
if sys.platform.startswith('linux'):
os.system('./ctl install_launcher')
self.status['progress'] = 1
self.status['done'] = True

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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)

View file

@ -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'])