mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Fixed more complicated user file references
This commit is contained in:
parent
0818dccac4
commit
f44c3fecb2
@ -113,10 +113,10 @@ for dirtype in dir_settings:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
print("")
|
print("")
|
||||||
print("")
|
print("")
|
||||||
print(dir_settings)
|
pprint(dir_settings)
|
||||||
print("")
|
print("")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
@ -136,9 +136,15 @@ data_directories = {
|
|||||||
"cache":pthj(dir_settings['cache']),
|
"cache":pthj(dir_settings['cache']),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("")
|
||||||
|
print("")
|
||||||
|
pprint(data_directories)
|
||||||
|
print("")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
|
||||||
data_dir = {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from doreah.io import col, ask, prompt
|
|||||||
from doreah import auth
|
from doreah import auth
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..globalconf import data_dir
|
from ..globalconf import data_dir, dir_settings
|
||||||
|
|
||||||
|
|
||||||
# EXTERNAL API KEYS
|
# EXTERNAL API KEYS
|
||||||
@ -20,8 +20,8 @@ apikeys = {
|
|||||||
|
|
||||||
def copy_initial_local_files():
|
def copy_initial_local_files():
|
||||||
folder = pkg_resources.resource_filename("maloja","data_files")
|
folder = pkg_resources.resource_filename("maloja","data_files")
|
||||||
#shutil.copy(folder,DATA_DIR)
|
for cat in dir_settings:
|
||||||
dir_util.copy_tree(folder,datadir(),update=False)
|
dir_util.copy_tree(os.path.join(folder,cat),dir_settings[cat],update=False)
|
||||||
|
|
||||||
charset = list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
charset = list(range(10)) + list("abcdefghijklmnopqrstuvwxyz") + list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
def randomstring(length=32):
|
def randomstring(length=32):
|
||||||
@ -44,12 +44,13 @@ def setup():
|
|||||||
elif key == "ASK":
|
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.")
|
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)
|
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:
|
else:
|
||||||
print("\t" + apikeys[k] + " found.")
|
print("\t" + apikeys[k] + " found.")
|
||||||
|
|
||||||
|
|
||||||
# OWN API KEY
|
# OWN API KEY
|
||||||
|
print(data_dir['clients']("authenticated_machines.tsv"))
|
||||||
if os.path.exists(data_dir['clients']("authenticated_machines.tsv")):
|
if os.path.exists(data_dir['clients']("authenticated_machines.tsv")):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -91,11 +92,11 @@ def setup():
|
|||||||
|
|
||||||
if settings.get_settings("NAME") is None:
|
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)
|
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:
|
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)
|
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(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:
|
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)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
from .globalconf import data_dir, DATA_DIR
|
from .globalconf import data_dir
|
||||||
|
|
||||||
|
|
||||||
# server stuff
|
# server stuff
|
||||||
@ -51,7 +51,6 @@ THREADS = 24
|
|||||||
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
|
BaseRequest.MEMFILE_MAX = 15 * 1024 * 1024
|
||||||
|
|
||||||
STATICFOLDER = pkg_resources.resource_filename(__name__,"web/static")
|
STATICFOLDER = pkg_resources.resource_filename(__name__,"web/static")
|
||||||
DATAFOLDER = DATA_DIR
|
|
||||||
|
|
||||||
webserver = Bottle()
|
webserver = Bottle()
|
||||||
auth.authapi.mount(server=webserver)
|
auth.authapi.mount(server=webserver)
|
||||||
@ -150,12 +149,12 @@ def dynamic_image():
|
|||||||
@webserver.route("/images/<pth:re:.*\\.gif>")
|
@webserver.route("/images/<pth:re:.*\\.gif>")
|
||||||
def static_image(pth):
|
def static_image(pth):
|
||||||
if globalconf.USE_THUMBOR:
|
if globalconf.USE_THUMBOR:
|
||||||
return static_file(pthjoin("images",pth),root=DATAFOLDER)
|
return static_file(pth,root=data_dir['images']())
|
||||||
|
|
||||||
type = pth.split(".")[-1]
|
type = 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(pthjoin("images",small_pth),root=DATAFOLDER)
|
response = static_file(small_pth,root=data_dir['images']())
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
from wand.image import Image
|
from wand.image import Image
|
||||||
@ -166,11 +165,11 @@ def static_image(pth):
|
|||||||
ratio = 300/smaller
|
ratio = 300/smaller
|
||||||
img.resize(int(ratio*x),int(ratio*y))
|
img.resize(int(ratio*x),int(ratio*y))
|
||||||
img.save(filename=data_dir['images'](small_pth))
|
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:
|
else:
|
||||||
response = static_file(pthjoin("images",pth),root=DATAFOLDER)
|
response = static_file(pth,root=data_dir['images']())
|
||||||
except:
|
except:
|
||||||
response = static_file(pthjoin("images",pth),root=DATAFOLDER)
|
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")
|
||||||
|
@ -58,7 +58,7 @@ def get_all_possible_filenames(artist=None,artists=None,title=None):
|
|||||||
else: return []
|
else: return []
|
||||||
|
|
||||||
|
|
||||||
superfolder = "images/tracks/" if track else "images/artists/"
|
superfolder = "tracks/" if track else "artists/"
|
||||||
|
|
||||||
filenames = []
|
filenames = []
|
||||||
|
|
||||||
@ -117,14 +117,14 @@ def local_files(artist=None,artists=None,title=None):
|
|||||||
# direct files
|
# direct files
|
||||||
for ext in ["png","jpg","jpeg","gif"]:
|
for ext in ["png","jpg","jpeg","gif"]:
|
||||||
#for num in [""] + [str(n) for n in range(0,10)]:
|
#for num in [""] + [str(n) for n in range(0,10)]:
|
||||||
if os.path.exists(datadir(purename + "." + ext)):
|
if os.path.exists(data_dir['images'](purename + "." + ext)):
|
||||||
images.append("/" + purename + "." + ext)
|
images.append("/images/" + purename + "." + ext)
|
||||||
|
|
||||||
# folder
|
# folder
|
||||||
try:
|
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"]:
|
if f.split(".")[-1] in ["png","jpg","jpeg","gif"]:
|
||||||
images.append("/" + purename + "/" + f)
|
images.append("/images/" + purename + "/" + f)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -297,8 +297,8 @@ def set_image(b64,**keys):
|
|||||||
b64 = base64.b64decode(b64)
|
b64 = base64.b64decode(b64)
|
||||||
filename = "webupload" + str(int(datetime.datetime.now().timestamp())) + "." + type
|
filename = "webupload" + str(int(datetime.datetime.now().timestamp())) + "." + type
|
||||||
for folder in get_all_possible_filenames(**keys):
|
for folder in get_all_possible_filenames(**keys):
|
||||||
if os.path.exists(datadir(folder)):
|
if os.path.exists(data_dir['images'](folder)):
|
||||||
with open(datadir(folder,filename),"wb") as f:
|
with open(data_dir['images'](folder,filename),"wb") as f:
|
||||||
f.write(b64)
|
f.write(b64)
|
||||||
|
|
||||||
# set as current picture in rotation
|
# set as current picture in rotation
|
||||||
@ -307,8 +307,8 @@ def set_image(b64,**keys):
|
|||||||
return
|
return
|
||||||
|
|
||||||
folder = get_all_possible_filenames(**keys)[0]
|
folder = get_all_possible_filenames(**keys)[0]
|
||||||
os.makedirs(datadir(folder))
|
os.makedirs(data_dir['images'](folder))
|
||||||
with open(datadir(folder,filename),"wb") as f:
|
with open(data_dir['images'](folder,filename),"wb") as f:
|
||||||
f.write(b64)
|
f.write(b64)
|
||||||
|
|
||||||
# set as current picture in rotation
|
# set as current picture in rotation
|
||||||
|
Loading…
Reference in New Issue
Block a user