diff --git a/.gitignore b/.gitignore index 2e35fa0..86b929b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ *~ build/ dist/ +rec/ +*.egg-info/ diff --git a/server/cli.py b/server/cli.py index ee9b099..49107c9 100644 --- a/server/cli.py +++ b/server/cli.py @@ -1,4 +1,5 @@ import os +import os.path import sys from argparse import ArgumentParser, Action from datetime import datetime @@ -74,7 +75,10 @@ def common_pre(): logger.warn("Configuration file '%s' does not exist; skipping" % path) continue configs.append(path) - os.chdir(os.path.dirname(os.path.realpath(__file__))) + if getattr(sys, 'frozen', False): + os.chdir(sys._MEIPASS) + else: + os.chdir(os.path.dirname(os.path.realpath(__file__))) for conf in configs: get_config().from_pyfile(conf) diff --git a/server/default_config.py b/server/default_config.py index 483e470..2e60c92 100644 --- a/server/default_config.py +++ b/server/default_config.py @@ -1,4 +1,6 @@ import logging +import os.path +import sys HOST = "localhost" PORT = "8000" @@ -28,13 +30,18 @@ TAG_EXTRA = {} # LICENSE URI is special because date need to be added TAG_LICENSE_URI = None +# defaults STATIC_FILES = "static/" STATIC_PAGES = "pages/" -try: - from pkg_resources import resource_filename, resource_isdir +if getattr(sys, 'frozen', False): # pyinstaller + STATIC_FILES = os.path.join(sys._MEIPASS, STATIC_FILES) + STATIC_PAGES = os.path.join(sys._MEIPASS, STATIC_PAGES) +else: + try: + from pkg_resources import resource_filename, resource_isdir - if resource_isdir("techrec", "pages"): - STATIC_PAGES = resource_filename("techrec", "pages") - STATIC_FILES = resource_filename("techrec", "static") -except ImportError: - logging.exception("Error loading resources from installed part") + if resource_isdir("techrec", "pages"): + STATIC_PAGES = resource_filename("techrec", "pages") + STATIC_FILES = resource_filename("techrec", "static") + except ImportError: + logging.exception("Error loading resources from installed part") diff --git a/techrec.spec b/techrec.spec new file mode 100644 index 0000000..0b8b0a4 --- /dev/null +++ b/techrec.spec @@ -0,0 +1,51 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + + +a = Analysis( + ["server/cli.py"], + pathex=["."], + binaries=[], + datas=[ + ("server/default_config.py", "."), + ("server/pages/", "pages/"), + ("server/static/", "static/"), + ], + hiddenimports=[ + "techrec.cli", + "techrec.config_manager", + "techrec.db", + "techrec.default_config", + "techrec.forge", + "techrec.maint", + "techrec.processqueue", + "techrec.server", + "techrec.test_forge", + ], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name="techrec", + debug=False, + bootloader_ignore_signals=False, + strip=True, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, +) +# vim: set ft=python: