Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gerion Entrup
brainzfs
Commits
9f986588
Commit
9f986588
authored
Nov 15, 2016
by
Gerion Entrup
Browse files
settings: add get_options and cleaner self reference
parent
d09adf36
Changes
2
Hide whitespace changes
Inline
Side-by-side
brainzfs.py
View file @
9f986588
...
...
@@ -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
)
else
:
parser
.
add_argument
(
'--'
+
opt
,
action
=
"store_true"
,
help
=
h
)
...
...
@@ -85,7 +79,7 @@ def main(args):
print
(
arg
.
scan_interval
)
# 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
)
...
...
settings/__init__.py
View file @
9f986588
import
s
etting
s
import
s
y
s
self
=
sys
.
modules
[
__name__
]
_docs
=
{}
def
mk_opt
(
name
,
value
,
doc
,
after_default
=
''
):
global
_docs
setattr
(
se
ttings
,
name
,
value
)
setattr
(
se
lf
,
name
,
value
)
# TODO split after 79 chars
doc
+=
'
\n\n
The 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment