Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+reprettyprinter; hypertext rendering of LDF done
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@670 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
33841b1
commit 679b2d8
Showing
10 changed files
with
597 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/python | ||
import os | ||
import sys | ||
import string | ||
import slpsns | ||
import elementtree.ElementTree as ET | ||
|
||
def identify(e): | ||
if 'id' in e.attrib: | ||
return e.tag+'@'+e.get('id') | ||
else: | ||
return e.tag | ||
|
||
def createCleanElementFrom(e): | ||
#print 'Copying element',e.tag.replace(slpsns.htm_(''),'') | ||
e2 = ET.Element(e.tag.replace(slpsns.htm_(''),'')) | ||
if e.text: | ||
e2.text = e.text | ||
if e.tail: | ||
e2.tail = e.tail | ||
for a in e.attrib: | ||
e2.set(a,e.get(a)) | ||
#print 'Copying attribute',a | ||
for se in e.findall('*'): | ||
e2.append(createCleanElementFrom(se)) | ||
return e2 | ||
|
||
|
||
def repp(localpath,tree,prettyprinter): | ||
ending = '' | ||
for e in tree.findall('*'): | ||
tree.remove(e) | ||
tree.text = '' | ||
inputfile = 'printed_for_xldf.tmp' | ||
if os.system(localpath+prettyprinter+' '+localpath+tree.get('src')+' '+inputfile): | ||
print '[----] Failed: can''t execute the pretty-printer!' | ||
return | ||
for e in ET.parse(inputfile).findall('/*/*'): | ||
#for e in ET.XML('<t>'+''.join(open(inputfile,'r').readlines())+'</t>').findall('*'): | ||
tree.append(createCleanElementFrom(e)) | ||
print '[++++] Re-pretty-printed.' | ||
return | ||
|
||
|
||
def main(inldffile,ppfile,outldffile): | ||
tree = ET.parse(inldffile) | ||
if inldffile.find('/')<0: | ||
localpath = '' | ||
else: | ||
localpath = '/'.join(inldffile.split('/')[:-1])+'/' | ||
cx = 0 | ||
for s in tree.findall('//sample'): | ||
print '[????] Found',identify(s),'of',s.get('src') | ||
repp(localpath,s,ppfile) | ||
cx += 1 | ||
print 'Total',cx,'samples processed' | ||
tree.write(outldffile) | ||
return | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 4: | ||
apply(main,sys.argv[1:4]) | ||
else: | ||
print '''Change the Pretty-Printer automation tool | ||
Usage:''' | ||
print ' ',sys.argv[0],'<input ldf file>','<new samples pretty-printer>','<output ldf file>' | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#! /bin/sh | ||
|
||
# Get our hands on basedir | ||
LOCAL1=${PWD} | ||
cd `dirname $0` | ||
cd ../.. | ||
SLPS=${PWD} | ||
cd ${LOCAL1} | ||
|
||
if [ $# -ne 3 ]; then | ||
echo "Usage: repp <LDF-input> <preprocessor> <LDF-output>" | ||
exit 1 | ||
elif [ ! -r $1 ]; then | ||
echo "Oops: $1 not found or not readable." | ||
exit 1 | ||
elif [ ! -r $2 ]; then | ||
echo "Oops: $2 not found or not readable." | ||
exit 1 | ||
else | ||
rm -f $3 | ||
python ${SLPS}/shared/python/repp.py $1 $2 $3 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.