Commit 7bea8ed9 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

add settings reading

settings writing is missing though, so the code is not completely tested
parent a36593d2
......@@ -3,6 +3,7 @@
import argparse
import sys
import logging
import os
# workaround for sqlite pseudo concurrency
# remove it once python supports fully concurrency in sqlite
......@@ -20,6 +21,10 @@ from schedu import Schedu
version = "0.1-alpha"
schema_version = 1
# config_file_dir = os.path.join(os.path.expanduser('~'),
# '.config',
# 'brainzfs')
config_file_dir = 'config'
def _init_database(dbfile, migrate=False):
......@@ -32,7 +37,7 @@ def _init_database(dbfile, migrate=False):
database = 'sqlite:///'
engine = create_engine(database + dbfile,
connect_args={'check_same_thread':False},
#echo = True,
# echo = True,
poolclass=StaticPool)
db_version = model.get_version(engine)
if db_version > 0 and db_version < schema_version:
......@@ -48,8 +53,8 @@ def _init_database(dbfile, migrate=False):
session_factory = sessionmaker(bind=engine)
session = scoped_session(session_factory)
if database == 'sqlite:///':
#dirty workaroud for sqlite non concurrent mode in python
#remove it once python supports fully concurrency in sqlite
# dirty workaroud for sqlite non concurrent mode in python
# remove it once python supports fully concurrency in sqlite
session = sqlitequeue.get_Session(session)
model.write_version(session, schema_version)
return session
......@@ -83,8 +88,10 @@ def main(args):
parser.add_argument('--logfile', '-l', help="log into a logfile")
parser.add_argument('--migrate', '-m', action="store_true", default=False, help="migrate to a newer database schema. This cannot be undone.")
# options from settings
# add options from settings
for opt, value in settings.get_options():
if opt == 'identifier':
continue
t = type(value)
h = settings.get_doc(opt)
if t is str:
......@@ -104,8 +111,23 @@ def main(args):
datefmt='%y-%m-%d %H:%M')
logger = logging.getLogger('main')
# load settings from configfile
source_listing = '+'.join(os.listdir(arg.sourcedir)).lower()
if os.path.isdir(config_file_dir):
c_file_cands = [os.path.join(config_file_dir, x)
for x in os.listdir(config_file_dir)]
config_file = settings.parser.identify(c_file_cands,
source_listing)
else:
config_file = None
if config_file is not None:
settings.parse(config_file)
settings.identifier = source_listing
# set settings options
for opt, value in settings.get_options():
if opt == 'identifier':
continue
v = getattr(arg, opt)
if v is not None:
setattr(settings, opt, v)
......@@ -120,12 +142,12 @@ def main(args):
schedu = Schedu(session, arg.sourcedir)
schedu.start()
#from model import Recording
#from mbdata.models import Release, ReleaseGroup, Track, Artist, ArtistCredit, ArtistCreditName, Medium
#from sqlalchemy.sql import select
#se = self.session()
#from utils import debug_breakpoint
#debug_breakpoint()
# from model import Recording
# from mbdata.models import Release, ReleaseGroup, Track, Artist, ArtistCredit, ArtistCreditName, Medium
# from sqlalchemy.sql import select
# se = self.session()
# from utils import debug_breakpoint
# debug_breakpoint()
translator = Translator(session, arg.mountpoint)
translator.start()
......
......@@ -66,6 +66,8 @@ def write(path):
def parse(path):
return settings.parser.parse(path, self)
mk_opt('identifier', '',
'Fuzzy but unique identifier for the source directory. Do not change.')
mk_opt('default_mode_dir', Octal(0o555),
'Default permission for directories. This can only be stronger than the default.',
......
import configparser
import difflib
roots = 'settings'
def convert(settings, opt, value):
......@@ -13,11 +16,25 @@ def parse(path, settings):
config = configparser.ConfigParser()
config.read(path)
root = 'settings'
root = config[root]
root = config[roots]
for opt, value in settings.get_options():
if opt in root:
v = convert(settings, opt, root[opt])
if v is not None and settings.check_constr(opt, v):
setattr(settings, opt, v)
def identify(configfiles, listing):
configfile = (0, None)
for path in configfiles:
config = configparser.ConfigParser()
config.read(path)
root = config[roots]
if 'identify' in root:
ratio = difflib.SequenceMatche(a=root['identify'].lower(),
b=listing).ratio()
if ratio > configfile[0]:
configfile = (ratio, path)
return configfile[1]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment