diff --git a/oml/commands.py b/oml/commands.py index 25e1fa8..c252666 100644 --- a/oml/commands.py +++ b/oml/commands.py @@ -154,7 +154,7 @@ def command_update_static(*args): import utils setup.create_db() 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): shutil.move(old_oxjs, oxjs) if not os.path.exists(oxjs): @@ -163,7 +163,7 @@ def command_update_static(*args): os.system('cd "%s" && git pull' % oxjs) r('python3', os.path.join(oxjs, 'tools', 'build', 'build.py'), '-nogeo') 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): r('git', 'clone', '--depth', '1', 'https://code.0x2620.org/0x2620/openmedialibrary_reader.git', reader) elif os.path.exists(os.path.join(reader, '.git')): diff --git a/oml/media/txt.py b/oml/media/txt.py index ca76253..29a61c7 100644 --- a/oml/media/txt.py +++ b/oml/media/txt.py @@ -7,8 +7,9 @@ import tempfile import subprocess def cover(path): + import settings 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.wait() with open(image, 'rb') as fd: diff --git a/oml/server.py b/oml/server.py index 1993ae1..8d39872 100644 --- a/oml/server.py +++ b/oml/server.py @@ -120,11 +120,11 @@ def run(): common_handlers = [ (r'/(favicon.ico)', StaticFileHandler, {'path': settings.static_path}), - (r'/static/oxjs/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'oxjs')}), - (r'/static/cbr.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'cbr.js')}), - (r'/static/epub.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'epub.js')}), - (r'/static/pdf.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'pdf.js')}), - (r'/static/txt.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'txt.js')}), + (r'/static/oxjs/(.*)', StaticFileHandler, {'path': os.path.join(settings.top_dir, 'oxjs')}), + (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.top_dir, 'reader', 'epub.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.top_dir, 'reader', 'txt.js')}), (r'/static/(.*)', StaticFileHandler, {'path': settings.static_path}), (r'/(.*)/epub/(.*)', EpubHandler), (r'/(.*?)/reader/', ReaderHandler), diff --git a/oml/settings.py b/oml/settings.py index 346af60..0fad9ee 100644 --- a/oml/settings.py +++ b/oml/settings.py @@ -8,15 +8,17 @@ from oml.utils import get_user_id from oml import fulltext 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') -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') -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): - 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): data_path = config_path else: diff --git a/oml/tor.py b/oml/tor.py index baf1bad..adf8726 100644 --- a/oml/tor.py +++ b/oml/tor.py @@ -303,15 +303,15 @@ def torbrowser_url(sys_platform=None): def get_tor(): if sys.platform == 'darwin': 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', - 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): return path elif sys.platform == 'win32': 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 ( os.path.join('Tor Browser', 'Browser', 'TorBrowser', 'Tor', 'tor.exe'), @@ -324,16 +324,16 @@ def get_tor(): ): path = os.path.join(prefix, exe) 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: if os.path.isfile(path) and os.access(path, os.X_OK): return os.path.normpath(path) elif sys.platform.startswith('linux'): for path in ( - os.path.join(settings.base_dir, '..', 'platform_linux64', 'tor', 'tor'), - os.path.join(settings.base_dir, '..', 'platform_linux32', 'tor', 'tor'), - os.path.join(settings.base_dir, '..', 'platform_linux_armv7l', 'tor', 'tor'), - os.path.join(settings.base_dir, '..', 'platform_linux_aarch64', 'tor', 'tor'), + os.path.join(settings.top_dir, 'platform_linux64', 'tor', 'tor'), + os.path.join(settings.top_dir, 'platform_linux32', 'tor', 'tor'), + os.path.join(settings.top_dir, 'platform_linux_armv7l', '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): return os.path.normpath(path) @@ -352,7 +352,7 @@ def get_tor(): return path except: 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')) if os.path.exists(local_tor): return local_tor @@ -361,7 +361,7 @@ def get_tor(): def get_geoip(tor): geo = [] 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') ): gepipfile = os.path.join(tordir, 'geoip') @@ -383,7 +383,7 @@ def install_tor(): logger.debug('found existing tor installation') return 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: logger.debug('downloading and installing tor') if sys.platform.startswith('linux'): diff --git a/oml/utils.py b/oml/utils.py index 51295a4..c8477c0 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -485,7 +485,7 @@ def check_pidfile(pid): def ctl(*args): import settings 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') cmd = [python, 'oml'] + list(args) startupinfo = subprocess.STARTUPINFO()