unify top directory

This commit is contained in:
j 2024-06-10 14:57:12 +01:00
parent 4df34b28e5
commit d5ff48a1c5
6 changed files with 26 additions and 23 deletions

View file

@ -154,7 +154,7 @@ def command_update_static(*args):
import utils import utils
setup.create_db() setup.create_db()
old_oxjs = os.path.join(settings.static_path, 'oxjs') old_oxjs = os.path.join(settings.static_path, 'oxjs')
oxjs = os.path.join(settings.base_dir, '..', 'oxjs') oxjs = os.path.join(settings.top_dir, 'oxjs')
if os.path.exists(old_oxjs) and not os.path.exists(oxjs): if os.path.exists(old_oxjs) and not os.path.exists(oxjs):
shutil.move(old_oxjs, oxjs) shutil.move(old_oxjs, oxjs)
if not os.path.exists(oxjs): if not os.path.exists(oxjs):
@ -163,7 +163,7 @@ def command_update_static(*args):
os.system('cd "%s" && git pull' % oxjs) os.system('cd "%s" && git pull' % oxjs)
r('python3', os.path.join(oxjs, 'tools', 'build', 'build.py'), '-nogeo') r('python3', os.path.join(oxjs, 'tools', 'build', 'build.py'), '-nogeo')
utils.update_static() utils.update_static()
reader = os.path.join(settings.base_dir, '..', 'reader') reader = os.path.join(settings.top_dir, 'reader')
if not os.path.exists(reader): if not os.path.exists(reader):
r('git', 'clone', '--depth', '1', 'https://code.0x2620.org/0x2620/openmedialibrary_reader.git', reader) r('git', 'clone', '--depth', '1', 'https://code.0x2620.org/0x2620/openmedialibrary_reader.git', reader)
elif os.path.exists(os.path.join(reader, '.git')): elif os.path.exists(os.path.join(reader, '.git')):

View file

@ -7,8 +7,9 @@ import tempfile
import subprocess import subprocess
def cover(path): def cover(path):
import settings
image = tempfile.mkstemp('.jpg')[1] image = tempfile.mkstemp('.jpg')[1]
cmd = ['python3', '../reader/txt.js/txt.py', '-i', path, '-o', image] cmd = ['python3', os.path.join(settings.top_dir, 'reader/txt.js/txt.py'), '-i', path, '-o', image]
p = subprocess.Popen(cmd, close_fds=True) p = subprocess.Popen(cmd, close_fds=True)
p.wait() p.wait()
with open(image, 'rb') as fd: with open(image, 'rb') as fd:

View file

@ -120,11 +120,11 @@ def run():
common_handlers = [ common_handlers = [
(r'/(favicon.ico)', StaticFileHandler, {'path': settings.static_path}), (r'/(favicon.ico)', StaticFileHandler, {'path': settings.static_path}),
(r'/static/oxjs/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'oxjs')}), (r'/static/oxjs/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'oxjs')}),
(r'/static/cbr.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'cbr.js')}), (r'/static/cbr.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'reader', 'cbr.js')}),
(r'/static/epub.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'epub.js')}), (r'/static/epub.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'reader', 'epub.js')}),
(r'/static/pdf.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'pdf.js')}), (r'/static/pdf.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'reader', 'pdf.js')}),
(r'/static/txt.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'txt.js')}), (r'/static/txt.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'reader', 'txt.js')}),
(r'/static/(.*)', StaticFileHandler, {'path': settings.static_path}), (r'/static/(.*)', StaticFileHandler, {'path': settings.static_path}),
(r'/(.*)/epub/(.*)', EpubHandler), (r'/(.*)/epub/(.*)', EpubHandler),
(r'/(.*?)/reader/', ReaderHandler), (r'/(.*?)/reader/', ReaderHandler),

View file

@ -8,15 +8,17 @@ from oml.utils import get_user_id
from oml import fulltext from oml import fulltext
base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')) base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..'))
top_dir = os.path.dirname(base_dir)
static_path = os.path.join(base_dir, 'static') static_path = os.path.join(base_dir, 'static')
updates_path = os.path.normpath(os.path.join(base_dir, '..', 'updates')) updates_path = os.path.normpath(os.path.join(top_dir, 'updates'))
oml_data_path = os.path.join(base_dir, 'config.json') oml_data_path = os.path.join(base_dir, 'config.json')
data_path = os.path.normpath(os.path.join(base_dir, '..', 'data')) data_path = os.path.normpath(os.path.join(top_dir, 'data'))
if not os.path.exists(data_path): if not os.path.exists(data_path):
config_path = os.path.normpath(os.path.join(base_dir, '..', 'config')) config_path = os.path.normpath(os.path.join(top_dir, 'config'))
if os.path.exists(config_path): if os.path.exists(config_path):
data_path = config_path data_path = config_path
else: else:

View file

@ -303,15 +303,15 @@ def torbrowser_url(sys_platform=None):
def get_tor(): def get_tor():
if sys.platform == 'darwin': if sys.platform == 'darwin':
for path in ( for path in (
os.path.join(settings.base_dir, '..', 'platform_darwin64', 'tor', 'tor'), os.path.join(settings.top_dir, 'platform_darwin64', 'tor', 'tor'),
'/Applications/TorBrowser.app/TorBrowser/Tor/tor', '/Applications/TorBrowser.app/TorBrowser/Tor/tor',
os.path.join(settings.base_dir, '..', 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor') os.path.join(settings.top_dir, 'tor', 'TorBrowser.app', 'TorBrowser', 'Tor', 'tor')
): ):
if os.path.isfile(path) and os.access(path, os.X_OK): if os.path.isfile(path) and os.access(path, os.X_OK):
return path return path
elif sys.platform == 'win32': elif sys.platform == 'win32':
paths = [ paths = [
os.path.join(settings.base_dir, '..', 'platform_win32', 'tor', 'tor.exe') os.path.join(settings.top_dir, 'platform_win32', 'tor', 'tor.exe')
] ]
for exe in ( for exe in (
os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe'), os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe'),
@ -324,16 +324,16 @@ def get_tor():
): ):
path = os.path.join(prefix, exe) path = os.path.join(prefix, exe)
paths.append(path) paths.append(path)
paths.append(os.path.join(settings.base_dir, '..', 'tor', 'Tor', 'tor.exe')) paths.append(os.path.join(settings.top_dir, 'tor', 'Tor', 'tor.exe'))
for path in paths: for path in paths:
if os.path.isfile(path) and os.access(path, os.X_OK): if os.path.isfile(path) and os.access(path, os.X_OK):
return os.path.normpath(path) return os.path.normpath(path)
elif sys.platform.startswith('linux'): elif sys.platform.startswith('linux'):
for path in ( for path in (
os.path.join(settings.base_dir, '..', 'platform_linux64', 'tor', 'tor'), os.path.join(settings.top_dir, 'platform_linux64', 'tor', 'tor'),
os.path.join(settings.base_dir, '..', 'platform_linux32', 'tor', 'tor'), os.path.join(settings.top_dir, 'platform_linux32', 'tor', 'tor'),
os.path.join(settings.base_dir, '..', 'platform_linux_armv7l', 'tor', 'tor'), os.path.join(settings.top_dir, 'platform_linux_armv7l', 'tor', 'tor'),
os.path.join(settings.base_dir, '..', 'platform_linux_aarch64', 'tor', 'tor'), os.path.join(settings.top_dir, 'platform_linux_aarch64', 'tor', 'tor'),
): ):
if os.path.isfile(path) and os.access(path, os.X_OK): if os.path.isfile(path) and os.access(path, os.X_OK):
return os.path.normpath(path) return os.path.normpath(path)
@ -352,7 +352,7 @@ def get_tor():
return path return path
except: except:
pass pass
local_tor = os.path.normpath(os.path.join(settings.base_dir, '..', local_tor = os.path.normpath(os.path.join(settings.top_dir
'tor', 'tor-browser_en-US', 'Browser', 'TorBrowser', 'Tor', 'tor')) 'tor', 'tor-browser_en-US', 'Browser', 'TorBrowser', 'Tor', 'tor'))
if os.path.exists(local_tor): if os.path.exists(local_tor):
return local_tor return local_tor
@ -361,7 +361,7 @@ def get_tor():
def get_geoip(tor): def get_geoip(tor):
geo = [] geo = []
for tordir in ( for tordir in (
os.path.normpath(os.path.join(settings.base_dir, '..', 'platform', 'tor')), os.path.normpath(os.path.join(settings.top_dir, 'platform', 'tor')),
os.path.join(os.path.dirname(os.path.dirname(tor)), 'Data', 'Tor') os.path.join(os.path.dirname(os.path.dirname(tor)), 'Data', 'Tor')
): ):
gepipfile = os.path.join(tordir, 'geoip') gepipfile = os.path.join(tordir, 'geoip')
@ -383,7 +383,7 @@ def install_tor():
logger.debug('found existing tor installation') logger.debug('found existing tor installation')
return return
url = torbrowser_url() url = torbrowser_url()
target = os.path.normpath(os.path.join(settings.base_dir, '..', 'tor')) target = os.path.normpath(os.path.join(settings.top_dir, 'tor'))
if url: if url:
logger.debug('downloading and installing tor') logger.debug('downloading and installing tor')
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):

View file

@ -485,7 +485,7 @@ def check_pidfile(pid):
def ctl(*args): def ctl(*args):
import settings import settings
if sys.platform == 'win32': if sys.platform == 'win32':
platform_win32 = os.path.normpath(os.path.join(settings.base_dir, '..', 'platform_win32')) platform_win32 = os.path.normpath(os.path.join(settings.top_dir, 'platform_win32'))
python = os.path.join(platform_win32, 'pythonw.exe') python = os.path.join(platform_win32, 'pythonw.exe')
cmd = [python, 'oml'] + list(args) cmd = [python, 'oml'] + list(args)
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()