From eb0e68327173371fd967f8e2fc16181230a63fa4 Mon Sep 17 00:00:00 2001 From: Romain Goffe Date: Fri, 6 Apr 2012 19:15:56 +0200 Subject: [PATCH] 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. --- songbook.py | 23 ++++++++++++++++++++++- templates/ancient.tmpl | 4 +--- templates/minimal.tmpl | 2 +- templates/patacrep-en.tmpl | 4 +--- templates/patacrep.tmpl | 4 +--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/songbook.py b/songbook.py index 1c874c5e..0b074937 100755 --- a/songbook.py +++ b/songbook.py @@ -9,13 +9,32 @@ import re import json import locale 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): return [ m.group(1) for m in (reg.match(l) for l in iterable) if m ] def songslist(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) def parseTemplate(template): @@ -187,6 +206,8 @@ def main(): sb = json.load(f) f.close() + copyCovers() + if depend: makeDepend(sb, output) else: diff --git a/templates/ancient.tmpl b/templates/ancient.tmpl index b932b352..28b6b979 100644 --- a/templates/ancient.tmpl +++ b/templates/ancient.tmpl @@ -67,9 +67,7 @@ \newindex{titleidx}{\getname_title} \newauthorindex{authidx}{\getname_auth} -\graphicspath{ - {img/}, -} +\graphicspath{ {covers/}, {img/} } \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor} diff --git a/templates/minimal.tmpl b/templates/minimal.tmpl index 5829b75d..8da8944e 100644 --- a/templates/minimal.tmpl +++ b/templates/minimal.tmpl @@ -44,7 +44,7 @@ \newindex{titleidx}{\getname_title} \newauthorindex{authidx}{\getname_auth} -\graphicspath{ {img/} } +\graphicspath{ {covers/}, {img/} } %hide song number \renewcommand{\printsongnum}[1]{} diff --git a/templates/patacrep-en.tmpl b/templates/patacrep-en.tmpl index 2ffcdb21..56df8fba 100644 --- a/templates/patacrep-en.tmpl +++ b/templates/patacrep-en.tmpl @@ -67,9 +67,7 @@ \newindex{titleidx}{\getname_title} \newauthorindex{authidx}{\getname_auth} -\graphicspath{ - {img/}, -} +\graphicspath{ {covers/}, {img/} } \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor} diff --git a/templates/patacrep.tmpl b/templates/patacrep.tmpl index 357a7bd0..7b820505 100644 --- a/templates/patacrep.tmpl +++ b/templates/patacrep.tmpl @@ -67,9 +67,7 @@ \newindex{titleidx}{\getname_title} \newauthorindex{authidx}{\getname_auth} -\graphicspath{ - {img/}, -} +\graphicspath{ {covers/}, {img/} } \definecolor{SongNumberBgColor}{HTML}{\getsongnumberbgcolor} \definecolor{NoteBgColor}{HTML}{\getnotebgcolor}