Browse Source

Introduction de variables de configuration privées

Les variables dont le nom commence par `_` sont privées : elles ne
peuvent pas être assignées dans le fichier songbook ou dans un template,
et sont destinées à un usage interne.
pull/47/head
Louis 11 years ago
parent
commit
13322630ab
  1. 2
      songbook_core/build.py
  2. 6
      songbook_core/content/cwd.py
  3. 8
      songbook_core/content/song.py
  4. 2
      songbook_core/data/templates/songs.tex

2
songbook_core/build.py

@ -75,7 +75,7 @@ class Songbook(object):
abs_datadir.append(__DATADIR__) abs_datadir.append(__DATADIR__)
self.config['datadir'] = abs_datadir self.config['datadir'] = abs_datadir
self.config['songdir'] = [os.path.join(path, 'songs') for path in self.config['datadir']] self.config['_songdir'] = [os.path.join(path, 'songs') for path in self.config['datadir']]
def build_config(self, from_templates): def build_config(self, from_templates):
config = DEFAULT_CONFIG config = DEFAULT_CONFIG

6
songbook_core/content/cwd.py

@ -6,10 +6,10 @@ import os
from songbook_core.content import process_content from songbook_core.content import process_content
def parse(keyword, config, argument, contentlist): def parse(keyword, config, argument, contentlist):
config['songdir'] = ( config['_songdir'] = (
[os.path.relpath(argument)] + [os.path.relpath(argument)] +
[os.path.join(path, argument) for path in config['songdir']] + [os.path.join(path, argument) for path in config['_songdir']] +
config['songdir'] config['_songdir']
) )
return process_content(contentlist, config) return process_content(contentlist, config)

8
songbook_core/content/song.py

@ -35,9 +35,9 @@ class SongRenderer(Content, Song):
def parse(keyword, argument, contentlist, config): def parse(keyword, argument, contentlist, config):
if 'languages' not in config: if 'languages' not in config:
config['languages'] = set() config['_languages'] = set()
songlist = [] songlist = []
for songdir in config['songdir']: for songdir in config['_songdir']:
if contentlist: if contentlist:
break break
contentlist = [ contentlist = [
@ -47,12 +47,12 @@ def parse(keyword, argument, contentlist, config):
] ]
for elem in contentlist: for elem in contentlist:
before = len(songlist) before = len(songlist)
for songdir in config['songdir']: for songdir in config['_songdir']:
for filename in glob.iglob(os.path.join(songdir, elem)): for filename in glob.iglob(os.path.join(songdir, elem)):
LOGGER.debug('Parsing file "{}"'.format(filename)) LOGGER.debug('Parsing file "{}"'.format(filename))
song = SongRenderer(filename, config) song = SongRenderer(filename, config)
songlist.append(song) songlist.append(song)
config["languages"].update(song.languages) config["_languages"].update(song.languages)
if len(songlist) > before: if len(songlist) > before:
break break
if len(songlist) == before: if len(songlist) == before:

2
songbook_core/data/templates/songs.tex

@ -70,7 +70,7 @@
(* block songbookpreambule *) (* block songbookpreambule *)
(( super() )) (( super() ))
(* for lang in languages *) (* for lang in _languages *)
\PassOptionsToPackage{((lang))}{babel} \PassOptionsToPackage{((lang))}{babel}
(* endfor *) (* endfor *)
\usepackage[((lang))]{babel} \usepackage[((lang))]{babel}

Loading…
Cancel
Save