summaryrefslogtreecommitdiff
path: root/browser
diff options
context:
space:
mode:
Diffstat (limited to 'browser')
-rw-r--r--browser/fsm.py4
-rw-r--r--browser/gemini.py11
-rw-r--r--browser/util.py13
3 files changed, 21 insertions, 7 deletions
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)