diff --git a/python/index.py b/index.py similarity index 100% rename from python/index.py rename to index.py diff --git a/python/template.py b/python/template.py deleted file mode 100644 index 6d3ec838..00000000 --- a/python/template.py +++ /dev/null @@ -1,282 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# - -import getopt, sys -import os.path -import re -import json -import locale -import shutil -import locale -import platform - -from utils.utils import recursiveFind - -reTitle = re.compile('(?<=beginsong\\{)(.(? 0: - out.write(formatDefinition('songslist', songslist(library, songs, prefixes))) - out.write('\\makeatother\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.replace("\\","/") + "/") - content[index] = line - if re.compile("getLibraryImgDirectory").search(line): - line = line.replace("\\getLibraryImgDirectory", library + "img/") - content[index] = line - if re.compile("getLibraryLilypondDirectory").search(line): - line = line.replace("\\getLibraryLilypondDirectory", library + "lilypond/") - content[index] = line - - f.close() - out.write(''.join(content)) - - out.close() - -def makeDepend(sb, library, output): - name = output[:-2] - - indexPattern = re.compile(r"^[^%]*\\(?:newauthor|new)index\{.*\}\{(.*?)\}") - lilypondPattern = re.compile(r"^[^%]*\\(?:lilypond)\{(.*?)\}") - - # check for deps (in sb data) - deps = []; - if sb["songs"] == "all": - deps += recursiveFind(os.path.join(library, 'songs'), '*.sg') - else: - deps += map(lambda x: library + "songs/" + x, sb["songs"]) - - # check for lilypond deps (in songs data) if necessary - lilypond = [] - if "bookoptions" in sb and "lilypond" in sb["bookoptions"]: - for filename in deps: - tmpl = open(filename) - lilypond += matchRegexp(lilypondPattern, tmpl) - tmpl.close() - - # check for index (in template file) - if "template" in sb: - filename = sb["template"] - else: - filename = "patacrep.tmpl" - tmpl = open("templates/"+filename) - idx = map(lambda x: x.replace("\getname", name), matchRegexp(indexPattern, tmpl)) - tmpl.close() - - # write .d file - out = open(output, 'w') - out.write('{0} {1} : {2}\n'.format(output, name+".tex", ' '.join(deps))) - out.write('{0} : {1}\n'.format(name+".pdf", ' '.join(map(lambda x: x+".sbx",idx)+map(lambda x: library+"lilypond/"+x+".pdf", lilypond)))) - out.write('\t$(LATEX) {0}\n'.format(name+".tex")) - out.write('{0} : {1}\n'.format(' '.join(map(lambda x: x+".sxd",idx)), name+".aux")) - out.close() - -def usage(): - print "No usage information yet." - -def main(): - locale.setlocale(locale.LC_ALL, '') # set script locale to match user's - try: - opts, args = getopt.getopt(sys.argv[1:], - "hs:o:l:d", - ["help","songbook=","output=","depend","library="]) - except getopt.GetoptError, err: - # print help and exit - print str(err) - usage() - sys.exit(2) - - songbook = None - depend = False - output = None - library = './' - - for o, a in opts: - if o in ("-h", "--help"): - usage() - sys.exit() - elif o in ("-s", "--songbook"): - songbook = a - elif o in ("-d", "--depend"): - depend = True - elif o in ("-o", "--output"): - output = a - elif o in ("-l", "--library"): - if not a.endswith('/'): - a += '/' - library = a - else: - assert False, "unhandled option" - - makeCoverCache(library) - if songbook and output: - f = open(songbook) - sb = json.load(f) - f.close() - - if depend: - makeDepend(sb, library, output) - else: - makeTexFile(sb, library, output) - -if __name__ == '__main__': - main() diff --git a/python/song.py b/song.py similarity index 76% rename from python/song.py rename to song.py index 5f65cf3e..d0d5a264 100644 --- a/python/song.py +++ b/song.py @@ -7,15 +7,15 @@ import re reTitle = re.compile('(?<=beginsong\\{)(.(?= (2,6): - return '\\hyperlink{{{0[link]}}}{{{0[num]}}}'.format(ref) - else: - return '\\hyperlink{%(link)s}{%(num)s}' % ref - - def entryToStr(self, key, entry): - if sys.version_info >= (2,6): - return '\\idxentry{{{0}}}{{{1}}}\n'.format(key, '\\\\'.join(map(self.refToStr, entry))) - else: - return '\\idxentry{%s}{%s}\n' % (key, '\\\\'.join(map(self.refToStr, entry))) - - def idxBlockToStr(self, letter, entries): - str = '\\begin{idxblock}{'+letter+'}'+'\n' - for key in sorted(entries.keys(), key=sortindex.sortkey): - str += self.entryToStr(key, entries[key]) - str += '\\end{idxblock}'+'\n' - return str - - def entriesToStr(self): - str = "" - for letter in sorted(self.data.keys()): - str += self.idxBlockToStr(letter, self.data[letter]) - return str - -def processSXDEntry(tab): - return (tab[0], tab[1], tab[2]) - -def processSXD(filename): - file = open(filename) - data = [] - for line in file: - data.append(line.strip()) - file.close() - - type = data[0] - i = 1 - idx = index() - - if len(data) > 1: - while data[i].startswith('%'): - keywords = keywordPattern.match(data[i]).groups() - idx.keyword(keywords[0],keywords[1]) - i += 1 - - idx.compileKeywords() - for i in range(i,len(data),3): - entry = processSXDEntry(data[i:i+3]) - idx.add(entry[0],entry[1],entry[2]) - return idx - -def usage(exitCode=None): - print "usage: songbook-makeindex.py [options] source" - sys.exit(exitCode) - -def main(): - locale.setlocale(locale.LC_ALL, '') - usage = "usage: %prog [options] FILE" - parser = OptionParser(usage) - parser.add_option("-o", "--output", dest="filename", - help="write result into FILE", metavar="FILE") - (options, args) = parser.parse_args() - - # Args processing - if len(args) != 1: - parser.error("incorrect number of arguments") - if not os.path.exists(args[0]): - parser.error("inexistant input file") - - # Options processing - if options.filename: - output = open(options.filename,"w") - else: - output = sys.stdout - - # Actual processing - idx = processSXD(args[0]) - output.write(idx.entriesToStr()) - -if __name__ == '__main__': - main() diff --git a/songbook.py b/songbook.py index f07a3006..082e31e2 100755 --- a/songbook.py +++ b/songbook.py @@ -36,11 +36,12 @@ def songslist(library, songs, prefixes): title = reTitle.search(data).group(0) artist = reArtist.search(data.replace("{","")).group(0) match = reAlbum.search(data.replace("{","")) + lilypond = False if match: album = match.group(0) else: album = '' - song_objects.append(Song(title, artist, album, path)) + song_objects.append(Song(title, artist, album, path, lilypond)) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(unprefixed(x.title, prefixes))) song_objects = sorted(song_objects, key=lambda x: locale.strxfrm(x.album)) diff --git a/python/tools.py b/tools.py similarity index 100% rename from python/tools.py rename to tools.py