mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Merge branch 'master' into processcontrolrework
This commit is contained in:
commit
5f29cea6ad
18
Dockerfile
18
Dockerfile
@ -1,12 +1,18 @@
|
|||||||
FROM python:3.6-alpine
|
FROM python:3-alpine
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
RUN apk update
|
RUN apk add --no-cache --virtual .build-deps \
|
||||||
RUN apk add gcc libxml2-dev libxslt-dev py3-pip libc-dev linux-headers
|
gcc \
|
||||||
RUN pip3 install psutil
|
libxml2-dev \
|
||||||
|
libxslt-dev \
|
||||||
RUN pip3 install malojaserver
|
py3-pip \
|
||||||
|
libc-dev \
|
||||||
|
linux-headers \
|
||||||
|
&& \
|
||||||
|
pip3 install psutil && \
|
||||||
|
pip3 install malojaserver && \
|
||||||
|
apk del .build-deps
|
||||||
|
|
||||||
EXPOSE 42010
|
EXPOSE 42010
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ I can support you with issues best if you use **Alpine Linux**. In my experience
|
|||||||
5) (Recommended) Until I have a proper service implemented, I would recommend setting two cronjobs for maloja:
|
5) (Recommended) Until I have a proper service implemented, I would recommend setting two cronjobs for maloja:
|
||||||
|
|
||||||
```
|
```
|
||||||
@reboot maloja start
|
@reboot sleep 15 && maloja start
|
||||||
42 0 * * * maloja restart
|
42 0 * * 2 maloja restart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
apk add python3 python3-dev gcc libxml2-dev libxslt-dev py3-pip libc-dev
|
apk add python3 python3-dev gcc libxml2-dev libxslt-dev py3-pip libc-dev linux-headers
|
||||||
|
pip3 install psutil
|
||||||
pip3 install malojaserver
|
pip3 install malojaserver
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
apt update
|
apt update
|
||||||
apt install python3 python3-pip
|
apt install python3 python3-pip
|
||||||
|
pip3 install psutil
|
||||||
pip3 install malojaserver
|
pip3 install malojaserver
|
||||||
|
@ -5,7 +5,7 @@ author = {
|
|||||||
"email":"maloja@krateng.dev",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,4,9
|
version = 2,4,13
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
links = {
|
links = {
|
||||||
"pypi":"malojaserver",
|
"pypi":"malojaserver",
|
||||||
@ -15,7 +15,7 @@ links = {
|
|||||||
requires = [
|
requires = [
|
||||||
"bottle>=0.12.16",
|
"bottle>=0.12.16",
|
||||||
"waitress>=1.3",
|
"waitress>=1.3",
|
||||||
"doreah>=1.5.6",
|
"doreah>=1.6.3",
|
||||||
"nimrodel>=0.6.3",
|
"nimrodel>=0.6.3",
|
||||||
"setproctitle>=1.1.10",
|
"setproctitle>=1.1.10",
|
||||||
"wand>=0.5.4",
|
"wand>=0.5.4",
|
||||||
|
@ -68,3 +68,4 @@ USE_PYHP = no #not recommended at the moment
|
|||||||
USE_JINJA = no #overwrites pyhp preference
|
USE_JINJA = no #overwrites pyhp preference
|
||||||
FEDERATION = yes #does nothing yet
|
FEDERATION = yes #does nothing yet
|
||||||
SKIP_SETUP = no
|
SKIP_SETUP = no
|
||||||
|
LOGGING = true
|
||||||
|
@ -933,6 +933,7 @@ def build_db():
|
|||||||
log("Building database...")
|
log("Building database...")
|
||||||
|
|
||||||
global SCROBBLES, ARTISTS, TRACKS
|
global SCROBBLES, ARTISTS, TRACKS
|
||||||
|
global TRACKS_NORMALIZED_SET, TRACKS_NORMALIZED, ARTISTS_NORMALIZED_SET, ARTISTS_NORMALIZED
|
||||||
global SCROBBLESDICT, STAMPS
|
global SCROBBLESDICT, STAMPS
|
||||||
|
|
||||||
SCROBBLES = []
|
SCROBBLES = []
|
||||||
@ -941,6 +942,11 @@ def build_db():
|
|||||||
STAMPS = []
|
STAMPS = []
|
||||||
SCROBBLESDICT = {}
|
SCROBBLESDICT = {}
|
||||||
|
|
||||||
|
TRACKS_NORMALIZED = []
|
||||||
|
ARTISTS_NORMALIZED = []
|
||||||
|
ARTISTS_NORMALIZED_SET = set()
|
||||||
|
TRACKS_NORMALIZED_SET = set()
|
||||||
|
|
||||||
|
|
||||||
# parse files
|
# parse files
|
||||||
db = tsv.parse_all(datadir("scrobbles"),"int","string","string",comments=False)
|
db = tsv.parse_all(datadir("scrobbles"),"int","string","string",comments=False)
|
||||||
@ -1067,6 +1073,9 @@ 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")
|
||||||
|
temp_caching = settings.get_settings("CACHE_DATABASE_SHORT")
|
||||||
|
|
||||||
cachestats = {
|
cachestats = {
|
||||||
"cache_query":{
|
"cache_query":{
|
||||||
"hits_perm":0,
|
"hits_perm":0,
|
||||||
@ -1102,11 +1111,11 @@ def db_query_cached(**kwargs):
|
|||||||
eligible_permanent_caching = (
|
eligible_permanent_caching = (
|
||||||
"timerange" in kwargs and
|
"timerange" in kwargs and
|
||||||
not kwargs["timerange"].active() and
|
not kwargs["timerange"].active() and
|
||||||
settings.get_settings("CACHE_DATABASE_PERM")
|
perm_caching
|
||||||
)
|
)
|
||||||
eligible_temporary_caching = (
|
eligible_temporary_caching = (
|
||||||
not eligible_permanent_caching and
|
not eligible_permanent_caching and
|
||||||
settings.get_settings("CACHE_DATABASE_SHORT")
|
temp_caching
|
||||||
)
|
)
|
||||||
|
|
||||||
# hit permanent cache for past timeranges
|
# hit permanent cache for past timeranges
|
||||||
@ -1138,11 +1147,11 @@ def db_aggregate_cached(**kwargs):
|
|||||||
eligible_permanent_caching = (
|
eligible_permanent_caching = (
|
||||||
"timerange" in kwargs and
|
"timerange" in kwargs and
|
||||||
not kwargs["timerange"].active() and
|
not kwargs["timerange"].active() and
|
||||||
settings.get_settings("CACHE_DATABASE_PERM")
|
perm_caching
|
||||||
)
|
)
|
||||||
eligible_temporary_caching = (
|
eligible_temporary_caching = (
|
||||||
not eligible_permanent_caching and
|
not eligible_permanent_caching and
|
||||||
settings.get_settings("CACHE_DATABASE_SHORT")
|
temp_caching
|
||||||
)
|
)
|
||||||
|
|
||||||
# hit permanent cache for past timeranges
|
# hit permanent cache for past timeranges
|
||||||
@ -1173,17 +1182,18 @@ def invalidate_caches():
|
|||||||
log("Database caches invalidated.")
|
log("Database caches invalidated.")
|
||||||
|
|
||||||
def reduce_caches(to=0.75):
|
def reduce_caches(to=0.75):
|
||||||
global cache_query, cache_aggregate
|
global cache_query, cache_aggregate, cache_query_perm, cache_aggregate_perm
|
||||||
for c in cache_query, cache_aggregate:
|
for c in cache_query, cache_aggregate, cache_query_perm, cache_aggregate_perm:
|
||||||
currentsize = len(c)
|
currentsize = len(c)
|
||||||
targetsize = int(currentsize * to)
|
if currentsize > 100:
|
||||||
c.set_size(targetsize)
|
targetsize = max(int(currentsize * to),10)
|
||||||
c.set_size(csz)
|
c.set_size(targetsize)
|
||||||
|
c.set_size(csz)
|
||||||
|
|
||||||
def reduce_caches_if_low_ram():
|
def reduce_caches_if_low_ram():
|
||||||
ramprct = psutil.virtual_memory().percent
|
ramprct = psutil.virtual_memory().percent
|
||||||
if ramprct > cmp:
|
if ramprct > cmp:
|
||||||
log("{prct}% RAM usage, reducing temporary caches!".format(prct=ramprct),module="debug")
|
log("{prct}% RAM usage, reducing caches!".format(prct=ramprct),module="debug")
|
||||||
ratio = (cmp / ramprct) ** 3
|
ratio = (cmp / ramprct) ** 3
|
||||||
reduce_caches(to=ratio)
|
reduce_caches(to=ratio)
|
||||||
|
|
||||||
|
@ -1,23 +1,34 @@
|
|||||||
import os
|
import os
|
||||||
|
from doreah.settings import get_settings
|
||||||
|
from doreah.settings import config as settingsconfig
|
||||||
|
|
||||||
|
|
||||||
# data folder
|
|
||||||
# must be determined first because getting settings relies on it
|
|
||||||
|
|
||||||
try:
|
# check environment variables for data directory
|
||||||
DATA_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
# otherwise, go with defaults
|
||||||
assert os.path.exists(DATA_DIR)
|
setting_datadir = get_settings("DATA_DIRECTORY",files=[],environ_prefix="MALOJA_")
|
||||||
except:
|
if setting_datadir is not None and os.path.exists(setting_datadir):
|
||||||
DATA_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
DATA_DIR = setting_datadir
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
HOME_DIR = os.environ["XDG_DATA_HOME"].split(":")[0]
|
||||||
|
assert os.path.exists(HOME_DIR)
|
||||||
|
except:
|
||||||
|
HOME_DIR = os.path.join(os.environ["HOME"],".local/share/")
|
||||||
|
|
||||||
|
DATA_DIR = os.path.join(HOME_DIR,"maloja")
|
||||||
|
|
||||||
DATA_DIR = os.path.join(DATA_DIR,"maloja")
|
|
||||||
os.makedirs(DATA_DIR,exist_ok=True)
|
os.makedirs(DATA_DIR,exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def datadir(*args):
|
def datadir(*args):
|
||||||
return os.path.join(DATA_DIR,*args)
|
return os.path.join(DATA_DIR,*args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### DOREAH CONFIGURATION
|
### DOREAH CONFIGURATION
|
||||||
|
|
||||||
from doreah import config
|
from doreah import config
|
||||||
@ -26,9 +37,6 @@ config(
|
|||||||
pyhp={
|
pyhp={
|
||||||
"version": 2
|
"version": 2
|
||||||
},
|
},
|
||||||
logging={
|
|
||||||
"logfolder": datadir("logs")
|
|
||||||
},
|
|
||||||
settings={
|
settings={
|
||||||
"files":[
|
"files":[
|
||||||
datadir("settings/default.ini"),
|
datadir("settings/default.ini"),
|
||||||
@ -44,9 +52,18 @@ config(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# because we loaded a doreah module already before setting the config, we need to to that manually
|
||||||
|
settingsconfig._readpreconfig()
|
||||||
|
|
||||||
|
config(
|
||||||
|
logging={
|
||||||
|
"logfolder": datadir("logs") if get_settings("LOGGING") else None
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
settingsconfig._readpreconfig()
|
||||||
|
|
||||||
|
|
||||||
from doreah.settings import get_settings
|
|
||||||
|
|
||||||
# thumbor
|
# thumbor
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user