Browse Source

Turned authors in a list of authors

pull/70/head
Louis 10 years ago
committed by Luthaf
parent
commit
9c49243db1
  1. 21
      patacrep/authors.py
  2. 13
      patacrep/index.py
  3. 9
      patacrep/songs/latex/__init__.py

21
patacrep/authors.py

@ -164,17 +164,21 @@ def processauthors(authors_string, after=None, ignore=None, sep=None):
For example, we are processing:
# processauthors(
# "Lyrics by William Blake (from Milton, 1808),
music by Hubert Parry (1916),
and sung by The Royal\ Choir~of~Nowhere
(just here to show you how processing is done)",
# [
# "
# Lyrics by William Blake (from Milton, 1808),
# music by Hubert Parry (1916),
# and sung by The Royal\ Choir~of~Nowhere
# (just here to show you how processing is done)
# ",
# ],
# after = ["by"],
# ignore = ["anonymous"],
# sep = [re.compile('^(.*) and (.*)$')],
# )
The "authors_string" string is processed as:
The "authors_string" is processed as:
1) First, parenthesis (and its content) are removed.
# "Lyrics by William Blake, music by Hubert Parry,
@ -220,3 +224,10 @@ def processauthors(authors_string, after=None, ignore=None, sep=None):
ignore)
)
]
def process_listauthors(authors_list):
"""Process a list of authors, and return the list of resulting authors."""
return sum([
processauthors(string)
for string in authors_list
])

13
patacrep/index.py

@ -19,7 +19,6 @@ EOL = "\n"
KEYWORD_PATTERN = re.compile(r"^%(\w+)\s?(.*)$", re.LOCALE)
FIRST_LETTER_PATTERN = re.compile(r"^(?:\{?\\\w+\}?)*[^\w]*(\w)", re.LOCALE)
def process_sxd(filename):
"""Parse sxd file.
@ -162,7 +161,11 @@ class Index(object):
def entry_to_str(self, key, entry):
"""Return the LaTeX code corresponding to the entry."""
return (r'\idxentry{{{0}}}{{{1}}}' + EOL).format(
return r"""\idxentry{{
{0}
}}{{
{1}
}}""".format(
self.key_to_str(key),
r'\\'.join([self.ref_to_str(ref) for ref in entry]),
)
@ -182,13 +185,13 @@ class Index(object):
]
string = r'\begin{idxblock}{' + letter + '}' + EOL
for key in sorted(entries, key=sortkey):
string += self.entry_to_str(key, entries[key]['entries'])
string += r'\end{idxblock}' + EOL
string += " " + self.entry_to_str(key, entries[key]['entries'])
string += EOL + r'\end{idxblock}'
return string
def entries_to_str(self):
"""Return the LaTeX code corresponding to the index."""
string = ""
for letter in sorted(self.data.keys()):
string += self.idxblock_to_str(letter, self.data[letter])
string += self.idxblock_to_str(letter, self.data[letter]) + EOL
return string

9
patacrep/songs/latex/__init__.py

@ -16,7 +16,14 @@ class LatexSong(Song):
def parse(self, content):
"""Parse content, and return the dictinory of song data."""
return parse_song(content, self.fullpath)
with encoding.open_read(self.fullpath, encoding=self.encoding) as song:
self.data = parse_song(song.read(), self.fullpath)
self.titles = self.data['@titles']
del self.data['@titles']
self.languages = self.data['@languages']
del self.data['@languages']
self.authors = [self.data['by']]
del self.data['by']
def tex(self, output):
"""Return the LaTeX code rendering the song."""

Loading…
Cancel
Save