Commit 9f986588 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

settings: add get_options and cleaner self reference

parent d09adf36
......@@ -39,12 +39,6 @@ def _init_database(dbfile):
session = sqlitequeue.get_Session(session)
return session
def get_options():
function = type(lambda x:x)
for x in sorted(vars(settings).keys()):
if (x[0] != '_' and type(getattr(settings, x)) != function):
yield x
def main(args):
"""Main method. Parses cmdline arguments and starts the program."""
version = "0.1-alpha"
......@@ -61,13 +55,13 @@ def main(args):
parser.add_argument('--logfile', '-l', help="log into a logfile")
# options from settings
for opt in get_options():
t = type(getattr(settings, opt))
for opt, value in settings.get_options():
t = type(value)
h = settings.get_doc(opt)
if t == str:
parser.add_argument('--' + opt, help=h)
elif t == bool:
if getattr(settings, opt):
if value:
parser.add_argument('--' + opt, action="store_false", help=h)
parser.add_argument('--' + opt, action="store_true", help=h)
......@@ -85,7 +79,7 @@ def main(args):
# set settings options
for opt in get_options():
for opt, value in settings.get_options():
v = getattr(arg, opt)
if v is not None:
setattr(settings, opt, v)
import settings
import sys
self = sys.modules[__name__]
_docs = {}
def mk_opt(name, value, doc, after_default=''):
global _docs
setattr(settings, name, value)
setattr(self, name, value)
# TODO split after 79 chars
doc += '\n\nThe default value is {}'.format(value)
if after_default:
doc += ' ' + after_default
_docs[name] = doc + '.'
def get_doc(attr):
def get_options():
global _docs
return _docs[attr]
return [(x, getattr(self, x)) for x in sorted(_docs.keys())]
def get_doc(opt):
global _docs
return _docs[opt]
mk_opt('default_mode_dir', 0o555,
'Default permission for directories. This can only be stronger than the default.')
......@@ -55,5 +60,4 @@ mk_opt('slash_replacement', '-',
# this function must not be called again
del mk_opt
del settings
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