Permalink
Browse files

use xslt to remove random IDs from files

  • Loading branch information...
1 parent 29cf742 commit 5ceb31afb457c88d9cfeba079145b9e401b27842 @agrippa agrippa committed Mar 10, 2012
@@ -23,6 +23,12 @@
from utils import clean_cnxml, escape_system
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):
print('usage: python generate_valid_cnxml.py file')
quit()
@@ -45,6 +51,7 @@
output.write(cnxml)
output.close()
os.remove(filename)
+ remove_ids(valid_filename)
elif(extension == '.gdoc'):
valid_filename=name+'.cnxml'
fp=open(filename, 'r')
@@ -56,6 +63,7 @@
output=open(valid_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(valid_filename)
else:
print('Assuming this is a file containing a URL')
@@ -81,6 +89,7 @@
output=open(valid_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(valid_filename)
except urllib2.URLError, e:
print('URL '+url+' could not be opened')
quit()
@@ -31,6 +31,11 @@
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):
def setUp(self):
pass
@@ -75,6 +80,7 @@ def test_doc(self):
output=open(output_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate()
@@ -123,6 +129,7 @@ def test_odt(self):
output=open(output_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate()
@@ -177,6 +184,7 @@ def test_url(self):
output=open(output_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate()
@@ -226,6 +234,7 @@ def test_gdocs(self):
output=open(output_filename,'w')
output.write(cnxml)
output.close()
+ remove_ids(output_filename)
process = subprocess.Popen(['diff',valid_filename,output_filename], shell=False, stdout=subprocess.PIPE)
std_output = process.communicate()

0 comments on commit 5ceb31a

Please sign in to comment.