Browse Source

Gestion des datadirs plus pythonique ; Commentaires

pull/45/head
Louis 10 years ago
parent
commit
f4b9bfdfee
  1. 28
      songbook

28
songbook

@ -51,7 +51,7 @@ def argument_parser(args):
Book to compile. Book to compile.
""")) """))
parser.add_argument('--datadir', '-d', nargs=1, type=str, action='store', parser.add_argument('--datadir', '-d', nargs='+', type=str, action='append',
help=textwrap.dedent("""\ help=textwrap.dedent("""\
Data location. Expected (not necessarily required) Data location. Expected (not necessarily required)
subdirectories are 'songs', 'img', 'latex', 'templates'. subdirectories are 'songs', 'img', 'latex', 'templates'.
@ -108,24 +108,22 @@ def main():
LOGGER.error("Error while loading file '{}'.".format(songbook_path)) LOGGER.error("Error while loading file '{}'.".format(songbook_path))
sys.exit(1) sys.exit(1)
# Gathering datadirs
datadirs = [] datadirs = []
try: if options.datadir:
# Command line options
datadirs += [item[0] for item in options.datadir]
if 'datadir' in songbook:
# .sg file
if isinstance(songbook['datadir'], basestring): if isinstance(songbook['datadir'], basestring):
songbook['datadir'] = [songbook['datadir']] songbook['datadir'] = [songbook['datadir']]
for path in songbook['datadir']: datadirs += [
if not os.path.isabs(path): os.path.join(os.path.dirname(songbook_path), path)
datadirs.append(os.path.join(os.path.dirname(songbook_path), for path in songbook['datadir']
path ]
) if not datadirs:
) # Default value
else:
datadirs.append(path)
except KeyError:
datadirs = [os.path.dirname(songbook_path)] datadirs = [os.path.dirname(songbook_path)]
if options.datadir is not None:
datadirs = options.datadir + datadirs
songbook['datadir'] = datadirs songbook['datadir'] = datadirs
try: try:

Loading…
Cancel
Save