From ab648db336e117e551b1063093e28bfef78abf9d Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 21 May 2019 17:29:07 +0200 Subject: [PATCH 1/5] Experimental use of pyhp for artist page --- server.py | 96 +++++++++++++++-------- website/artist.pyhp | 156 +++++++++++++++++++++++++++++++++++++ website/common/header.html | 2 +- 3 files changed, 221 insertions(+), 33 deletions(-) create mode 100644 website/artist.pyhp diff --git a/server.py b/server.py index c98fee2..aa2957d 100755 --- a/server.py +++ b/server.py @@ -7,6 +7,9 @@ import waitress import monkey # rest of the project import database +import utilities +import htmlmodules +import malojatime from utilities import * from urihandler import uri_to_internal, remove_identical # doreah toolkit @@ -20,6 +23,7 @@ import signal import os import setproctitle # url handling +import urllib import urllib.request import urllib.parse from urllib.error import * @@ -128,46 +132,74 @@ def static_html(name): linkheaders = ["; rel=preload; as=style"] keys = remove_identical(FormsDict.decode(request.query)) - with open("website/" + name + ".html") as htmlfile: - html = htmlfile.read() + # if a pyhp file exists, use this + if os.path.exists("website/" + name + ".pyhp"): + from doreah.pyhp import file + #try: + # d = SourceFileLoader(name,"website/" + name + ".py").load_module().pyhp(keys) + # print("loaded dict") + #except: + # d = {} + # print("error") + # raise + environ = {} #things we expose to the pyhp pages - # apply global substitutions - with open("website/common/footer.html") as footerfile: - footerhtml = footerfile.read() - with open("website/common/header.html") as headerfile: - headerhtml = headerfile.read() - html = html.replace("",footerhtml + "").replace("",headerhtml + "") + # maloja + environ["db"] = database + environ["htmlmodules"] = htmlmodules + environ["malojatime"] = malojatime + environ["utilities"] = utilities + # external + environ["urllib"] = urllib + # request + environ["filterkeys"], environ["limitkeys"], environ["delimitkeys"], environ["amountkeys"] = uri_to_internal(keys) + + #response.set_header("Content-Type","application/xhtml+xml") + return file("website/" + name + ".pyhp",environ) + + # if not, use the old way + else: + + with open("website/" + name + ".html") as htmlfile: + html = htmlfile.read() + + # apply global substitutions + with open("website/common/footer.html") as footerfile: + footerhtml = footerfile.read() + with open("website/common/header.html") as headerfile: + headerhtml = headerfile.read() + html = html.replace("",footerhtml + "").replace("",headerhtml + "") - # If a python file exists, it provides the replacement dict for the html file - if os.path.exists("website/" + name + ".py"): - #txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT) - try: - txt_keys,resources = SourceFileLoader(name,"website/" + name + ".py").load_module().instructions(keys) - except Exception as e: - log("Error in website generation: " + str(sys.exc_info()),module="error") - raise + # If a python file exists, it provides the replacement dict for the html file + if os.path.exists("website/" + name + ".py"): + #txt_keys = SourceFileLoader(name,"website/" + name + ".py").load_module().replacedict(keys,DATABASE_PORT) + try: + txt_keys,resources = SourceFileLoader(name,"website/" + name + ".py").load_module().instructions(keys) + except Exception as e: + log("Error in website generation: " + str(sys.exc_info()),module="error") + raise - # add headers for server push - for resource in resources: - if all(ord(c) < 128 for c in resource["file"]): - # we can only put ascii stuff in the http header - linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"]) + # add headers for server push + for resource in resources: + if all(ord(c) < 128 for c in resource["file"]): + # we can only put ascii stuff in the http header + linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"]) - # apply key substitutions - for k in txt_keys: - if isinstance(txt_keys[k],list): - # if list, we replace each occurence with the next item - for element in txt_keys[k]: - html = html.replace(k,element,1) - else: - html = html.replace(k,txt_keys[k]) + # apply key substitutions + for k in txt_keys: + if isinstance(txt_keys[k],list): + # if list, we replace each occurence with the next item + for element in txt_keys[k]: + html = html.replace(k,element,1) + else: + html = html.replace(k,txt_keys[k]) - response.set_header("Link",",".join(linkheaders)) + response.set_header("Link",",".join(linkheaders)) - return html - #return static_file("website/" + name + ".html",root="") + return html + #return static_file("website/" + name + ".html",root="") #set graceful shutdown signal.signal(signal.SIGINT, graceful_exit) diff --git a/website/artist.pyhp b/website/artist.pyhp new file mode 100644 index 0000000..51ce1d9 --- /dev/null +++ b/website/artist.pyhp @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Maloja - <pyhp echo="artist" /> + + + + + + + + + + + + + + + +
+
+
+

+ +
+ +

Scrobbles

+ + + + + + + + + + + + + + + + + +
+ +

Top Tracks

+ + +
+ + + + + + + + + + + + +
+

Pulse

+ + + + + + + + + + +

+ + + + + + + + + + + +
+ +

Performance

+ + + + + + + + + + + +

+ + + + + + + + + + +
+ + +

Last Scrobbles

