Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDF->sample set script, ex-part of LCI
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@210 ab42f6e0-554d-0410-b580-99e487e6eeb2
- Loading branch information
1 parent
3b03867
commit 387c320
Showing
2 changed files
with
67 additions
and
0 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,6 @@ | ||
test: | ||
xsltproc ../../../shared/xsl/ldf2samples.xslt ../../fl/ldf/fl.ldf > samples.xml | ||
python xml2set.py samples.xml samples | ||
|
||
clean: | ||
rm -rf samples/* samples.xml *.pyc |
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,61 @@ | ||
#!/usr/bin/python | ||
import sys | ||
from elementtree import ElementTree | ||
|
||
def copyfile(x,y): | ||
xh=open(x,'r') | ||
yh=open(y,'w') | ||
yh.writelines(xh.readlines()) | ||
xh.close() | ||
yh.close() | ||
|
||
def unpacksamples(where,dir): | ||
library={} | ||
cx = 0 | ||
tree = ElementTree.parse(where) | ||
for outline in tree.findall("//sample"): | ||
cx+=1 | ||
torun = open (dir+'/sample'+`cx`+'.src',"w") | ||
for line in outline.text.split('\n'): | ||
if line.strip()!='': | ||
torun.write(line.strip()+'\n') | ||
torun.close() | ||
if outline.attrib.has_key('id'): | ||
library[outline.attrib['id']]=outline.text | ||
if outline.attrib.has_key('sort'): | ||
sort=outline.attrib['sort'] | ||
else: | ||
sort=None | ||
# All executions | ||
for outline in tree.findall("//runnable"): | ||
if outline.findtext('context'): | ||
if not library.has_key(outline.findtext('context')): | ||
print "No context found for sample",cx,'('+outline.findtext('context')+'), test case not used' | ||
continue | ||
else: | ||
con = open (dir+'/sample'+`cx`+'.src','w') | ||
for line in library[outline.findtext('context')].split('\n'): | ||
if line.strip()!='': | ||
con.write(line.strip()+'\n') | ||
con.close() | ||
if outline.findtext('yields'): | ||
con = open (dir+'/sample'+`cx`+'.val','w') | ||
con.write(outline.findtext('yields')) | ||
con.close() | ||
cx+=1 | ||
torun = open (dir+'/sample'+`cx`+'.run','w') | ||
line = outline.findtext('main') | ||
for arg in outline.findall("argument"): | ||
line += ' ' + arg.text | ||
torun.write(line+'\n') | ||
torun.close() | ||
print cx,'samples in the test set.' | ||
|
||
if __name__ == "__main__": | ||
print 'Sample Set Extractor' | ||
if len(sys.argv) == 3: | ||
unpacksamples(sys.argv[1],sys.argv[2]) | ||
else: | ||
print 'Usage:' | ||
print ' ',sys.argv[0],'<configuration file>','<output pdf>' | ||
sys.exit(1) |