2016-02-22 05:37:13 +01:00
|
|
|
#!/bin/python3
|
|
|
|
## Script to easily generate a set (concatenated scores)
|
|
|
|
|
2016-03-15 16:33:09 +01:00
|
|
|
import codecs, os, sys
|
2016-02-22 05:37:13 +01:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
|
|
|
|
parser = ArgumentParser(__file__)
|
|
|
|
parser.add_argument('setfile')
|
2016-07-12 11:23:53 +02:00
|
|
|
parser.add_argument('-c',dest='copy',action='store_true',default=False,help="Copy files instead of just linkingi")
|
|
|
|
parser.add_argument('-t',dest='title',help="Title for the set")
|
2016-02-22 05:37:13 +01:00
|
|
|
parser.add_argument('scores',nargs='+')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2016-03-15 16:33:09 +01:00
|
|
|
if os.path.isdir(args.setfile):
|
|
|
|
print("First argument cannot be a directory ")
|
|
|
|
sys.exit()
|
|
|
|
|
2016-07-12 11:23:53 +02:00
|
|
|
if os.path.dirname(args.setfile):
|
|
|
|
os.makedirs(os.path.dirname(args.setfile), exist_ok=True)
|
|
|
|
|
|
|
|
if args.setfile == '--':
|
|
|
|
fprint = print
|
|
|
|
else:
|
|
|
|
fpoint = codecs.open(args.setfile, 'w+', 'utf8')
|
|
|
|
fprint = fpoint.write
|
|
|
|
|
|
|
|
fprint(u'\ufeff')
|
|
|
|
fprint('\\version \"2.18.2\"\n\n')
|
|
|
|
|
|
|
|
if args.title:
|
|
|
|
fprint(
|
|
|
|
"\header {"+
|
|
|
|
"title = \"" + args.title + "\""+
|
|
|
|
"}\n")
|
|
|
|
|
|
|
|
fprint(
|
|
|
|
"\paper {"+
|
|
|
|
"#(define page-breaking ly:minimal-breaking)" +
|
|
|
|
"}\n")
|
|
|
|
|
2016-12-21 01:43:59 +01:00
|
|
|
fprint("#(ly:set-option 'relative-includes #t)\n")
|
|
|
|
|
2016-07-12 11:23:53 +02:00
|
|
|
fprint("\n\n%Scores\n")
|
2016-02-22 05:37:13 +01:00
|
|
|
|
|
|
|
for f in args.scores:
|
|
|
|
|
|
|
|
if not os.path.exists(f):
|
|
|
|
continue
|
|
|
|
|
|
|
|
if args.copy is True:
|
|
|
|
text = codecs.open(f, 'r', 'utf8').read()
|
|
|
|
if text.startswith(u'\ufeff'): text = text[1:]
|
|
|
|
text = text.split(u'\n')
|
|
|
|
|
|
|
|
for line in text:
|
|
|
|
if line.startswith(u'\\include'):
|
|
|
|
incline = line.replace('\\include', '').strip('"\' ')
|
|
|
|
|
|
|
|
if not incline.startswith('\\'): #already absolute
|
|
|
|
incline = os.path.join(os.path.abspath(os.path.dirname(f)), incline)
|
|
|
|
|
|
|
|
line = "\\include \""+incline+"\""
|
2016-07-12 11:23:53 +02:00
|
|
|
fprint(line.replace('\r', '')+'\n')
|
2016-02-22 05:37:13 +01:00
|
|
|
else:
|
2016-07-12 11:23:53 +02:00
|
|
|
fprint('\\include \"' + os.path.join( os.path.abspath( os.curdir ) ,f) + '\"\n')
|
2016-02-22 05:37:13 +01:00
|
|
|
|
|
|
|
fpoint.close()
|