summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Singleton <matt@xcolour.net>2022-01-19 19:03:01 -0600
committerMatt Singleton <matt@xcolour.net>2022-01-19 19:03:01 -0600
commit616371e01fa96653bd43f4384a6b8ef68b3661b5 (patch)
treef156998b6de2ad66ef72423a309f8df99140892b
parent35a197f5e5263bfb0e7d41717b2153c03e50008d (diff)
get it working with pyinstaller on macos
-rw-r--r--.gitignore3
-rw-r--r--browser/fsm.py4
-rw-r--r--browser/gemini.py11
-rw-r--r--browser/util.py13
-rw-r--r--requirements.txt6
5 files changed, 30 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index f7275bb..cc2549e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
venv/
+build/
+dist/
+Gemini Browser.spec
diff --git a/browser/fsm.py b/browser/fsm.py
index eccfc6e..c8c4e85 100644
--- a/browser/fsm.py
+++ b/browser/fsm.py
@@ -2,6 +2,8 @@ import html
import sys
import urllib.parse
+from util import resource_path
+
class StackFSM(object):
"""
@@ -105,7 +107,7 @@ class Parser(object):
if url_parts.scheme in ('gemini', ''):
external = ''
else:
- external = open('external_link.svg').read()
+ external = open(resource_path('resources/external_link.svg')).read()
if len(parts) == 1:
text = url
else:
diff --git a/browser/gemini.py b/browser/gemini.py
index 7bedda5..a26f8fc 100644
--- a/browser/gemini.py
+++ b/browser/gemini.py
@@ -6,6 +6,7 @@ import string
import urllib.parse
import fsm
+from util import resource_path
def htmlescape(text: str) -> str:
@@ -16,19 +17,19 @@ def gem2html(gem: dict) -> str:
params = {
'charset': 'utf-8',
'lang': 'en',
- 'css': open('style.css').read()
+ 'css': open(resource_path('resources/style.css')).read()
}
if gem['status'][0] == '2':
- template = string.Template(open('page_template.html').read())
+ template = string.Template(open(resource_path('resources/page_template.html')).read())
body = io.StringIO()
parser = fsm.Parser(gem['body'].split('\n'), body)
parser.parse()
params['body'] = body.getvalue()
elif gem['status'][0] == '1':
- template = string.Template(open('input_template.html').read())
+ template = string.Template(open(resource_path('resources/input_template.html')).read())
params['meta'] = gem['meta']
else:
- template = string.Template(open('error_template.html').read())
+ template = string.Template(open(resource_path('resources/error_template.html')).read())
if gem['status'] == '00':
params['status'] = 'CLIENT ERROR'
elif gem['status'][0] == '4':
@@ -40,8 +41,6 @@ def gem2html(gem: dict) -> str:
params['meta'] = gem['meta']
html = template.substitute(params)
- with open('latest.html', 'w') as fp:
- fp.write(html)
return html
diff --git a/browser/util.py b/browser/util.py
new file mode 100644
index 0000000..3d504b3
--- /dev/null
+++ b/browser/util.py
@@ -0,0 +1,13 @@
+import os
+import sys
+
+
+def resource_path(relative_path: str) -> str:
+ # https://stackoverflow.com/a/13790741
+ try:
+ base_path = sys._MEIPASS
+ except Exception:
+ base_path = os.path.abspath(".")
+ with open('/Users/matt/devel/gemini-client/applog.txt', 'w') as fp:
+ fp.write(os.path.join(base_path, relative_path))
+ return os.path.join(base_path, relative_path)
diff --git a/requirements.txt b/requirements.txt
index e69de29..01d75a4 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -0,0 +1,6 @@
+altgraph==0.17.2
+macholib==1.15.2
+pyinstaller==4.8
+pyinstaller-hooks-contrib==2021.5
+PySide2==5.15.2.1
+shiboken2==5.15.2.1