1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Replaced settings calls

This commit is contained in:
krateng 2021-12-19 21:10:55 +01:00
parent b39e2b889a
commit 4186171b8f
12 changed files with 57 additions and 56 deletions

View File

@ -3,7 +3,7 @@ from ._exceptions import *
from .. import database from .. import database
import datetime import datetime
from doreah.settings import get_settings from .globalconf import malojaconfig
class Listenbrainz(APIHandler): class Listenbrainz(APIHandler):
@ -72,7 +72,7 @@ class Listenbrainz(APIHandler):
if token not in database.allAPIkeys(): if token not in database.allAPIkeys():
raise InvalidAuthException() raise InvalidAuthException()
else: else:
return 200,{"code":200,"message":"Token valid.","valid":True,"user_name":get_settings("NAME") or 'Maloja User'} return 200,{"code":200,"message":"Token valid.","valid":True,"user_name":malojaconfig["NAME"]}
def get_token_from_request_keys(self,keys): def get_token_from_request_keys(self,keys):
if 'token' in keys: if 'token' in keys:

View File

@ -1,5 +1,5 @@
from ..database import * from ..database import *
from doreah import settings from ..globalconf import malojaconfig
from ..__pkginfo__ import version from ..__pkginfo__ import version
from ..malojauri import uri_to_internal from ..malojauri import uri_to_internal
from .. import utilities from .. import utilities
@ -41,7 +41,7 @@ def server_info():
response.set_header("Content-Type","application/json") response.set_header("Content-Type","application/json")
return { return {
"name":settings.get_settings("NAME"), "name":malojaconfig["NAME"],
"version":version, "version":version,
"versionstring":".".join(str(n) for n in version), "versionstring":".".join(str(n) for n in version),
"db_status":dbstatus "db_status":dbstatus

View File

@ -1,7 +1,7 @@
import re import re
#from . import utilities #from . import utilities
from doreah import tsv, settings from doreah import tsv
from .globalconf import data_dir from .globalconf import data_dir, malojaconfig
import pkg_resources import pkg_resources
# need to do this as a class so it can retain loaded settings from file # need to do this as a class so it can retain loaded settings from file
@ -62,13 +62,13 @@ class CleanerAgent:
#Delimiters used for extra artists, even when in the title field #Delimiters used for extra artists, even when in the title field
#delimiters_feat = ["ft.","ft","feat.","feat","featuring","Ft.","Ft","Feat.","Feat","Featuring"] #delimiters_feat = ["ft.","ft","feat.","feat","featuring","Ft.","Ft","Feat.","Feat","Featuring"]
delimiters_feat = settings.get_settings("DELIMITERS_FEAT") delimiters_feat = malojaconfig["DELIMITERS_FEAT"]
#Delimiters in informal artist strings, spaces expected around them #Delimiters in informal artist strings, spaces expected around them
#delimiters = ["vs.","vs","&"] #delimiters = ["vs.","vs","&"]
delimiters = settings.get_settings("DELIMITERS_INFORMAL") delimiters = malojaconfig["DELIMITERS_FEAT"]
#Delimiters used specifically to tag multiple artists when only one tag field is available, no spaces used #Delimiters used specifically to tag multiple artists when only one tag field is available, no spaces used
#delimiters_formal = ["; ",";","/"] #delimiters_formal = ["; ",";","/"]
delimiters_formal = settings.get_settings("DELIMITERS_FORMAL") delimiters_formal = malojaconfig["DELIMITERS_FEAT"]
def parseArtists(self,a): def parseArtists(self,a):
@ -76,7 +76,7 @@ class CleanerAgent:
res = [self.parseArtists(art) for art in a] res = [self.parseArtists(art) for art in a]
return [a for group in res for a in group] return [a for group in res for a in group]
if a.strip() in settings.get_settings("INVALID_ARTISTS"): if a.strip() in malojaconfig["DELIMITERS_FEAT"]:
return [] return []
if a.strip().lower() in self.rules_ignoreartist: if a.strip().lower() in self.rules_ignoreartist:
@ -135,7 +135,7 @@ class CleanerAgent:
t = re.sub(r" \(originally by .*?\)","",t) t = re.sub(r" \(originally by .*?\)","",t)
t = re.sub(r" \(.*?Remaster.*?\)","",t) t = re.sub(r" \(.*?Remaster.*?\)","",t)
for s in settings.get_settings("REMOVE_FROM_TITLE"): for s in malojaconfig["DELIMITERS_FEAT"]:
if s in t: if s in t:
t = t.replace(s,"") t = t.replace(s,"")

View File

@ -283,7 +283,7 @@ def info():
artists = {} artists = {}
return { return {
"name":settings.get_settings("NAME"), "name":malojaconfig["NAME"],
"artists":{ "artists":{
chartentry["artist"]:round(chartentry["scrobbles"] * 100 / totalscrobbles,3) chartentry["artist"]:round(chartentry["scrobbles"] * 100 / totalscrobbles,3)
for chartentry in get_charts_artists() if chartentry["scrobbles"]/totalscrobbles >= 0 for chartentry in get_charts_artists() if chartentry["scrobbles"]/totalscrobbles >= 0
@ -476,7 +476,7 @@ def trackInfo(track):
scrobbles = c["scrobbles"] scrobbles = c["scrobbles"]
position = c["rank"] position = c["rank"]
cert = None cert = None
threshold_gold, threshold_platinum, threshold_diamond = settings.get_settings("SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND") threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND"]
if scrobbles >= threshold_diamond: cert = "diamond" if scrobbles >= threshold_diamond: cert = "diamond"
elif scrobbles >= threshold_platinum: cert = "platinum" elif scrobbles >= threshold_platinum: cert = "platinum"
elif scrobbles >= threshold_gold: cert = "gold" elif scrobbles >= threshold_gold: cert = "gold"
@ -742,7 +742,7 @@ def build_db():
scrobblenum = len(db) scrobblenum = len(db)
log(f"Found {scrobblenum} scrobbles...") log(f"Found {scrobblenum} scrobbles...")
usebar = not settings.get_settings("CLEAN_OUTPUT") usebar = not malojaconfig["CLEAN_OUTPUT"]
if usebar: pbar = ProgressBar(max=scrobblenum,prefix="Loading scrobbles") if usebar: pbar = ProgressBar(max=scrobblenum,prefix="Loading scrobbles")
else: else:
n = 0 n = 0
@ -860,7 +860,7 @@ def sync():
import copy import copy
if settings.get_settings("USE_DB_CACHE"): if malojaconfig["USE_DB_CACHE"]:
def db_query(**kwargs): def db_query(**kwargs):
return db_query_cached(**kwargs) return db_query_cached(**kwargs)
def db_aggregate(**kwargs): def db_aggregate(**kwargs):
@ -872,8 +872,8 @@ else:
return db_aggregate_full(**kwargs) return db_aggregate_full(**kwargs)
csz = settings.get_settings("DB_CACHE_ENTRIES") csz = malojaconfig["DB_CACHE_ENTRIES"]
cmp = settings.get_settings("DB_MAX_MEMORY") cmp = malojaconfig["DB_MAX_MEMORY"]
try: try:
import psutil import psutil
use_psutil = True use_psutil = True
@ -885,8 +885,8 @@ cache_query_perm = lru.LRU(csz)
cache_aggregate = lru.LRU(csz) cache_aggregate = lru.LRU(csz)
cache_aggregate_perm = lru.LRU(csz) cache_aggregate_perm = lru.LRU(csz)
perm_caching = settings.get_settings("CACHE_DATABASE_PERM") perm_caching = malojaconfig["CACHE_DATABASE_PERM"]
temp_caching = settings.get_settings("CACHE_DATABASE_SHORT") temp_caching = malojaconfig["CACHE_DATABASE_SHORT"]
cachestats = { cachestats = {
"cache_query":{ "cache_query":{

View File

@ -2,10 +2,11 @@ from datetime import timezone, timedelta, date, time, datetime
from calendar import monthrange from calendar import monthrange
from os.path import commonprefix from os.path import commonprefix
import math import math
from doreah.settings import get_settings
from .globalconf import malojaconfig
OFFSET = get_settings("TIMEZONE") OFFSET = malojaconfig["TIMEZONE"]
TIMEZONE = timezone(timedelta(hours=OFFSET)) TIMEZONE = timezone(timedelta(hours=OFFSET))
UTC = timezone.utc UTC = timezone.utc
@ -486,7 +487,7 @@ def timestamp_desc(t,short=False):
timeobj = datetime.fromtimestamp(t,tz=TIMEZONE) timeobj = datetime.fromtimestamp(t,tz=TIMEZONE)
if not short: return timeobj.strftime(get_settings("TIME_FORMAT")) if not short: return timeobj.strftime(malojaconfig["TIMEZONE"])
difference = int(datetime.now().timestamp() - t) difference = int(datetime.now().timestamp() - t)

View File

@ -45,7 +45,7 @@ def start():
sp = subprocess.Popen(["python3","-m","maloja.proccontrol.supervisor"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) sp = subprocess.Popen(["python3","-m","maloja.proccontrol.supervisor"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
print(col["green"]("Maloja started!")) print(col["green"]("Maloja started!"))
port = settings.get_settings("WEB_PORT") port = malojaconfig["WEB_PORT"]
print("Visit your server address (Port " + str(port) + ") to see your web interface. Visit /admin_setup to get started.") print("Visit your server address (Port " + str(port) + ") to see your web interface. Visit /admin_setup to get started.")
print("If you're installing this on your local machine, these links should get you there:") print("If you're installing this on your local machine, these links should get you there:")

View File

@ -1,11 +1,10 @@
import pkg_resources import pkg_resources
from distutils import dir_util from distutils import dir_util
from doreah import settings
from doreah.io import col, ask, prompt from doreah.io import col, ask, prompt
from doreah import auth from doreah import auth
import os import os
from ..globalconf import data_dir, dir_settings from ..globalconf import data_dir, dir_settings, malojaconfig
# EXTERNAL API KEYS # EXTERNAL API KEYS
@ -32,17 +31,17 @@ def randomstring(length=32):
def setup(): def setup():
copy_initial_local_files() copy_initial_local_files()
SKIP = settings.get_settings("SKIP_SETUP") SKIP = malojaconfig["SKIP_SETUP"]
print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.") print("Various external services can be used to display images. If not enough of them are set up, only local images will be used.")
for k in apikeys: for k in apikeys:
key = settings.get_settings(k) key = malojaconfig[k]
if key is False: if key is False:
print("\t" + "Currently not using a " + apikeys[k] + " for image display.") print("\t" + "Currently not using a " + apikeys[k] + " for image display.")
elif key is None or key == "ASK": elif key is None or key == "ASK":
print("\t" + "Please enter your " + col['gold'](apikeys[k]) + ". If you do not want to use one at this moment, simply leave this empty and press Enter.") print("\t" + "Please enter your " + col['gold'](apikeys[k]) + ". If you do not want to use one at this moment, simply leave this empty and press Enter.")
key = prompt("",types=(str,),default=False,skip=SKIP) key = prompt("",types=(str,),default=False,skip=SKIP)
settings.update_settings(data_dir['settings']("settings.ini"),{k:key},create_new=True) malojaconfig[k] = key
else: else:
print("\t" + apikeys[k] + " found.") print("\t" + apikeys[k] + " found.")
@ -57,8 +56,8 @@ def setup():
keyfile.write(key + "\t" + "Default Generated Key") keyfile.write(key + "\t" + "Default Generated Key")
# PASSWORD # PASSWORD
defaultpassword = settings.get_settings("DEFAULT_PASSWORD") defaultpassword = malojaconfig["DEFAULT_PASSWORD"]
forcepassword = settings.get_settings("FORCE_PASSWORD") forcepassword = malojaconfig["FORCE_PASSWORD"]
# this is mainly meant for docker, supply password via environment variable # this is mainly meant for docker, supply password via environment variable
if forcepassword is not None: if forcepassword is not None:
@ -79,13 +78,14 @@ def setup():
# we still 'ask' the user to set one, but for docker this will be skipped # we still 'ask' the user to set one, but for docker this will be skipped
newpw = prompt("Please set a password for web backend access. Leave this empty to use the default password.",skip=SKIP,default=defaultpassword,secret=True) newpw = prompt("Please set a password for web backend access. Leave this empty to use the default password.",skip=SKIP,default=defaultpassword,secret=True)
auth.defaultuser.setpw(newpw) auth.defaultuser.setpw(newpw)
if settings.get_settings("NAME") is None: if malojaconfig["NAME"] is None:
name = prompt("Please enter your name. This will be displayed e.g. when comparing your charts to another user. Leave this empty if you would not like to specify a name right now.",default="Generic Maloja User",skip=SKIP) name = prompt("Please enter your name. This will be displayed e.g. when comparing your charts to another user. Leave this empty if you would not like to specify a name right now.",default="Generic Maloja User",skip=SKIP)
settings.update_settings(data_dir['settings']("settings.ini"),{"NAME":name},create_new=True) malojaconfig["NAME"] = name
if settings.get_settings("SEND_STATS") is None: if malojaconfig["SEND_STATS"] is None:
answer = ask("I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)?",default=True,skip=SKIP) answer = ask("I would like to know how many people use Maloja. Would it be okay to send a daily ping to my server (this contains no data that isn't accessible via your web interface already)?",default=True,skip=SKIP)
if answer: if answer:
settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":True,"PUBLIC_URL":None},create_new=True) malojaconfig["SEND_STATS"] = True
malojaconfig["PUBLIC_URL"] = None
else: else:
settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":False},create_new=True) malojaconfig["SEND_STATS"] = False

View File

@ -5,8 +5,8 @@ import subprocess
import setproctitle import setproctitle
import signal import signal
from doreah.logging import log from doreah.logging import log
from doreah.settings import get_settings
from .globalconf import malojaconfig
from .control import getInstance from .control import getInstance
@ -33,7 +33,7 @@ def start():
while True: while True:
log("Maloja is not running, starting...",module="supervisor") log("Maloja is not running, starting...",module="supervisor")
if get_settings("UPDATE_AFTER_CRASH"): if malojaconfig["UPDATE_AFTER_CRASH"]:
update() update()
process = start() process = start()

View File

@ -47,8 +47,8 @@ import urllib
#settings.config(files=["settings/default.ini","settings/settings.ini"]) #settings.config(files=["settings/default.ini","settings/settings.ini"])
#settings.update("settings/default.ini","settings/settings.ini") #settings.update("settings/default.ini","settings/settings.ini")
MAIN_PORT = settings.get_settings("WEB_PORT") MAIN_PORT = malojaconfig["WEB_PORT"]
HOST = settings.get_settings("HOST") HOST = malojaconfig["HOST"]
THREADS = 24 THREADS = 24
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024 BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
@ -90,7 +90,7 @@ css = generate_css()
def clean_html(inp): def clean_html(inp):
return inp return inp
#if settings.get_settings("DEV_MODE"): return inp #if malojaconfig["DEV_MODE"]: return inp
#else: return html_minify(inp) #else: return html_minify(inp)
@ -218,7 +218,7 @@ def static_image(pth):
def get_css(): def get_css():
response.content_type = 'text/css' response.content_type = 'text/css'
global css global css
if settings.get_settings("DEV_MODE"): css = generate_css() if malojaconfig["DEV_MODE"]: css = generate_css()
return css return css
@ -263,7 +263,7 @@ def static_html(name):
except (ValueError, IndexError) as e: except (ValueError, IndexError) as e:
abort(404,"This Artist or Track does not exist") abort(404,"This Artist or Track does not exist")
if settings.get_settings("DEV_MODE"): jinja_environment.cache.clear() if malojaconfig["DEV_MODE"]: jinja_environment.cache.clear()
log("Generated page {name} in {time:.5f}s".format(name=name,time=clock.stop()),module="debug_performance") log("Generated page {name} in {time:.5f}s".format(name=name,time=clock.stop()),module="debug_performance")
return clean_html(res) return clean_html(res)

View File

@ -10,9 +10,9 @@ import xml.etree.ElementTree as ElementTree
import json import json
import urllib.parse, urllib.request import urllib.parse, urllib.request
import base64 import base64
from doreah.settings import get_settings
from doreah.logging import log from doreah.logging import log
from ..globalconf import malojaconfig
services = { services = {
@ -69,7 +69,7 @@ class GenericInterface:
# populate from settings file once on creation # populate from settings file once on creation
# avoid constant disk access, restart on adding services is acceptable # avoid constant disk access, restart on adding services is acceptable
for key in self.settings: for key in self.settings:
self.settings[key] = get_settings(self.settings[key]) self.settings[key] = malojaconfig[self.settings[key]]
self.authorize() self.authorize()
# this makes sure that of every class we define, we immediately create an # this makes sure that of every class we define, we immediately create an
@ -105,7 +105,7 @@ class ProxyScrobbleInterface(GenericInterface,abstract=True):
def active_proxyscrobble(self): def active_proxyscrobble(self):
return ( return (
all(self.settings[key] not in [None,"ASK",False] for key in self.proxyscrobble["required_settings"]) and all(self.settings[key] not in [None,"ASK",False] for key in self.proxyscrobble["required_settings"]) and
get_settings(self.proxyscrobble["activated_setting"]) malojaconfig[self.proxyscrobble["activated_setting"]]
) )
def scrobble(self,artists,title,timestamp): def scrobble(self,artists,title,timestamp):
@ -130,7 +130,7 @@ class ImportInterface(GenericInterface,abstract=True):
def active_import(self): def active_import(self):
return ( return (
all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"]) and all(self.settings[key] not in [None,"ASK",False] for key in self.scrobbleimport["required_settings"]) and
get_settings(self.scrobbleimport["activated_setting"]) malojaconfig[self.scrobbleimport["activated_setting"]]
) )
@ -147,7 +147,7 @@ class MetadataInterface(GenericInterface,abstract=True):
def active_metadata(self): def active_metadata(self):
return ( return (
all(self.settings[key] not in [None,"ASK",False] for key in self.metadata["required_settings"]) and all(self.settings[key] not in [None,"ASK",False] for key in self.metadata["required_settings"]) and
self.identifier in get_settings("METADATA_PROVIDERS") self.identifier in malojaconfig["METADATA_PROVIDERS"]
) )
def get_image_track(self,track): def get_image_track(self,track):
@ -228,5 +228,5 @@ from . import *
services["metadata"].sort( services["metadata"].sort(
key=lambda provider : get_settings("METADATA_PROVIDERS").index(provider.identifier) key=lambda provider : malojaconfig["METADATA_PROVIDERS"].index(provider.identifier)
) )

View File

@ -34,8 +34,8 @@ else:
### Caches ### Caches
cacheage = settings.get_settings("CACHE_EXPIRE_POSITIVE") * 24 * 3600 cacheage = malojaconfig["CACHE_EXPIRE_POSITIVE"] * 24 * 3600
cacheage_neg = settings.get_settings("CACHE_EXPIRE_NEGATIVE") * 24 * 3600 cacheage_neg = malojaconfig["CACHE_EXPIRE_NEGATIVE"] * 24 * 3600
artist_cache = caching.Cache(name="imgcache_artists",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True) artist_cache = caching.Cache(name="imgcache_artists",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True)
track_cache = caching.Cache(name="imgcache_tracks",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True) track_cache = caching.Cache(name="imgcache_tracks",maxage=cacheage,maxage_negative=cacheage_neg,persistent=True)
@ -133,7 +133,7 @@ def local_files(artist=None,artists=None,title=None):
# these caches are there so we don't check all files every time, but return the same one # these caches are there so we don't check all files every time, but return the same one
local_cache_age = settings.get_settings("LOCAL_IMAGE_ROTATE") local_cache_age = malojaconfig["LOCAL_IMAGE_ROTATE"]
local_artist_cache = caching.Cache(maxage=local_cache_age) local_artist_cache = caching.Cache(maxage=local_cache_age)
local_track_cache = caching.Cache(maxage=local_cache_age) local_track_cache = caching.Cache(maxage=local_cache_age)
@ -142,7 +142,7 @@ def getTrackImage(artists,title,fast=False):
hashable_track = (frozenset(artists),title) hashable_track = (frozenset(artists),title)
# Prio 1: Local image # Prio 1: Local image
if settings.get_settings("USE_LOCAL_IMAGES"): if malojaconfig["USE_LOCAL_IMAGES"]:
try: try:
return thumborize(local_track_cache.get(hashable_track)) return thumborize(local_track_cache.get(hashable_track))
except: except:
@ -189,7 +189,7 @@ def getTrackImage(artists,title,fast=False):
def getArtistImage(artist,fast=False): def getArtistImage(artist,fast=False):
# Prio 1: Local image # Prio 1: Local image
if settings.get_settings("USE_LOCAL_IMAGES"): if malojaconfig["USE_LOCAL_IMAGES"]:
try: try:
return thumborize(local_artist_cache.get(artist)) return thumborize(local_artist_cache.get(artist))
except: except:

View File

@ -87,7 +87,7 @@ def update_weekly():
@daily @daily
def send_stats(): def send_stats():
if settings.get_settings("SEND_STATS"): if malojaconfig["SEND_STATS"]:
log("Sending daily stats report...") log("Sending daily stats report...")
@ -98,8 +98,8 @@ def send_stats():
"method":"POST", "method":"POST",
"headers":{"Content-Type": "application/json"}, "headers":{"Content-Type": "application/json"},
"data":json.dumps({ "data":json.dumps({
"name":settings.get_settings("NAME"), "name":malojaconfig["NAME"],
"url":settings.get_settings("PUBLIC_URL"), "url":malojaconfig["PUBLIC_URL"],
"version":".".join(str(d) for d in version), "version":".".join(str(d) for d in version),
"artists":len(ARTISTS), "artists":len(ARTISTS),
"tracks":len(TRACKS), "tracks":len(TRACKS),