diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index dec7da5..c16cf30 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -1,4 +1,5 @@ import sqlalchemy as sql +from sqlalchemy.dialects.sqlite import insert as sqliteinsert import json import unicodedata import math @@ -20,6 +21,13 @@ from doreah.regular import runhourly, runmonthly DBTABLES = { # name - type - foreign key - kwargs + '_maloja':{ + 'columns':[ + ("key", sql.String, {'primary_key':True}), + ("value", sql.String, {}) + ], + 'extraargs':(),'extrakwargs':{} + }, 'scrobbles':{ 'columns':[ ("timestamp", sql.Integer, {'primary_key':True}), @@ -151,6 +159,29 @@ def connection_provider(func): wrapper.__innerfunc__ = func return wrapper +@connection_provider +def get_maloja_info(keys,dbconn=None): + op = DB['_maloja'].select().where( + DB['_maloja'].c.key.in_(keys) + ) + result = dbconn.execute(op).all() + + info = {} + for row in result: + info[row.key] = row.value + return info + +@connection_provider +def set_maloja_info(info,dbconn=None): + for k in info: + op = sqliteinsert(DB['_maloja']).values( + key=k, value=info[k] + ).on_conflict_do_update( + index_elements=['key'], + set_={'value':info[k]} + ) + dbconn.execute(op) + ##### DB <-> Dict translations ## ATTENTION ALL ADVENTURERS diff --git a/maloja/pkg_global/conf.py b/maloja/pkg_global/conf.py index 5d9b885..3f49c0f 100644 --- a/maloja/pkg_global/conf.py +++ b/maloja/pkg_global/conf.py @@ -302,15 +302,6 @@ data_dir = { -### write down the last ran version -with open(pthj(dir_settings['state'],".lastmalojaversion"),"w") as filed: - filed.write(VERSION) - filed.write("\n") - - - - - ### DOREAH CONFIGURATION from doreah import config @@ -336,7 +327,8 @@ config( custom_css_files = [f for f in os.listdir(data_dir['css']()) if f.lower().endswith('.css')] - +from ..database.sqldb import set_maloja_info +set_maloja_info({'last_run_version':VERSION}) # what the fuck did i just write # this spaghetti file is proudly sponsored by the rice crackers i'm eating at the