Browse Source

Add a make cover cache function to the songbook util

original/refs/heads/split-songs
Alexandre Dupas 12 years ago
parent
commit
640b465057
  1. 46
      songbook.py

46
songbook.py

@ -24,23 +24,30 @@ class Song:
def __repr__(self): def __repr__(self):
return repr((self.title, self.artist, self.album, self.path)) return repr((self.title, self.artist, self.album, self.path))
def copyCovers(): from xdg.BaseDirectory import *
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(cachePath):
''' '''
Copy all covers found in songs/ hierarchy into a same folder. This Copy all pictures found in the libraries into a unique cache
allows a much faster search for pdflatex since the \graphicspath folder.
macro now only contains a single directory instead of quite a long
list to search through.
''' '''
#create "covers/" directory if it does not exist # create the cache directory if it does not exist
d = os.path.dirname("covers/") if not os.path.exists(cachePath):
if not os.path.exists(d): os.makedirs(cachePath)
os.makedirs(d)
covers = list(set(glob.glob('songs/*/*.jpg'))) # copy pictures file into the cache directory
covers = glob.glob('songs/*/*.jpg')
for cover in covers: for cover in covers:
f = "covers/" + os.path.basename(cover) coverPath = os.path.join(cachePath, os.path.basename(cover))
if(os.path.exists(f) == False): shutil.copy(cover, coverPath)
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 ]
@ -161,12 +168,10 @@ def makeTexFile(sb, output):
def makeDepend(sb, output): def makeDepend(sb, output):
name = output[:-2] name = output[:-2]
#dependsPattern = re.compile(r"^[^%]*(?:include|input)\{(.*?)\}")
indexPattern = re.compile(r"^[^%]*\\(?:newauthor|new)index\{.*\}\{(.*?)\}") indexPattern = re.compile(r"^[^%]*\\(?:newauthor|new)index\{.*\}\{(.*?)\}")
lilypondPattern = re.compile(r"^[^%]*\\(?:lilypond)\{(.*?)\}") lilypondPattern = re.compile(r"^[^%]*\\(?:lilypond)\{(.*?)\}")
# check for deps (in sb data) # check for deps (in sb data)
#deps = matchRegexp(dependsPattern, [ v for v in sb.itervalues() if type(v) is not list ])
deps = []; deps = [];
if sb["songs"] == "all": if sb["songs"] == "all":
deps += glob.glob('songs/*/*.sg') deps += glob.glob('songs/*/*.sg')
@ -206,7 +211,7 @@ def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], opts, args = getopt.getopt(sys.argv[1:],
"hs:o:d", "hs:o:d",
["help","songbook=","output=","depend"]) ["help","songbook=","output=","depend","cache"])
except getopt.GetoptError, err: except getopt.GetoptError, err:
# print help and exit # print help and exit
print str(err) print str(err)
@ -216,11 +221,14 @@ def main():
songbook = None songbook = None
depend = False depend = False
output = None output = None
cache = False
for o, a in opts: for o, a in opts:
if o in ("-h", "--help"): if o in ("-h", "--help"):
usage() usage()
sys.exit() sys.exit()
elif o in ("--cache"):
cache = True
elif o in ("-s", "--songbook"): elif o in ("-s", "--songbook"):
songbook = a songbook = a
elif o in ("-d", "--depend"): elif o in ("-d", "--depend"):
@ -230,13 +238,13 @@ def main():
else: else:
assert False, "unhandled option" assert False, "unhandled option"
if songbook and output: if cache:
makeCoverCache(os.path.join(songbook_cache_home, 'images'))
elif songbook and output:
f = open(songbook) f = open(songbook)
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:

Loading…
Cancel
Save