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 0ef7784..50c9631 100755 --- a/server.py +++ b/server.py @@ -7,8 +7,13 @@ import waitress import monkey # rest of the project import database +import htmlmodules +import htmlgenerators +import malojatime +import utilities from utilities import resolveImage from urihandler import uri_to_internal, remove_identical +import urihandler # doreah toolkit from doreah import settings from doreah.logging import log @@ -19,6 +24,8 @@ import sys import signal import os import setproctitle +# url handling +import urllib @@ -141,50 +148,69 @@ 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") and settings.get_settings("USE_PYHP"): + from doreah.pyhp import file + 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["htmlgenerators"] = htmlgenerators + environ["malojatime"] = malojatime + environ["utilities"] = utilities + environ["urihandler"] = urihandler + # 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: - content = SourceFileLoader(name,"website/" + name + ".py").load_module().instructions(keys) - if isinstance(content,str): redirect(content) - txt_keys, resources = content - except HTTPResponse as e: - raise - 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="") # Shortlinks diff --git a/settings/default.ini b/settings/default.ini index ebf58e4..0087509 100644 --- a/settings/default.ini +++ b/settings/default.ini @@ -56,3 +56,4 @@ NAME = "Generic Maloja User" [Misc] EXPERIMENTAL_FEATURES = no +USE_PYHP = no diff --git a/website/artist.pyhp b/website/artist.pyhp new file mode 100644 index 0000000..23141c9 --- /dev/null +++ b/website/artist.pyhp @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Maloja - <pyhp echo="artist" /> + + + + + + + + + + + + + + + +
+
+
+

+ +
+ +

Scrobbles

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

Top Tracks

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

Pulse

+ + + + + + + + + + +

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

Performance

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

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

Last Scrobbles

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

+ +

Scrobbles

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

Pulse

+ + + + + + + + + + +

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

Performance

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

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

Last Scrobbles

+ + + + + + + + +