Skip to content

Commit

Permalink
Improve snippet checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Jan 17, 2012
1 parent 03ffefe commit 9ab0ce1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions snippet/bin/check_manuscript.py
@@ -1,15 +1,15 @@
#!/usr/bin/env python

# Check that the expected (or actual) snippets are in the manuscript. E.g.
# bin/check_manuscript.py ~/book-workspace/htdg2/ch11.xml expected/ch11/grunt/*
# bin/check_manuscript.py ~/book-workspace/htdg3/ch11.xml expected/ch11/grunt/*

# TODO: ignore id elements in the XML in the book.
# Need to use an XML parser for this.
import sys

manuscript = open(sys.argv[1], 'r').read()

for snippet_file in sys.argv[2:]:
index = manuscript.find(open(snippet_file, 'r').read())
lines = open(snippet_file, 'r').readlines()
snippet = "".join(lines[1:]).strip() # remove first line (comment) and strip spaces
index = manuscript.find(snippet)
if index == -1:
print "Snippet not found", snippet_file
17 changes: 12 additions & 5 deletions snippet/bin/check_manuscript.sh
Expand Up @@ -5,9 +5,16 @@ bin=`cd "$bin"; pwd`

actual="$bin"/../actual

$bin/check_manuscript.py ~/book-workspace/htdg3/ch02.xml $actual/ch02/*
$bin/check_manuscript.py ~/book-workspace/htdg3/ch04.xml $actual/ch04/*
$bin/check_manuscript.py ~/book-workspace/htdg3/ch05.xml $actual/ch05/*
$bin/check_manuscript.py ~/book-workspace/htdg3/ch07.xml $actual/ch07/*
for ch in ch02 ch04 ch05 ch07 ch08
do
# remove any id attributes from program listings
sed '/<programlisting/s/ id=".*"//' ~/book-workspace/htdg3/$ch.xml > /tmp/$ch.xml
$bin/check_manuscript.py /tmp/$ch.xml $actual/$ch/*
done

# Avro check
sed '/<programlisting/s/ id=".*"//' ~/book-workspace/htdg3/ch04.xml > /tmp/ch04-avro.xml
$bin/check_manuscript.py /tmp/ch04-avro.xml $actual/ch04-avro/*

# Common check
$bin/check_manuscript.py ~/book-workspace/htdg3/ch07.xml $actual/common/*
$bin/check_manuscript.py ~/book-workspace/htdg3/ch08.xml $actual/ch08/*

0 comments on commit 9ab0ce1

Please sign in to comment.