Skip to content

Commit

Permalink
use xslt to remove random IDs from files
Browse files Browse the repository at this point in the history
  • Loading branch information
agrippa committed Mar 10, 2012
1 parent 29cf742 commit 5ceb31a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions oerpub/rhaptoslabs/swordpushweb/test/generate_valid_cnxml.py
Expand Up @@ -23,6 +23,12 @@
from utils import clean_cnxml, escape_system from utils import clean_cnxml, escape_system
from lxml import etree from lxml import etree


def remove_ids(filename):
command='xsltproc -o tmp.xml removeid.xsl '+filename
os.system(command)
os.system('cp tmp.xml '+filename)


if(len(sys.argv) != 2): if(len(sys.argv) != 2):
print('usage: python generate_valid_cnxml.py file') print('usage: python generate_valid_cnxml.py file')
quit() quit()
Expand All @@ -45,6 +51,7 @@
output.write(cnxml) output.write(cnxml)
output.close() output.close()
os.remove(filename) os.remove(filename)
remove_ids(valid_filename)
elif(extension == '.gdoc'): elif(extension == '.gdoc'):
valid_filename=name+'.cnxml' valid_filename=name+'.cnxml'
fp=open(filename, 'r') fp=open(filename, 'r')
Expand All @@ -56,6 +63,7 @@
output=open(valid_filename,'w') output=open(valid_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(valid_filename)


else: else:
print('Assuming this is a file containing a URL') print('Assuming this is a file containing a URL')
Expand All @@ -81,6 +89,7 @@
output=open(valid_filename,'w') output=open(valid_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(valid_filename)
except urllib2.URLError, e: except urllib2.URLError, e:
print('URL '+url+' could not be opened') print('URL '+url+' could not be opened')
quit() quit()
Expand Down
9 changes: 9 additions & 0 deletions oerpub/rhaptoslabs/swordpushweb/test/test_conversion.py
Expand Up @@ -31,6 +31,11 @@


test_folder_name='test_files/' test_folder_name='test_files/'


def remove_ids(filename):
command='xsltproc -o tmp.xml removeid.xsl '+filename
os.system(command)
os.system('cp tmp.xml '+filename)

class SimpleTest(unittest.TestCase): class SimpleTest(unittest.TestCase):
def setUp(self): def setUp(self):
pass pass
Expand Down Expand Up @@ -75,6 +80,7 @@ def test_doc(self):
output=open(output_filename,'w') output=open(output_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE) process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate() std_output = process.communicate()


Expand Down Expand Up @@ -123,6 +129,7 @@ def test_odt(self):
output=open(output_filename,'w') output=open(output_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE) process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate() std_output = process.communicate()


Expand Down Expand Up @@ -177,6 +184,7 @@ def test_url(self):
output=open(output_filename,'w') output=open(output_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(output_filename)


process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE) process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate() std_output = process.communicate()
Expand Down Expand Up @@ -226,6 +234,7 @@ def test_gdocs(self):
output=open(output_filename,'w') output=open(output_filename,'w')
output.write(cnxml) output.write(cnxml)
output.close() output.close()
remove_ids(output_filename)


process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE) process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate() std_output = process.communicate()
Expand Down

0 comments on commit 5ceb31a

Please sign in to comment.