mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Updated doreah toolkit
This commit is contained in:
parent
e78373fb16
commit
6f9ea32d08
2
.doreah
Normal file
2
.doreah
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
logging.logfolder = logs
|
||||||
|
settings.files = [ "settings/default.ini" , "settings/settings.ini" ]
|
20
database.py
20
database.py
@ -1,18 +1,26 @@
|
|||||||
|
# server
|
||||||
from bottle import Bottle, route, get, post, run, template, static_file, request, response, FormsDict
|
from bottle import Bottle, route, get, post, run, template, static_file, request, response, FormsDict
|
||||||
from importlib.machinery import SourceFileLoader
|
|
||||||
import urllib
|
|
||||||
import waitress
|
import waitress
|
||||||
import os
|
# rest of the project
|
||||||
import datetime
|
|
||||||
from cleanup import *
|
from cleanup import *
|
||||||
from utilities import *
|
from utilities import *
|
||||||
|
from malojatime import *
|
||||||
|
from htmlgenerators import KeySplit
|
||||||
|
# doreah toolkit
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
from doreah import tsv
|
from doreah import tsv
|
||||||
from malojatime import *
|
# technical
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import json
|
import json
|
||||||
from htmlgenerators import KeySplit
|
# url handling
|
||||||
|
from importlib.machinery import SourceFileLoader
|
||||||
|
import urllib
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dbserver = Bottle()
|
dbserver = Bottle()
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
## decorator to set default arguments that are only evaluated at runtime
|
## decorator to set default arguments that are only evaluated at runtime
|
||||||
def defaultarguments(defaultdict,**defaultargs):
|
def defaultarguments(defaultdict,**defaultargs):
|
||||||
def decorator(func): #actual decorator function
|
def decorator(func): #actual decorator function
|
||||||
@ -27,3 +28,11 @@ def gopen(filepath,mode):
|
|||||||
os.makedirs(directory, exist_ok=True)
|
os.makedirs(directory, exist_ok=True)
|
||||||
|
|
||||||
return open(filepath,mode)
|
return open(filepath,mode)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# reads module configuration from file
|
||||||
|
def doreahconfig(module):
|
||||||
|
from .settings import get_settings
|
||||||
|
s = get_settings(files=[".doreah"],prefix=module + ".",cut_prefix=True)
|
||||||
|
return s
|
||||||
|
@ -2,7 +2,7 @@ import datetime
|
|||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ._internal import defaultarguments, gopen
|
from ._internal import defaultarguments, gopen, doreahconfig
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ config()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Log entry
|
# Log entry
|
||||||
# module allows discrimination between modules of a program. Will be prepended in console output and will determine the separate file for disk storage
|
# module allows discrimination between modules of a program. Will be prepended in console output and will determine the separate file for disk storage
|
||||||
# defaults to actual name of the calling module or "main" for the main script
|
# defaults to actual name of the calling module or "main" for the main script
|
||||||
@ -100,3 +101,9 @@ def logh1(*args,**kwargs):
|
|||||||
return log(*args,**kwargs,header=1)
|
return log(*args,**kwargs,header=1)
|
||||||
def logh2(*args,**kwargs):
|
def logh2(*args,**kwargs):
|
||||||
return log(*args,**kwargs,header=2)
|
return log(*args,**kwargs,header=2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# now check local configuration file
|
||||||
|
_config.update(doreahconfig("logging"))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import pickle
|
import pickle
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ._internal import defaultarguments, gopen
|
from ._internal import defaultarguments, gopen, doreahconfig
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ def config(folder="storage"):
|
|||||||
# initial config on import, set everything to default
|
# initial config on import, set everything to default
|
||||||
config()
|
config()
|
||||||
|
|
||||||
|
|
||||||
@defaultarguments(_config,folder="folder")
|
@defaultarguments(_config,folder="folder")
|
||||||
def save(data,name,folder):
|
def save(data,name,folder):
|
||||||
|
|
||||||
@ -38,3 +39,8 @@ def load(name,folder):
|
|||||||
fl.close()
|
fl.close()
|
||||||
|
|
||||||
return ob
|
return ob
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# now check local configuration file
|
||||||
|
_config.update(doreahconfig("persistence"))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from ._internal import defaultarguments
|
from ._internal import defaultarguments, doreahconfig
|
||||||
|
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
@ -28,12 +28,43 @@ config()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _interpret(text):
|
def _interpret(text):
|
||||||
if _config["onlytext"]: return text
|
if _config["onlytext"]: return text
|
||||||
|
|
||||||
if text.lower() in ["true","yes"]: return True
|
if text.lower() in ["true","yes"]: return True
|
||||||
if text.lower() in ["false","no"]: return False
|
if text.lower() in ["false","no"]: return False
|
||||||
if text.lower() in ["none","nan","n/a",""]: return None
|
if text.lower() in ["none","nan","n/a",""]: return None
|
||||||
|
if text.startswith("[") and text.endswith("]"):
|
||||||
|
list = []
|
||||||
|
buffer = ""
|
||||||
|
string = None
|
||||||
|
stringended = False
|
||||||
|
for c in text[1:-1]:
|
||||||
|
if stringended and c != ",": pass #after a string is done, skip to the next delimiter
|
||||||
|
elif c == '"' and string is None:
|
||||||
|
string = '"' # start new string
|
||||||
|
buffer = '"'
|
||||||
|
elif c == "'" and string is None:
|
||||||
|
string = "'" # start new string
|
||||||
|
buffer = "'"
|
||||||
|
elif c == '"' and string is '"':
|
||||||
|
string = None # terminate string
|
||||||
|
stringended = True
|
||||||
|
buffer += '"'
|
||||||
|
elif c == "'" and string is "'":
|
||||||
|
string = None # terminate string
|
||||||
|
stringended = True
|
||||||
|
buffer += "'"
|
||||||
|
elif c == "," and string is None:
|
||||||
|
list.append(buffer)
|
||||||
|
buffer = ""
|
||||||
|
stringended = False
|
||||||
|
else: buffer += c
|
||||||
|
|
||||||
|
list.append(buffer.strip())
|
||||||
|
return [_interpret(entry) for entry in list]
|
||||||
|
|
||||||
if text.startswith("'") and text.endswith("'"): return text[1:-1]
|
if text.startswith("'") and text.endswith("'"): return text[1:-1]
|
||||||
if text.startswith('"') and text.endswith('"'): return text[1:-1]
|
if text.startswith('"') and text.endswith('"'): return text[1:-1]
|
||||||
try:
|
try:
|
||||||
@ -184,3 +215,11 @@ def update(source="default_settings.ini",target="settings.ini"):
|
|||||||
usersettings = get_settings(files=[target],raw=True)
|
usersettings = get_settings(files=[target],raw=True)
|
||||||
shutil.copyfile(source,target)
|
shutil.copyfile(source,target)
|
||||||
update_settings(target,usersettings)
|
update_settings(target,usersettings)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# now check local configuration file
|
||||||
|
_config.update(doreahconfig("settings"))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from ._internal import defaultarguments
|
from ._internal import defaultarguments, doreahconfig
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
@ -42,3 +42,11 @@ def clock(*identifiers,lastcalls={None:None}):
|
|||||||
def clockp(name,*identifiers):
|
def clockp(name,*identifiers):
|
||||||
time = clock(*identifiers)
|
time = clock(*identifiers)
|
||||||
print(name + ": " + str(time))
|
print(name + ": " + str(time))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# now check local configuration file
|
||||||
|
_config.update(doreahconfig("timing"))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from ._internal import defaultarguments
|
from ._internal import defaultarguments, doreahconfig
|
||||||
|
|
||||||
_config = {}
|
_config = {}
|
||||||
|
|
||||||
@ -113,3 +113,8 @@ def add_entries(filename,al,comments):
|
|||||||
line = "\t".join([str(e).replace("\t"," ") for e in a])
|
line = "\t".join([str(e).replace("\t"," ") for e in a])
|
||||||
if comments: line = line.replace("#",r"\num")
|
if comments: line = line.replace("#",r"\num")
|
||||||
f.write(line + "\n")
|
f.write(line + "\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# now check local configuration file
|
||||||
|
_config.update(doreahconfig("tsv"))
|
||||||
|
@ -25,7 +25,7 @@ from urllib.error import *
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
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, DATABASE_PORT = settings.get_settings("WEB_PORT","API_PORT")
|
MAIN_PORT, DATABASE_PORT = settings.get_settings("WEB_PORT","API_PORT")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user