Changeset 114
- Timestamp:
- 01/29/06 10:56:47 (3 years ago)
- Files:
-
- branches/timadditionaltypes/pyramid/build.py (modified) (3 diffs)
- branches/timadditionaltypes/pyramid/flatteners.py (modified) (1 diff)
- branches/timadditionaltypes/pyramid/pyramid (added)
- branches/timadditionaltypes/pyramid/restParser.py (modified) (2 diffs)
- branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/.cache.dump (modified) (1 diff)
- branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/index.html (modified) (1 diff)
- branches/timadditionaltypes/pyramid/test/tests.py (modified) (3 diffs)
- branches/timadditionaltypes/setup.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/timadditionaltypes/pyramid/build.py
r102 r114 130 130 131 131 def main(options,args): 132 133 132 if options.resources: 134 133 resourcedirs = options.resources.split(',') … … 144 143 build(options.data,options.out,verbose=options.verbose,resourcedirs=resourcedirs,rebuilddirs=rebuilddirs) 145 144 146 if __name__ == "__main__": 145 146 def parseOptions(): 147 147 parser = OptionParser() 148 148 parser.add_option("-d", "--data", dest="data", help="directory in which the fragment data is stored", metavar="DATA") … … 152 152 parser.add_option("-R", "--rebuilddirs",dest="rebuilddirs",help="only rebuild below these comma separated directories",metavar="REBUILDDIRS") 153 153 (options, args) = parser.parse_args() 154 155 154 main(options,args) 155 156 if __name__ == "__main__": 157 parseOptions() branches/timadditionaltypes/pyramid/flatteners.py
r104 r114 62 62 fp = open(restfile) 63 63 except IOError: 64 print 'IOError whilst trying to open "restfile" %s'%(restfile) 65 66 return T.xml(restParser.html_fragment(fp.read())) 64 print 'IOError whilst trying to open "restfile" %s'%(restfile) 65 66 try: 67 contents = fp.read() 68 output = restParser.html_fragment(contents) 69 except UnicodeError: 70 print contents 71 return T.xml(output) 67 72 68 73 class HtmlFileFlattener(components.Adapter): branches/timadditionaltypes/pyramid/restParser.py
r110 r114 51 51 52 52 def html_fragment(input_string, source_path=None, destination_path=None, 53 input_encoding=' iso-8859-1', output_encoding='utf8',53 input_encoding='unicode', output_encoding='utf8', 54 54 doctitle=0, initial_header_level=1): 55 55 """ … … 64 64 string is desired, use the default value of "unicode" . 65 65 """ 66 try: 67 input_string = input_string.decode('utf-8') 68 except: 69 input_string = input_string.decode('iso-8859-1') 70 66 71 parts = html_parts( 67 72 input_string=input_string, source_path=source_path, branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/.cache.dump
r100 r114 145 145 (g50 146 146 g6 147 S'<p><a class="reference" href="http://www.europython.com">EuroPython</a> 2004 is taking place in G\xc3\x b6teborg,\nSweden from June 7-9 2004. Register today or view the programme</p>\n'147 S'<p><a class="reference" href="http://www.europython.com">EuroPython</a> 2004 is taking place in G\xc3\x83\xc2\xb6teborg,\nSweden from June 7-9 2004. Register today or view the programme</p>\n' 148 148 tRp67 149 149 sS'href' branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/index.html
r100 r114 145 145 146 146 <h2 class="news"><a href="/news/europython-2004">Europython in Göteborg, Sweden</a></h2> 147 <p><a class="reference" href="http://www.europython.com">EuroPython</a> 2004 is taking place in Gà ¶teborg,147 <p><a class="reference" href="http://www.europython.com">EuroPython</a> 2004 is taking place in Göteborg, 148 148 Sweden from June 7-9 2004. Register today or view the programme</p> 149 149 branches/timadditionaltypes/pyramid/test/tests.py
r102 r114 23 23 removeTemp(dir) 24 24 os.mkdir(dir) 25 26 def tree_from_stream(stream, 27 norm_sp=1, ext_ges=0, ext_pes=0, include_comment=1, 28 encoding='UTF-8', html=0): 29 """ 30 create internal tree from xml stream (open file or IOString) 31 if norm_sp = 1, normalize space and new line 32 """ 33 from xml.sax import make_parser, SAXNotRecognizedException 34 from xml.sax.handler import feature_namespaces, feature_external_ges, \ 35 feature_external_pes, property_lexical_handler 36 from logilab.xmldiff.parser import SaxHandler 37 handler = SaxHandler(norm_sp, include_comment, encoding) 38 if html: 39 parser = make_parser(["xml.sax.drivers2.drv_sgmlop_html"]) 40 else: 41 parser = make_parser() 42 # do not perform Namespace processing 43 parser.setFeature(feature_namespaces, 0) 44 # do not include any external entities 45 try: 46 parser.setFeature(feature_external_ges, ext_ges) 47 #xml.sax._exceptions. 48 except SAXNotRecognizedException: 49 pass 50 try: 51 parser.setFeature(feature_external_pes, ext_pes) 52 #xml.sax._exceptions. 53 except SAXNotRecognizedException: 54 pass 55 # add lexical handler for comments, entities, dtd and cdata 56 parser.setProperty(property_lexical_handler, handler) 57 parser.setContentHandler(handler) 58 parser.parse(stream) 59 return handler.get_tree() 60 61 62 from logilab.xmldiff.format import AbstractFormatter 63 from logilab.xmldiff.objects import f_xpath,A_N2 64 import types 65 66 class InternalPrinter(AbstractFormatter): 67 """ print actions in the internal format """ 68 69 def add_action(self, action): 70 """ 71 See AbstractFormatter interface 72 """ 73 if len(action) > 2 and type(action[A_N2]) == types.ListType: 74 if type(action[A_N1]) == types.ListType: 75 #swap or move node 76 action[A_N1] = f_xpath(action[A_N1]) 77 action[A_N2] = f_xpath(action[A_N2]) 78 AbstractFormatter.add_action(self, action) 79 80 def format_action(self, action): 81 """ 82 See AbstractFormatter interface 83 """ 84 pass 85 def htmldiff(text1, text2, norm_sp=1, xupd=0, ezs=0, verbose=0, ext_ges=0, ext_pes=0, include_comment=0, encoding='UTF-8', html=1): 86 """ Computes the diff between two files. 87 """ 88 from xml.sax import SAXParseException 89 from cStringIO import StringIO 90 fh1 = StringIO(text1) 91 fh2 = StringIO(text2) 92 93 # convert xml files to tree 94 try: 95 #from logilab.xmldiff.input import tree_from_stream 96 tree1 = tree_from_stream(fh1, norm_sp, ext_ges, 97 ext_pes, include_comment, 98 encoding, html) 99 tree2 = tree_from_stream(fh2, norm_sp, ext_ges, 100 ext_pes, include_comment, 101 encoding, html) 102 fh1.close () 103 fh2.close () 104 except SAXParseException, msg: 105 print msg 106 return -1 107 108 if verbose: 109 from logilab.xmldiff.objects import repr, N_ISSUE, N_CHILDS 110 print "Source tree\n", repr(tree1) 111 print "Destination tree\n", repr(tree2) 112 print 'Source tree has', tree1[N_ISSUE], 'nodes' 113 print 'Destination tree has', tree2[N_ISSUE], 'nodes' 114 # output formatter 115 if xupd: 116 from logilab.xmldiff.format import XUpdatePrinter 117 formatter = XUpdatePrinter() 118 else: 119 formatter = InternalPrinter() 120 # choose and apply tree to tree algorithm 121 if ezs: 122 from logilab.xmldiff.ezs import EzsCorrector 123 strategy = EzsCorrector(formatter) 124 else: 125 from logilab.xmldiff.fmes import FmesCorrector 126 #import gc 127 #gc.set_debug(gc.DEBUG_LEAK|gc.DEBUG_STATS) 128 strategy = FmesCorrector(formatter) 129 strategy.process_trees(tree1, tree2) 130 return formatter.edit_s 131 132 25 133 26 134 def compareDirs(actual,expected,skipdirs=[],skipfiles=[]): … … 42 150 return False 43 151 else: 44 d = difflib.Differ() 45 result = list(difflib.context_diff(filetext1,filetext2)) 152 result = htmldiff('\n'.join(filetext1),'\n'.join(filetext2)) 153 #d = difflib.Differ() 154 #result = list(difflib.context_diff(filetext1,filetext2)) 46 155 if len(result) > 0: 156 print '#'*80 157 print filetext1 158 print '<'*80 159 print filetext2 160 print '#'*80 47 161 print '%s\n Differences in generated output for %s\n%s' % ('='*70,relpath / file,'='*70) 48 print '\n'.join(result[3:]) 162 from pprint import pprint 163 pprint(result) 49 164 print '='*70 50 165 return False … … 125 240 """ remove all test folders 126 241 """ 127 removeTemp(TEMPFOLDER)242 #removeTemp(TEMPFOLDER) 128 243 129 244 if __name__ == "__main__": branches/timadditionaltypes/setup.py
r96 r114 1 from setuptools import setup 1 #from setuptools import setup 2 from distutils.core import setup 2 3 setup(name='pyramid', 3 version='0. 2',4 version='0.3', 4 5 description='Pydotorg Website Build System', 5 6 author='Tim Parkin', … … 7 8 url='http://pyramid.pollenation.net', 8 9 packages=['pyramid'], 9 scripts=['pyramid/instantwebserver' ],10 scripts=['pyramid/instantwebserver','pyramid/pyramid'], 10 11 )
