summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/extensions/print_pdf.py20
-rw-r--r--lib/i18n.py16
-rwxr-xr-xlib/utils/paths.py13
-rwxr-xr-xlib/utils/version.py19
4 files changed, 19 insertions, 49 deletions
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index afef673d..3fb6a6a3 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -21,13 +21,14 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from lxml import etree
from werkzeug.serving import make_server
-from .base import InkstitchExtension
from ..debug.debug import debug
from ..i18n import _, get_languages
from ..i18n import translation as inkstitch_translation
from ..stitch_plan import stitch_groups_to_stitch_plan
from ..svg import render_stitch_plan
from ..threads import ThreadCatalog
+from ..utils import get_resource_dir
+from .base import InkstitchExtension
def datetimeformat(value, format='%Y/%m/%d'):
@@ -111,13 +112,7 @@ class PrintPreviewServer(Thread):
self.__setup_app()
def __set_resources_path(self):
- if getattr(sys, 'frozen', False):
- if sys.platform == "darwin":
- self.resources_path = os.path.join(sys._MEIPASS, "..", 'Resources', 'print', 'resources')
- else:
- self.resources_path = os.path.join(sys._MEIPASS, 'print', 'resources')
- else:
- self.resources_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'print', 'resources'))
+ self.resources_path = os.path.join(get_resource_dir('print'), 'resources')
def __setup_app(self): # noqa: C901
self.__set_resources_path()
@@ -313,14 +308,7 @@ class PrintInfoFrame(wx.Frame):
class Print(InkstitchExtension):
def build_environment(self):
- if getattr(sys, 'frozen', False):
- if sys.platform == "darwin":
- print_dir = os.path.join(sys._MEIPASS, "..", 'Resources', "print")
- else:
- print_dir = os.path.join(sys._MEIPASS, "print")
- else:
- print_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "print"))
-
+ print_dir = get_resource_dir('print')
template_dir = os.path.join(print_dir, "templates")
env = Environment(
diff --git a/lib/i18n.py b/lib/i18n.py
index 0a35ae25..2a901a0e 100644
--- a/lib/i18n.py
+++ b/lib/i18n.py
@@ -5,10 +5,8 @@
import gettext
import os
-import sys
-from os.path import dirname, realpath
-from .utils import cache
+from .utils import cache, get_resource_dir
_ = translation = None
locale_dir = None
@@ -23,17 +21,7 @@ def N_(message): return message
def _set_locale_dir():
global locale_dir
-
- if getattr(sys, 'frozen', False):
- # we are in a pyinstaller installation
- locale_dir = sys._MEIPASS
- else:
- locale_dir = dirname(dirname(realpath(__file__)))
-
- if sys.platform == "darwin" and getattr(sys, 'frozen', False):
- locale_dir = os.path.join(locale_dir, "..", 'Resources', 'locales')
- else:
- locale_dir = os.path.join(locale_dir, 'locales')
+ locale_dir = get_resource_dir('locales')
def localize(languages=None):
diff --git a/lib/utils/paths.py b/lib/utils/paths.py
index 10d72de9..2e9faa59 100755
--- a/lib/utils/paths.py
+++ b/lib/utils/paths.py
@@ -10,14 +10,19 @@ from os.path import dirname, realpath
import appdirs
-def get_bundled_dir(name):
+def get_bundled_dir(name=None):
if getattr(sys, 'frozen', None) is not None:
if sys.platform == "darwin":
- return realpath(os.path.join(sys._MEIPASS, "..", 'Resources', name))
+ path = os.path.join(sys._MEIPASS, "..", 'Resources')
else:
- return realpath(os.path.join(sys._MEIPASS, "..", name))
+ path = os.path.join(sys._MEIPASS, "..")
else:
- return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name))
+ path = os.path.join(dirname(realpath(__file__)), '..', '..')
+
+ if name is not None:
+ path = os.path.join(path, name)
+
+ return realpath(path)
def get_resource_dir(name):
diff --git a/lib/utils/version.py b/lib/utils/version.py
index eaa539b8..f4959a41 100755
--- a/lib/utils/version.py
+++ b/lib/utils/version.py
@@ -3,14 +3,14 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-import sys
-from os.path import isfile, join, realpath
+from os.path import isfile, join
from ..i18n import _
+from ..utils import get_bundled_dir
def get_inkstitch_version():
- version = _get_source_file("VERSION")
+ version = join(get_bundled_dir(), "VERSION")
if isfile(version):
with open(version, 'r') as v:
inkstitch_version = _("Ink/Stitch Version: %s") % v.readline()
@@ -20,21 +20,10 @@ def get_inkstitch_version():
def get_inkstitch_license():
- license = _get_source_file("LICENSE")
+ license = join(get_bundled_dir(), "LICENSE")
if isfile(license):
with open(license, 'r') as lcs:
license = lcs.read()
else:
license = "License: GNU GENERAL PUBLIC LICENSE\nVersion 3, 29 June 2007"
return license
-
-
-def _get_source_file(filename):
- if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
- if sys.platform == "darwin":
- source_file = realpath(join(sys._MEIPASS, "..", 'Resources', filename))
- else:
- source_file = realpath(join(sys._MEIPASS, "..", filename))
- else:
- source_file = realpath(join(realpath(__file__), "..", "..", "..", filename))
- return source_file