pandora_amp/install.py

83 lines
2.6 KiB
Python
Raw Normal View History

2018-11-05 20:26:47 +00:00
#!/usr/bin/python3
import re
2015-09-20 15:58:31 +00:00
import os
from os.path import join, abspath, basename, dirname
2016-11-29 22:02:48 +00:00
name = 'amp'
2015-09-20 15:58:31 +00:00
base = abspath(dirname(__file__))
os.chdir(base)
for root, folders, files in os.walk(join(base, 'static')):
for f in files:
src = join(root, f)
target = src.replace(base, '/srv/pandora')
rel_src = os.path.relpath(src, dirname(target))
2016-11-29 22:02:48 +00:00
if os.path.exists(target) or os.path.islink(target):
2015-09-20 15:58:31 +00:00
os.unlink(target)
os.symlink(rel_src, target)
'''
overwrite = (
('home', 'indiancinema'),
('infoView', 'indiancinema'),
)
os.chdir('/srv/pandora/static/js')
for filename, sitename in overwrite:
src = '%s.%s.js' % (filename, sitename)
target = '%s.%s.js' % (filename, name)
if os.path.exists(target):
os.unlink(target)
os.symlink(src, target)
'''
os.chdir(base)
src = join(base, 'config.jsonc')
target = '/srv/pandora/pandora/config.%s.jsonc' % name
rel_src = os.path.relpath(src, dirname(target))
if os.path.exists(target):
os.unlink(target)
os.symlink(rel_src, target)
t = '/srv/pandora/pandora/config.jsonc'
if os.path.exists(t):
os.unlink(t)
os.symlink(basename(target), t)
for root, folders, files in os.walk(join(base, 'scripts')):
for f in files:
2018-11-05 20:26:47 +00:00
if f.endswith('.pyc'):
continue
2015-09-20 15:58:31 +00:00
src = join(root, f)
target = src.replace(base, '/srv/pandora')
rel_src = os.path.relpath(src, dirname(target))
2016-11-29 22:02:48 +00:00
if os.path.exists(target) or os.path.islink(target):
2015-09-20 15:58:31 +00:00
os.unlink(target)
2018-11-05 20:26:47 +00:00
print(rel_src, target)
2015-09-20 15:58:31 +00:00
os.symlink(rel_src, target)
2018-11-05 19:45:42 +00:00
if os.path.exists('__init__.py'):
# make module available to pandora
target = os.path.join('/srv/pandora/pandora/', name)
rel_src = os.path.relpath(base, dirname(target))
if os.path.exists(target):
os.unlink(target)
os.symlink(rel_src, target)
# include module in local settings
local_settings_py = '/srv/pandora/pandora/local_settings.py'
with open(local_settings_py) as fd:
local_settings_changed = False
local_settings = fd.read()
if 'LOCAL_APPS' not in local_settings:
local_settings += '\nLOCAL_APPS = ["%s"]\n' % name
local_settings_changed = True
else:
apps = re.compile('(LOCAL_APPS.*?)\]', re.DOTALL).findall(local_settings)[0]
if name not in apps:
new_apps = apps.strip() + ',\n"%s"\n' % name
local_settings = local_settings.replace(apps, new_apps)
local_settings_changed = True
if local_settings_changed:
with open(local_settings_py, 'w') as fd:
fd.write(local_settings)