Browse Source

make cache mechanism work with templates

remotes/origin/HEAD
Romain Goffe 12 years ago
parent
commit
e8fe09f290
  1. 4
      makefile
  2. 27
      songbook.py
  3. 2
      templates/ancient.tmpl
  4. 2
      templates/minimal.tmpl
  5. 2
      templates/patacrep.tmpl

4
makefile

@ -82,10 +82,10 @@ $(PDF): %.pdf: %.tex %.aux
$(MAKE_INDEX) --library=$(LIBRARY) $< > $@
%.tex: $(BOOKS_DIR)/%.sb
$(MAKE_SONGBOOK) --cache --library=$(LIBRARY) -s $< -o $@
$(MAKE_SONGBOOK) --library=$(LIBRARY) -s $< -o $@
%.d: $(BOOKS_DIR)/%.sb
$(MAKE_SONGBOOK) --cache --library=$(LIBRARY) -s $< -d -o $@
$(MAKE_SONGBOOK) --library=$(LIBRARY) -s $< -d -o $@
%.pdf: %.ly
@$(LILYPOND) --format=pdf -e '(define-public songbookstaff "$(SONGBOOKSTAFF)")' --output=$(@:%.pdf=%) $<

27
songbook.py

@ -25,16 +25,9 @@ class Song:
return repr((self.title, self.artist, self.album, self.path))
from xdg.BaseDirectory import *
cachePath = os.path.join(xdg_cache_home, 'songbook')
print 'xdg_data_home: %s' % xdg_data_home
print 'xdg_data_dirs: %s' % xdg_data_dirs
print 'xdg_config_home: %s' % xdg_config_home
print 'xdg_config_dirs: %s' % xdg_config_dirs
print 'xdg_cache_home: %s' % xdg_cache_home
songbook_cache_home = os.path.join(xdg_cache_home, 'songbook')
def makeCoverCache(library, cachePath):
def makeCoverCache(library):
'''
Copy all pictures found in the libraries into a unique cache
folder.
@ -157,13 +150,16 @@ def makeTexFile(sb, library, output):
out.write(formatDefinition('songslist', songslist(library, songs)))
out.write('\\makeatother\n')
# output grapihcs path
#out.write('\\graphicspath{ {img/}, {' + songbook_cache_home + '/images/} }\n')
# output template
commentPattern = re.compile(r"^\s*%")
f = open("templates/"+template)
content = [ line for line in f if not commentPattern.match(line) ]
for index, line in enumerate(content):
if re.compile("getcachedirectory").search(line):
line = line.replace("\\getcachedirectory", cachePath + "/")
content[index] = line
f.close()
out.write(''.join(content))
@ -215,7 +211,7 @@ def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
"hs:o:d:l",
["help","songbook=","output=","depend","cache","library="])
["help","songbook=","output=","depend","library="])
except getopt.GetoptError, err:
# print help and exit
print str(err)
@ -225,15 +221,12 @@ def main():
songbook = None
depend = False
output = None
cache = False
library = './'
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("--cache"):
cache = True
elif o in ("-s", "--songbook"):
songbook = a
elif o in ("-d", "--depend"):
@ -245,7 +238,7 @@ def main():
else:
assert False, "unhandled option"
makeCoverCache(library, os.path.join(songbook_cache_home, 'images'))
makeCoverCache(library)
if songbook and output:
f = open(songbook)
sb = json.load(f)

2
templates/ancient.tmpl

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

2
templates/minimal.tmpl

@ -41,7 +41,7 @@
\usepackage[italian,portuguese,spanish,english,french]{babel}
\lang{\getlang}
\graphicspath{ {covers/}, {img/} }
\graphicspath{ {img/}, {\getcachedirectory} }
\nosongnumbers
\pagestyle{empty}

2
templates/patacrep.tmpl

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

Loading…
Cancel
Save