diff --git a/maloja/globalconf.py b/maloja/globalconf.py index 8e15918..2da2391 100644 --- a/maloja/globalconf.py +++ b/maloja/globalconf.py @@ -113,10 +113,10 @@ for dirtype in dir_settings: except: pass - +from pprint import pprint print("") print("") -print(dir_settings) +pprint(dir_settings) print("") print("") @@ -136,9 +136,15 @@ data_directories = { "cache":pthj(dir_settings['cache']), } +print("") +print("") +pprint(data_directories) +print("") +print("") + data_dir = { - k:lambda *x: pthj(data_directories[k],*x) for k in data_directories + k:lambda *x,k=k: pthj(data_directories[k],*x) for k in data_directories } diff --git a/maloja/proccontrol/setup.py b/maloja/proccontrol/setup.py index 5cf223e..e819c99 100644 --- a/maloja/proccontrol/setup.py +++ b/maloja/proccontrol/setup.py @@ -5,7 +5,7 @@ from doreah.io import col, ask, prompt from doreah import auth import os -from ..globalconf import data_dir +from ..globalconf import data_dir, dir_settings # EXTERNAL API KEYS @@ -20,8 +20,8 @@ apikeys = { def copy_initial_local_files(): folder = pkg_resources.resource_filename("maloja","data_files") - #shutil.copy(folder,DATA_DIR) - dir_util.copy_tree(folder,datadir(),update=False) + for cat in dir_settings: + dir_util.copy_tree(os.path.join(folder,cat),dir_settings[cat],update=False) charset = list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") def randomstring(length=32): @@ -44,12 +44,13 @@ def setup(): elif key == "ASK": print("\t" + "Please enter your " + 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=None,skip=SKIP) - settings.update_settings(datadir("settings/settings.ini"),{k:key},create_new=True) + settings.update_settings(data_dir['settings']("settings.ini"),{k:key},create_new=True) else: print("\t" + apikeys[k] + " found.") # OWN API KEY + print(data_dir['clients']("authenticated_machines.tsv")) if os.path.exists(data_dir['clients']("authenticated_machines.tsv")): pass else: @@ -91,11 +92,11 @@ def setup(): if settings.get_settings("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) - settings.update_settings(datadir("settings/settings.ini"),{"NAME":name},create_new=True) + settings.update_settings(data_dir['settings']("settings.ini"),{"NAME":name},create_new=True) if settings.get_settings("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) if answer: - settings.update_settings(datadir("settings/settings.ini"),{"SEND_STATS":True,"PUBLIC_URL":None},create_new=True) + settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":True,"PUBLIC_URL":None},create_new=True) else: - settings.update_settings(datadir("settings/settings.ini"),{"SEND_STATS":False},create_new=True) + settings.update_settings(data_dir['settings']("settings.ini"),{"SEND_STATS":False},create_new=True) diff --git a/maloja/server.py b/maloja/server.py index 95db671..b046ce9 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import os -from .globalconf import data_dir, DATA_DIR +from .globalconf import data_dir # server stuff @@ -51,7 +51,6 @@ THREADS = 24 BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024 STATICFOLDER = pkg_resources.resource_filename(__name__,"web/static") -DATAFOLDER = DATA_DIR webserver = Bottle() auth.authapi.mount(server=webserver) @@ -150,12 +149,12 @@ def dynamic_image(): @webserver.route("/images/") def static_image(pth): if globalconf.USE_THUMBOR: - return static_file(pthjoin("images",pth),root=DATAFOLDER) + return static_file(pth,root=data_dir['images']()) type = pth.split(".")[-1] small_pth = pth + "-small" if os.path.exists(data_dir['images'](small_pth)): - response = static_file(pthjoin("images",small_pth),root=DATAFOLDER) + response = static_file(small_pth,root=data_dir['images']()) else: try: from wand.image import Image @@ -166,11 +165,11 @@ def static_image(pth): ratio = 300/smaller img.resize(int(ratio*x),int(ratio*y)) img.save(filename=data_dir['images'](small_pth)) - response = static_file(pthjoin("images",small_pth),root=DATAFOLDER) + response = static_file(small_pth,root=data_dir['images']()) else: - response = static_file(pthjoin("images",pth),root=DATAFOLDER) + response = static_file(pth,root=data_dir['images']()) except: - response = static_file(pthjoin("images",pth),root=DATAFOLDER) + response = static_file(pth,root=data_dir['images']()) #response = static_file("images/" + pth,root="") response.set_header("Cache-Control", "public, max-age=86400") diff --git a/maloja/utilities/images.py b/maloja/utilities/images.py index bcf2a94..65f788d 100644 --- a/maloja/utilities/images.py +++ b/maloja/utilities/images.py @@ -58,7 +58,7 @@ def get_all_possible_filenames(artist=None,artists=None,title=None): else: return [] - superfolder = "images/tracks/" if track else "images/artists/" + superfolder = "tracks/" if track else "artists/" filenames = [] @@ -117,14 +117,14 @@ def local_files(artist=None,artists=None,title=None): # direct files for ext in ["png","jpg","jpeg","gif"]: #for num in [""] + [str(n) for n in range(0,10)]: - if os.path.exists(datadir(purename + "." + ext)): - images.append("/" + purename + "." + ext) + if os.path.exists(data_dir['images'](purename + "." + ext)): + images.append("/images/" + purename + "." + ext) # folder try: - for f in os.listdir(datadir(purename)): + for f in os.listdir(data_dir['images'](purename)): if f.split(".")[-1] in ["png","jpg","jpeg","gif"]: - images.append("/" + purename + "/" + f) + images.append("/images/" + purename + "/" + f) except: pass @@ -297,8 +297,8 @@ def set_image(b64,**keys): b64 = base64.b64decode(b64) filename = "webupload" + str(int(datetime.datetime.now().timestamp())) + "." + type for folder in get_all_possible_filenames(**keys): - if os.path.exists(datadir(folder)): - with open(datadir(folder,filename),"wb") as f: + if os.path.exists(data_dir['images'](folder)): + with open(data_dir['images'](folder,filename),"wb") as f: f.write(b64) # set as current picture in rotation @@ -307,8 +307,8 @@ def set_image(b64,**keys): return folder = get_all_possible_filenames(**keys)[0] - os.makedirs(datadir(folder)) - with open(datadir(folder,filename),"wb") as f: + os.makedirs(data_dir['images'](folder)) + with open(data_dir['images'](folder,filename),"wb") as f: f.write(b64) # set as current picture in rotation