Add --contains flag to abcfield.py.

Currently we rely on any N: field with a Change: subnotice being the first
N: field. Add --contains field to abcfield.py to remove this restriction.

Also use it to extract new subfield Credit: and add that if present
to the tune information in print and on web.
This commit is contained in:
Jim Hague 2013-08-04 22:09:25 +01:00
parent 18e13bd98e
commit 6427153e8e
9 changed files with 40 additions and 6 deletions

View File

@ -5,6 +5,7 @@ R:March
O:England
Z:Paul Hardy's Session Tunebook 2013 (see www.paulhardy.net). Creative Commons cc by-nc-sa licenced.
N: Change: GatheringPeascods.abc
N: Credit: Paul Hardy's Session Tunebook
M:2/2
L:1/8
Q:1/2=90

View File

@ -3,6 +3,7 @@ T:Buttered Peas
R:Polka
O:England
Z:Paul Hardy's Session Tunebook 2013 (see www.paulhardy.net). Creative Commons cc by-nc-sa licenced.
N: Credit: Paul Hardy's Session Tunebook
M:2/2
L:1/8
Q:1/4=180

View File

@ -3,6 +3,7 @@ T:Orange in Bloom
T:Sherborne Waltz
R:Waltz
O:England
N: Credit: Paul Hardy's Session Tunebook
Z:Paul Hardy's Session Tunebook 2013 (see www.paulhardy.net). Creative Commons cc by-nc-sa licenced.
M:3/4
L:1/8

View File

@ -109,6 +109,9 @@ def process(inf, options):
for line in inf:
line = line.strip()
if len(line) > 2 and line[0] == options.field and line[1] == ':':
if len(options.contains) > 0:
if line.find(options.contains) < 0:
continue
if n > 1:
n = n - 1
else:
@ -129,6 +132,10 @@ parser.add_option("-n", "--index", dest="index",
action="store", type="int", default=1,
help="report INDEXth value [default: %default]",
metavar="INDEX")
parser.add_option("-c", "--contains", dest="contains",
action="store", type="string", default="",
help="report only if line contains CONTENT",
metavar="CONTENT")
(options, args) = parser.parse_args()
if options.html and options.latex:

View File

@ -34,6 +34,9 @@
</div>
</div>
<img class="dottes-png" src="@TUNE@.png" alt="@TITLE@ dots">
<div class="dottes-credit-@CREDITVISIBILITY@">
From @CREDIT@.
</div>
<div class="dottes-change-@CHANGEVISIBILITY@">
Change: <a class="dottes-change-link"
href="@CHANGETUNE@">@CHANGETITLE@</a>

View File

@ -47,8 +47,8 @@
% Show the main tune graphic and optional change.
% Args are tune name, tune title, tune subtitle, composer, tune graphic
% filename, change name, change title.
\newcommand{\showtune}[7]{%
% filename, change name, change title, credit.
\newcommand{\showtune}[8]{%
\vfill
\begin{center}
\phantomsection
@ -63,8 +63,11 @@
}
\addcontentsline{toc}{section}{#2}
\end{center}
\ifemptyarg{#8}{}{%
From {#8}.
}%
\ifemptyarg{#6}{}{%
Change: \hyperlink{#6}{#7}
Change: \hyperlink{#6}{#7}.
}%
}

View File

@ -44,7 +44,7 @@ find $booke -name "*.abc" | sort |
subtitle=`$dir/abcfield.py --index 2 --field T --latex $filename`
composer=`$dir/abcfield.py --field C --latex $filename`
changefile=`$dir/abcfield.py --field N $filename | grep "Change:" | sed -e "s/Change: *//"`
changefile=`$dir/abcfield.py --field N --contains "Change:" $filename | sed -e "s/Change: *//"`
changename=""
changetitle=""
if [ -n "$changefile" ]; then
@ -53,7 +53,9 @@ find $booke -name "*.abc" | sort |
fixtitle "$changetitle"
changetitle=$retval
fi
echo -E "\showtune{$name}{$title}{$subtitle}{$composer}{$graphicsdir/$name}{$changename}{$changetitle}" >> $tunesoutput
credit=`$dir/abcfield.py --field N --contains "Credit:" $filename | sed -e "s/Credit: *//"`
echo -E "\showtune{$name}{$title}{$subtitle}{$composer}{$graphicsdir/$name}{$changename}{$changetitle}{$credit}" >> $tunesoutput
echo -E "\showfirstline{$name}{$title}{$graphicsdir/firstline-$name}" >> $indexoutput
done

View File

@ -67,7 +67,7 @@ find $bookedir -name "*.abc" | sort |
title=$retval
subtitle=`$dir/abcfield.py --index 2 --field T --latex $filename`
composer=`$dir/abcfield.py --field C --latex $filename`
changefile=`$dir/abcfield.py --field N $filename | grep "Change:" | sed -e "s/Change: *//"`
changefile=`$dir/abcfield.py --field N --contains "Change:" $filename | sed -e "s/Change: *//"`
changetitle=""
changevisibility="no"
if [ -n "$changefile" ]; then
@ -77,6 +77,11 @@ find $bookedir -name "*.abc" | sort |
fixtitle "$changetitle"
changetitle=$retval
fi
credit=`$dir/abcfield.py --field N --contains "Credit:" $filename | sed -e "s/Credit: *//"`
creditvisibility="no"
if [ -n "$credit" ]; then
creditvisibility="yes"
fi
# Copy the ABC into the web.
cp $filename $webdir
@ -93,6 +98,8 @@ find $bookedir -name "*.abc" | sort |
-e "s/@CHANGETITLE@/${changetitle//&/\&}/" \
-e "s/@CHANGETUNE@/${changefile/.abc/.html}/" \
-e "s/@CHANGEVISIBILITY@/${changevisibility}/" \
-e "s/@CREDIT@/${credit}/" \
-e "s/@CREDITVISIBILITY@/${creditvisibility}/" \
-e "s/@TUNE@/${name}/" dottes.html.tune > $webdir/$tunepage
sed -e "s/@TITLE@/${title//&/\&}/" \

View File

@ -244,3 +244,12 @@ div.dottes-change-yes
div.dottes-change-link
{
}
div.dottes-credit-no
{
display: none;
}
div.dottes-credit-yes
{
}