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
renderer = SongRenderer(plugins[extension](
songdir.datadir,
filename,
config,
datadir=songdir.datadir,
))
songlist.append(renderer)
config["_languages"].update(renderer.song.languages)

10
patacrep/songs/__init__.py

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

2
patacrep/songs/convert/__main__.py

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

2
test/test_chordpro/test_parser.py

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

Loading…
Cancel
Save