Move prev/next field reading into abctemplate.py.
Fishing all that stuff out in makeWeb.sh was a bit ugly.
This commit is contained in:
parent
5d49c010e1
commit
fd98182250
|
@ -40,6 +40,24 @@ import string
|
||||||
|
|
||||||
from abcfield import getFieldDisplayText, getFullTitle
|
from abcfield import getFieldDisplayText, getFullTitle
|
||||||
|
|
||||||
|
def getFileData(f, latex):
|
||||||
|
res = {}
|
||||||
|
input_path = pathlib.Path(args.input.name)
|
||||||
|
res["name"] = input_path.stem
|
||||||
|
fdir = input_path.parent
|
||||||
|
|
||||||
|
lines = f.readlines()
|
||||||
|
res["title"] = getFieldDisplayText(lines, fdir, "T", latex=latex)
|
||||||
|
res["subtitle"] = getFieldDisplayText(lines, fdir, "T", n=2, latex=latex)
|
||||||
|
res["fulltitle"] = getFullTitle(lines, fdir, latex=latex)
|
||||||
|
res["tradition"] = getFieldDisplayText(lines, fdir, "A", latex=latex)
|
||||||
|
res["composer"] = getFieldDisplayText(lines, fdir, "C", latex=latex)
|
||||||
|
res["key"] = getFieldDisplayText(lines, fdir, "K", latex=latex)
|
||||||
|
res["parts"] = getFieldDisplayText(lines, fdir, "P", latex=latex)
|
||||||
|
res["notes"] = getFieldDisplayText(lines, fdir, "N", starts="Dottes:", latex=latex)
|
||||||
|
res["history"] = getFieldDisplayText(lines, fdir, "H", starts="Dottes:", latex=latex)
|
||||||
|
return res
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Substitute values from ABC file into template.')
|
parser = argparse.ArgumentParser(description='Substitute values from ABC file into template.')
|
||||||
parser.add_argument('-l', '--latex', dest='latex',
|
parser.add_argument('-l', '--latex', dest='latex',
|
||||||
|
@ -51,36 +69,41 @@ if __name__ == "__main__":
|
||||||
help='template file')
|
help='template file')
|
||||||
parser.add_argument('-v', '--value', dest='values', action="append",
|
parser.add_argument('-v', '--value', dest='values', action="append",
|
||||||
default=[], help='define var=value items for templater')
|
default=[], help='define var=value items for templater')
|
||||||
|
parser.add_argument('-n', '--next', dest='nextfile',
|
||||||
|
type=argparse.FileType('r'),
|
||||||
|
help='next tune file')
|
||||||
|
parser.add_argument('-p', '--prev', dest='prevfile',
|
||||||
|
type=argparse.FileType('r'),
|
||||||
|
help='previous tune file')
|
||||||
parser.add_argument('input', type=argparse.FileType('r'),
|
parser.add_argument('input', type=argparse.FileType('r'),
|
||||||
help='input ABC file')
|
help='input ABC file')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with args.input as f:
|
fields = getFileData(args.input, args.latex)
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
input_path = pathlib.Path(args.input.name)
|
vars = {}
|
||||||
fname = input_path.stem
|
|
||||||
fdir = input_path.parent
|
|
||||||
|
|
||||||
vars = dict()
|
|
||||||
vars["notesvisibility"] = "no"
|
vars["notesvisibility"] = "no"
|
||||||
vars["historyvisibility"] = "no"
|
vars["historyvisibility"] = "no"
|
||||||
|
|
||||||
vars["name"] = fname
|
for name in ["name", "title", "subtitle", "fulltitle", "tradition",
|
||||||
vars["title"] = getFieldDisplayText(lines, fdir, "T", latex=args.latex)
|
"composer", "key", "parts", "notes", "history"]:
|
||||||
vars["subtitle"] = getFieldDisplayText(lines, fdir, "T", n=2, latex=args.latex)
|
vars[name] = fields[name]
|
||||||
vars["fulltitle"] = getFullTitle(lines, fdir, latex=args.latex)
|
|
||||||
vars["tradition"] = getFieldDisplayText(lines, fdir, "A", latex=args.latex)
|
|
||||||
vars["composer"] = getFieldDisplayText(lines, fdir, "C", latex=args.latex)
|
|
||||||
vars["key"] = getFieldDisplayText(lines, fdir, "K", latex=args.latex)
|
|
||||||
vars["parts"] = getFieldDisplayText(lines, fdir, "P", latex=args.latex)
|
|
||||||
vars["notes"] = getFieldDisplayText(lines, fdir, "N", starts="Dottes:", latex=args.latex)
|
|
||||||
if vars["notes"]:
|
if vars["notes"]:
|
||||||
vars["notesvisibility"] = "yes"
|
vars["notesvisibility"] = "yes"
|
||||||
vars["history"] = getFieldDisplayText(lines, fdir, "H", starts="Dottes:", latex=args.latex)
|
|
||||||
if vars["history"]:
|
if vars["history"]:
|
||||||
vars["historyvisibility"] = "yes"
|
vars["historyvisibility"] = "yes"
|
||||||
|
|
||||||
|
if args.nextfile:
|
||||||
|
fields = getFileData(args.nextfile, args.latex)
|
||||||
|
for name in ["name", "title", "subtitle", "fulltitle"]:
|
||||||
|
vars["next" + name] = fields[name] if args.nextfile else ""
|
||||||
|
|
||||||
|
if args.prevfile:
|
||||||
|
fields = getFileData(args.prevfile, args.latex)
|
||||||
|
for name in ["name", "title", "subtitle", "fulltitle"]:
|
||||||
|
vars["prev" + name] = fields[name] if args.prevfile else ""
|
||||||
|
|
||||||
for val in args.values:
|
for val in args.values:
|
||||||
keyval = val.partition("=")
|
keyval = val.partition("=")
|
||||||
vars[keyval[0]] = keyval[2]
|
vars[keyval[0]] = keyval[2]
|
||||||
|
|
34
makeWeb.sh
34
makeWeb.sh
|
@ -93,25 +93,21 @@ do
|
||||||
# Get date and time of last change to tune.
|
# Get date and time of last change to tune.
|
||||||
lastchanged=`hg log --limit 1 --template "{date|shortdate}" $masterbookedir/${name}.abc`
|
lastchanged=`hg log --limit 1 --template "{date|shortdate}" $masterbookedir/${name}.abc`
|
||||||
|
|
||||||
# Get previous and next tune page names and titles.
|
# Get previous and next tunes, if available.
|
||||||
|
prevarg=""
|
||||||
prevpage=""
|
prevpage=""
|
||||||
prevtitle=""
|
nextarg=""
|
||||||
prevfulltitle=""
|
|
||||||
nextpage=""
|
nextpage=""
|
||||||
nexttitle=""
|
|
||||||
nextfulltitle=""
|
|
||||||
|
|
||||||
if [ $i -gt 0 ]; then
|
if [ $i -gt 0 ]; then
|
||||||
prev=${filenames[$((i - 1))]}
|
prev=${filenames[$((i - 1))]}
|
||||||
prevpage=`basename $prev .abc`.html
|
prevpage=`basename $prev .abc`.html
|
||||||
prevtitle=`./abcfield.py --display --field="T" $prev`
|
prevarg="--prev $prev"
|
||||||
prevfulltitle=`./abcfield.py --display --field="FT" $prev`
|
|
||||||
fi
|
fi
|
||||||
if [ $i -lt $((nofiles - 1)) ]; then
|
if [ $i -lt $((nofiles - 1)) ]; then
|
||||||
next=${filenames[$((i + 1))]}
|
next=${filenames[$((i + 1))]}
|
||||||
nextpage=`basename $next .abc`.html
|
nextpage=`basename $next .abc`.html
|
||||||
nexttitle=`./abcfield.py --display --field="T" $next`
|
nextarg="--next $next"
|
||||||
nextfulltitle=`./abcfield.py --display --field="FT" $next`
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Generate the tune web page.
|
# Generate the tune web page.
|
||||||
|
@ -122,21 +118,17 @@ do
|
||||||
--value "masterbooke=${masterbooke}" \
|
--value "masterbooke=${masterbooke}" \
|
||||||
--value "lastchanged=${lastchanged}" \
|
--value "lastchanged=${lastchanged}" \
|
||||||
--value "prevpage=${prevpage}" \
|
--value "prevpage=${prevpage}" \
|
||||||
--value "prevtitle=${prevtitle}" \
|
|
||||||
--value "prevfulltitle=${prevfulltitle}" \
|
|
||||||
--value "nextpage=${nextpage}" \
|
--value "nextpage=${nextpage}" \
|
||||||
--value "nexttitle=${nexttitle}" \
|
${prevarg} ${nextarg} \
|
||||||
--value "nextfulltitle=${nextfulltitle}" \
|
--template dottes.html.tune \
|
||||||
--template dottes.html.tune $filename > $webdir/$tunepage
|
$filename > $webdir/$tunepage
|
||||||
$dir/abctemplate.py \
|
$dir/abctemplate.py \
|
||||||
--value "masterbooke=${masterbooke}" \
|
--value "masterbooke=${masterbooke}" \
|
||||||
--value "lastchanged=${lastchanged}" \
|
--value "lastchanged=${lastchanged}" \
|
||||||
--value "prevpage=learner-${prevpage}" \
|
--value "prevpage=${prevpage}" \
|
||||||
--value "prevtitle=${prevtitle}" \
|
--value "nextpage=${nextpage}" \
|
||||||
--value "prevfulltitle=${prevfulltitle}" \
|
${prevarg} ${nextarg} \
|
||||||
--value "nextpage=learner-${nextpage}" \
|
--template dottes.html.learnertune \
|
||||||
--value "nexttitle=${nexttitle}" \
|
$filename > $webdir/$learnerpage
|
||||||
--value "nextfulltitle=${nextfulltitle}" \
|
|
||||||
--template dottes.html.learnertune $filename > $webdir/$learnerpage
|
|
||||||
$dir/abctemplate.py --template dottes.html.tuneindex $filename >> $webdir/$tunelist
|
$dir/abctemplate.py --template dottes.html.tuneindex $filename >> $webdir/$tunelist
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue