mirror of
https://github.com/krateng/maloja.git
synced 2025-04-15 00:10:32 +03:00
Some minor linting and reorganizing
This commit is contained in:
parent
0ccd39ffd9
commit
1e70a523b2
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,6 +5,7 @@
|
|||||||
nohup.out
|
nohup.out
|
||||||
*-old
|
*-old
|
||||||
*.yml
|
*.yml
|
||||||
|
pylintrc
|
||||||
|
|
||||||
# local actions
|
# local actions
|
||||||
scripts/*
|
scripts/*
|
||||||
|
@ -1 +1,4 @@
|
|||||||
|
# monkey patching
|
||||||
|
from . import monkey
|
||||||
|
# configuration before all else
|
||||||
|
from . import globalconf
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from .. import globalconf
|
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from doreah import settings
|
from doreah import settings
|
||||||
from doreah.control import mainfunction
|
from doreah.control import mainfunction
|
||||||
@ -10,6 +8,7 @@ import signal
|
|||||||
from .setup import setup
|
from .setup import setup
|
||||||
from . import tasks
|
from . import tasks
|
||||||
from .. import __pkginfo__ as info
|
from .. import __pkginfo__ as info
|
||||||
|
from .. import globalconf
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("#####")
|
print("#####")
|
||||||
|
@ -1,42 +1,30 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
|
||||||
from .globalconf import data_dir
|
|
||||||
|
|
||||||
|
|
||||||
# server stuff
|
# server stuff
|
||||||
from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template, HTTPResponse, BaseRequest, abort
|
from bottle import Bottle, static_file, request, response, FormsDict, redirect, BaseRequest, abort
|
||||||
import waitress
|
import waitress
|
||||||
|
|
||||||
# monkey patching
|
|
||||||
from . import monkey
|
|
||||||
# rest of the project
|
# rest of the project
|
||||||
from . import database
|
from . import database
|
||||||
from . import malojatime
|
|
||||||
from . import utilities
|
|
||||||
from . import malojauri
|
|
||||||
from .utilities import resolveImage
|
from .utilities import resolveImage
|
||||||
from .malojauri import uri_to_internal, remove_identical, compose_querystring
|
from .malojauri import uri_to_internal, remove_identical
|
||||||
from . import globalconf
|
from .globalconf import malojaconfig, data_dir
|
||||||
from .globalconf import malojaconfig
|
|
||||||
from .jinjaenv.context import jinja_environment
|
from .jinjaenv.context import jinja_environment
|
||||||
from jinja2.exceptions import TemplateNotFound
|
from .apis import init_apis
|
||||||
# doreah toolkit
|
# doreah toolkit
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
from doreah.timing import Clock
|
from doreah.timing import Clock
|
||||||
from doreah import auth
|
from doreah import auth
|
||||||
# technical
|
# technical
|
||||||
#from importlib.machinery import SourceFileLoader
|
|
||||||
import importlib
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
import setproctitle
|
import setproctitle
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import math
|
|
||||||
from css_html_js_minify import html_minify, css_minify
|
from css_html_js_minify import html_minify, css_minify
|
||||||
# url handling
|
from wand.image import Image as WandImage
|
||||||
import urllib
|
|
||||||
|
|
||||||
|
|
||||||
######
|
######
|
||||||
@ -63,14 +51,14 @@ setproctitle.setproctitle("Maloja")
|
|||||||
|
|
||||||
def generate_css():
|
def generate_css():
|
||||||
css = ""
|
css = ""
|
||||||
for f in os.listdir(os.path.join(STATICFOLDER,"css")):
|
for file in os.listdir(os.path.join(STATICFOLDER,"css")):
|
||||||
with open(os.path.join(STATICFOLDER,"css",f),"r") as fd:
|
with open(os.path.join(STATICFOLDER,"css",file),"r") as filed:
|
||||||
css += fd.read()
|
css += filed.read()
|
||||||
|
|
||||||
for f in os.listdir(data_dir['css']()):
|
for file in os.listdir(data_dir['css']()):
|
||||||
if f.endswith(".css"):
|
if file.endswith(".css"):
|
||||||
with open(os.path.join(data_dir['css'](f)),"r") as fd:
|
with open(os.path.join(data_dir['css'](file)),"r") as filed:
|
||||||
css += fd.read()
|
css += filed.read()
|
||||||
|
|
||||||
css = css_minify(css)
|
css = css_minify(css)
|
||||||
return css
|
return css
|
||||||
@ -148,8 +136,6 @@ aliases = {
|
|||||||
### API
|
### API
|
||||||
|
|
||||||
auth.authapi.mount(server=webserver)
|
auth.authapi.mount(server=webserver)
|
||||||
|
|
||||||
from .apis import init_apis
|
|
||||||
init_apis(webserver)
|
init_apis(webserver)
|
||||||
|
|
||||||
# redirects for backwards compatibility
|
# redirects for backwards compatibility
|
||||||
@ -182,14 +168,13 @@ def dynamic_image():
|
|||||||
@webserver.route("/images/<pth:re:.*\\.gif>")
|
@webserver.route("/images/<pth:re:.*\\.gif>")
|
||||||
def static_image(pth):
|
def static_image(pth):
|
||||||
|
|
||||||
type = pth.split(".")[-1]
|
ext = pth.split(".")[-1]
|
||||||
small_pth = pth + "-small"
|
small_pth = pth + "-small"
|
||||||
if os.path.exists(data_dir['images'](small_pth)):
|
if os.path.exists(data_dir['images'](small_pth)):
|
||||||
response = static_file(small_pth,root=data_dir['images']())
|
response = static_file(small_pth,root=data_dir['images']())
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from wand.image import Image
|
img = WandImage(filename=data_dir['images'](pth))
|
||||||
img = Image(filename=data_dir['images'](pth))
|
|
||||||
x,y = img.size[0], img.size[1]
|
x,y = img.size[0], img.size[1]
|
||||||
smaller = min(x,y)
|
smaller = min(x,y)
|
||||||
if smaller > 300:
|
if smaller > 300:
|
||||||
@ -199,12 +184,12 @@ def static_image(pth):
|
|||||||
response = static_file(small_pth,root=data_dir['images']())
|
response = static_file(small_pth,root=data_dir['images']())
|
||||||
else:
|
else:
|
||||||
response = static_file(pth,root=data_dir['images']())
|
response = static_file(pth,root=data_dir['images']())
|
||||||
except:
|
except Exception:
|
||||||
response = static_file(pth,root=data_dir['images']())
|
response = static_file(pth,root=data_dir['images']())
|
||||||
|
|
||||||
#response = static_file("images/" + pth,root="")
|
#response = static_file("images/" + pth,root="")
|
||||||
response.set_header("Cache-Control", "public, max-age=86400")
|
response.set_header("Cache-Control", "public, max-age=86400")
|
||||||
response.set_header("Content-Type", "image/" + type)
|
response.set_header("Content-Type", "image/" + ext)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@ -234,7 +219,6 @@ def static(name,ext):
|
|||||||
|
|
||||||
def static_html(name):
|
def static_html(name):
|
||||||
if name in aliases: redirect(aliases[name])
|
if name in aliases: redirect(aliases[name])
|
||||||
linkheaders = ["</style.css>; rel=preload; as=style"]
|
|
||||||
keys = remove_identical(FormsDict.decode(request.query))
|
keys = remove_identical(FormsDict.decode(request.query))
|
||||||
|
|
||||||
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
|
adminmode = request.cookies.get("adminmode") == "true" and auth.check(request)
|
||||||
@ -242,19 +226,18 @@ def static_html(name):
|
|||||||
clock = Clock()
|
clock = Clock()
|
||||||
clock.start()
|
clock.start()
|
||||||
|
|
||||||
LOCAL_CONTEXT = {
|
loc_context = {
|
||||||
"adminmode":adminmode,
|
"adminmode":adminmode,
|
||||||
"config":malojaconfig,
|
"config":malojaconfig,
|
||||||
"apikey":request.cookies.get("apikey") if adminmode else None,
|
"apikey":request.cookies.get("apikey") if adminmode else None,
|
||||||
"_urikeys":keys, #temporary!
|
"_urikeys":keys, #temporary!
|
||||||
}
|
}
|
||||||
lc = LOCAL_CONTEXT
|
loc_context["filterkeys"], loc_context["limitkeys"], loc_context["delimitkeys"], loc_context["amountkeys"], loc_context["specialkeys"] = uri_to_internal(keys)
|
||||||
lc["filterkeys"], lc["limitkeys"], lc["delimitkeys"], lc["amountkeys"], lc["specialkeys"] = uri_to_internal(keys)
|
|
||||||
|
|
||||||
template = jinja_environment.get_template(name + '.jinja')
|
template = jinja_environment.get_template(name + '.jinja')
|
||||||
try:
|
try:
|
||||||
res = template.render(**LOCAL_CONTEXT)
|
res = template.render(**loc_context)
|
||||||
except (ValueError, IndexError) as e:
|
except (ValueError, IndexError):
|
||||||
abort(404,"This Artist or Track does not exist")
|
abort(404,"This Artist or Track does not exist")
|
||||||
|
|
||||||
if malojaconfig["DEV_MODE"]: jinja_environment.cache.clear()
|
if malojaconfig["DEV_MODE"]: jinja_environment.cache.clear()
|
||||||
@ -300,7 +283,7 @@ def graceful_exit(sig=None,frame=None):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log("Error while shutting down!",e)
|
log("Error while shutting down!",e)
|
||||||
log("Server shutting down...")
|
log("Server shutting down...")
|
||||||
os._exit(42)
|
sys.exit(0)
|
||||||
|
|
||||||
#set graceful shutdown
|
#set graceful shutdown
|
||||||
signal.signal(signal.SIGINT, graceful_exit)
|
signal.signal(signal.SIGINT, graceful_exit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user