+ + + + + + diff --git a/website/common/header.html b/website/common/header.html index 57d7fa8..7c654f7 100644 --- a/website/common/header.html +++ b/website/common/header.html @@ -1,3 +1,3 @@ - + From 7b3c72d21186214e99eb74c6a707ab4b956b22d0 Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 21 May 2019 18:03:57 +0200 Subject: [PATCH 2/5] Added artist hyperlinks --- server.py | 2 ++ website/artist.pyhp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index aa2957d..65b6095 100755 --- a/server.py +++ b/server.py @@ -9,6 +9,7 @@ import monkey import database import utilities import htmlmodules +import htmlgenerators import malojatime from utilities import * from urihandler import uri_to_internal, remove_identical @@ -147,6 +148,7 @@ def static_html(name): # maloja environ["db"] = database environ["htmlmodules"] = htmlmodules + environ["htmlgenerators"] = htmlgenerators environ["malojatime"] = malojatime environ["utilities"] = utilities # external diff --git a/website/artist.pyhp b/website/artist.pyhp index 51ce1d9..f72802a 100644 --- a/website/artist.pyhp +++ b/website/artist.pyhp @@ -10,13 +10,12 @@ - - + @@ -24,9 +23,12 @@ - + + + + @@ -119,7 +121,7 @@ -

Performance

+

Performance

From 15970ff2c63561e4129d392a32c3528236f0ee5b Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 23 May 2019 16:39:30 +0200 Subject: [PATCH 3/5] Switched track page to pyhp --- server.py | 2 + website/artist.pyhp | 15 ++--- website/track.pyhp | 133 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 7 deletions(-) create mode 100644 website/track.pyhp diff --git a/server.py b/server.py index 65b6095..f3fc78b 100755 --- a/server.py +++ b/server.py @@ -13,6 +13,7 @@ import htmlgenerators import malojatime from utilities import * from urihandler import uri_to_internal, remove_identical +import urihandler # doreah toolkit from doreah import settings from doreah.logging import log @@ -151,6 +152,7 @@ def static_html(name): environ["htmlgenerators"] = htmlgenerators environ["malojatime"] = malojatime environ["utilities"] = utilities + environ["urihandler"] = urihandler # external environ["urllib"] = urllib # request diff --git a/website/artist.pyhp b/website/artist.pyhp index f72802a..23141c9 100644 --- a/website/artist.pyhp +++ b/website/artist.pyhp @@ -26,8 +26,9 @@ - - + + + @@ -54,7 +55,7 @@
-

Scrobbles

+

Scrobbles

@@ -76,7 +77,7 @@ -

Top Tracks

+

Top Tracks


@@ -95,7 +96,7 @@ -

Pulse

+

Pulse

@@ -121,7 +122,7 @@ -

Performance

+

Performance

@@ -149,7 +150,7 @@ -

Last Scrobbles

+

Last Scrobbles

diff --git a/website/track.pyhp b/website/track.pyhp new file mode 100644 index 0000000..845beb0 --- /dev/null +++ b/website/track.pyhp @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + Maloja - <pyhp echo="track['title']" /> + + + + + + + + + + + +
+
+
+
+

+ +

Scrobbles

+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + +
+

Pulse

+ + + + + + + + + + +

+ + + + + + + + + + + +
+ +

Performance

+ + + + + + + + + + + +

+ + + + + + + + + + +
+ + +

Last Scrobbles

+ + + + + + + + + From 00a8f1101c3dc904d77f5e37d5d53d95d1e52719 Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 13 Jun 2019 12:28:57 +0200 Subject: [PATCH 4/5] Implemented certification display from master --- website/track.pyhp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/track.pyhp b/website/track.pyhp index 845beb0..f78d0c3 100644 --- a/website/track.pyhp +++ b/website/track.pyhp @@ -5,7 +5,7 @@ - + @@ -29,7 +29,7 @@
-

+

Scrobbles

From 3746111ee878e90e0ab8a79d56ecb52c2573d287 Mon Sep 17 00:00:00 2001 From: Krateng Date: Thu, 24 Oct 2019 20:51:49 +0200 Subject: [PATCH 5/5] Updated to new pyhp --- .doreah | 2 ++ requirements.txt | 2 +- server.py | 9 +-------- settings/default.ini | 1 + 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.doreah b/.doreah index 5d9d026..29356ba 100644 --- a/.doreah +++ b/.doreah @@ -8,3 +8,5 @@ caching: folder: "cache/" regular: autostart: false +pyhp: + version: 2 diff --git a/requirements.txt b/requirements.txt index b5aa9c9..9dd1d56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ bottle>=0.12.16 waitress>=1.3 -doreah>=1.1.7 +doreah>=1.2 nimrodel>=0.4.9 setproctitle>=1.1.10 wand>=0.5.4 diff --git a/server.py b/server.py index 114a706..50c9631 100755 --- a/server.py +++ b/server.py @@ -149,15 +149,8 @@ def static_html(name): keys = remove_identical(FormsDict.decode(request.query)) # if a pyhp file exists, use this - if os.path.exists("website/" + name + ".pyhp"): + if os.path.exists("website/" + name + ".pyhp") and settings.get_settings("USE_PYHP"): from doreah.pyhp import file - #try: - # d = SourceFileLoader(name,"website/" + name + ".py").load_module().pyhp(keys) - # print("loaded dict") - #except: - # d = {} - # print("error") - # raise environ = {} #things we expose to the pyhp pages # maloja diff --git a/settings/default.ini b/settings/default.ini index d96ec0b..ec7e552 100644 --- a/settings/default.ini +++ b/settings/default.ini @@ -56,3 +56,4 @@ NAME = "Generic Maloja User" [Misc] EXPERIMENTAL_FEATURES = no +USE_PYHP = no