Browse Source

major performance improvement when building a songbook

make songbook.pdf :
 - before patch: 5mn23s
 - after patch: 14s

The issue was about LaTeX \graphicspath macro that was used for
covers.  Since covers are stored in each artist's directory,
\graohicspath was containing a large number of different paths which
resulted in quite some time to evaluate when using \includegraphics.

This small patch copies all covers in a single temporary directory
before building a songbook. Note that symlinks are quite tricky to use
with pdflatex, esp. with MacOs/Windows plateforms so a hard copy has
been preferred.
remotes/karagrat/master
Romain Goffe 13 years ago
parent
commit
eb0e683271
  1. 23
      songbook.py
  2. 4
      templates/ancient.tmpl
  3. 2
      templates/minimal.tmpl
  4. 4
      templates/patacrep-en.tmpl
  5. 4
      templates/patacrep.tmpl

23
songbook.py

@ -9,13 +9,32 @@ import re
import json import json
import locale import locale
import sortindex import sortindex
import shutil
def copyCovers():
'''
Copy all covers found in songs/ hierarchy into a same folder. This
allows a much faster search for pdflatex since the \graphicspath
macro now only contains a single directory instead of quite a long
list to search through.
'''
#create "covers/" directory if it does not exist
d = os.path.dirname("covers/")
if not os.path.exists(d):
os.makedirs(d)
covers = list(set(glob.glob('songs/*/*.jpg')))
for cover in covers:
f = "covers/" + os.path.basename(cover)
if(os.path.exists(f) == False):
shutil.copy(cover, f)
def matchRegexp(reg, iterable): def matchRegexp(reg, iterable):
return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ] return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ]
def songslist(songs): def songslist(songs):
directories = set(["img/"] + map(lambda x: "songs/" + os.path.dirname(x), songs)) directories = set(["img/"] + map(lambda x: "songs/" + os.path.dirname(x), songs))
result = ['\\graphicspath{'] + [ ' {{{0}/}},'.format(d) for d in directories ] + ['}'] + [ '\\input{{songs/{0}}}'.format(s.strip()) for s in songs ] result = [ '\\input{{songs/{0}}}'.format(s.strip()) for s in songs ]
return '\n'.join(result) return '\n'.join(result)
def parseTemplate(template): def parseTemplate(template):
@ -187,6 +206,8 @@ def main():
sb = json.load(f) sb = json.load(f)
f.close() f.close()
copyCovers()
if depend: if depend:
makeDepend(sb, output) makeDepend(sb, output)
else: else:

4
templates/ancient.tmpl

@ -67,9 +67,7 @@
\newindex{titleidx}{\getname_title} \newindex{titleidx}{\getname_title}
\newauthorindex{authidx}{\getname_auth} \newauthorindex{authidx}{\getname_auth}
\graphicspath{ \graphicspath{ {covers/}, {img/} }
{img/},
}
\definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor}
\definecolor{NoteBgColor}{HTML}{\getnotebgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor}

2
templates/minimal.tmpl

@ -44,7 +44,7 @@
\newindex{titleidx}{\getname_title} \newindex{titleidx}{\getname_title}
\newauthorindex{authidx}{\getname_auth} \newauthorindex{authidx}{\getname_auth}
\graphicspath{ {img/} } \graphicspath{ {covers/}, {img/} }
%hide song number %hide song number
\renewcommand{\printsongnum}[1]{} \renewcommand{\printsongnum}[1]{}

4
templates/patacrep-en.tmpl

@ -67,9 +67,7 @@
\newindex{titleidx}{\getname_title} \newindex{titleidx}{\getname_title}
\newauthorindex{authidx}{\getname_auth} \newauthorindex{authidx}{\getname_auth}
\graphicspath{ \graphicspath{ {covers/}, {img/} }
{img/},
}
\definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor}
\definecolor{NoteBgColor}{HTML}{\getnotebgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor}

4
templates/patacrep.tmpl

@ -67,9 +67,7 @@
\newindex{titleidx}{\getname_title} \newindex{titleidx}{\getname_title}
\newauthorindex{authidx}{\getname_auth} \newauthorindex{authidx}{\getname_auth}
\graphicspath{ \graphicspath{ {covers/}, {img/} }
{img/},
}
\definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor}
\definecolor{NoteBgColor}{HTML}{\getnotebgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor}

Loading…
Cancel
Save