Browse Source

Change `songs.Song` signature

Datadir is now an optional argument, and can be omitted to ignore cache
pull/126/head
Louis 9 years ago
parent
commit
e753cca8f6
  1. 2
      patacrep/content/song.py
  2. 10
      patacrep/songs/__init__.py
  3. 2
      patacrep/songs/convert/__main__.py
  4. 2
      test/test_chordpro/test_parser.py

2
patacrep/content/song.py

@ -87,9 +87,9 @@ def parse(keyword, argument, contentlist, config):
)) ))
continue continue
renderer = SongRenderer(plugins[extension]( renderer = SongRenderer(plugins[extension](
songdir.datadir,
filename, filename,
config, config,
datadir=songdir.datadir,
)) ))
songlist.append(renderer) songlist.append(renderer)
config["_languages"].update(renderer.song.languages) config["_languages"].update(renderer.song.languages)

10
patacrep/songs/__init__.py

@ -95,9 +95,12 @@ class Song:
"_version", "_version",
] ]
def __init__(self, datadir, subpath, config): def __init__(self, subpath, config, *, datadir=None):
self.fullpath = os.path.join(datadir, subpath) if datadir is None:
self.datadir = datadir self.datadir = ""
else:
self.datadir = datadir
self.fullpath = os.path.join(self.datadir, subpath)
self.encoding = config["encoding"] self.encoding = config["encoding"]
self.config = config self.config = config
@ -131,7 +134,6 @@ class Song:
self._parse(config) self._parse(config)
# Post processing of data # Post processing of data
self.datadir = datadir
self.subpath = subpath self.subpath = subpath
self.unprefixed_titles = [ self.unprefixed_titles = [
unprefixed_title( unprefixed_title(

2
patacrep/songs/convert/__main__.py

@ -51,7 +51,7 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
for file in song_files: for file in song_files:
song = song_parsers[source]("", file, DEFAULT_CONFIG) song = song_parsers[source](file, DEFAULT_CONFIG)
try: try:
destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest) destname = "{}.{}".format(".".join(file.split(".")[:-1]), dest)
if os.path.exists(destname): if os.path.exists(destname):

2
test/test_chordpro/test_parser.py

@ -55,7 +55,7 @@ class FileTestMeta(type):
chordproname = "{}.source".format(base) chordproname = "{}.source".format(base)
with disable_logging(): with disable_logging():
self.assertMultiLineEqual( self.assertMultiLineEqual(
ChordproSong(None, chordproname, DEFAULT_CONFIG).render( ChordproSong(chordproname, DEFAULT_CONFIG).render(
output=chordproname, output=chordproname,
output_format=LANGUAGES[dest], output_format=LANGUAGES[dest],
).strip(), ).strip(),

Loading…
Cancel
Save