Changeset 114

Show
Ignore:
Timestamp:
01/29/06 10:56:47 (3 years ago)
Author:
tim
Message:

updated a lot of stuff for a 0.3 tag release

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/timadditionaltypes/pyramid/build.py

    r102 r114  
    130130 
    131131def main(options,args): 
    132      
    133132    if options.resources: 
    134133        resourcedirs = options.resources.split(',') 
     
    144143    build(options.data,options.out,verbose=options.verbose,resourcedirs=resourcedirs,rebuilddirs=rebuilddirs) 
    145144 
    146 if __name__ == "__main__": 
     145 
     146def parseOptions(): 
    147147    parser = OptionParser() 
    148148    parser.add_option("-d", "--data", dest="data", help="directory in which the fragment data is stored", metavar="DATA") 
     
    152152    parser.add_option("-R", "--rebuilddirs",dest="rebuilddirs",help="only rebuild below these comma separated directories",metavar="REBUILDDIRS") 
    153153    (options, args) = parser.parse_args() 
    154      
    155154    main(options,args) 
     155 
     156if __name__ == "__main__": 
     157    parseOptions() 
  • branches/timadditionaltypes/pyramid/flatteners.py

    r104 r114  
    6262            fp = open(restfile) 
    6363        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) 
    6772 
    6873class HtmlFileFlattener(components.Adapter): 
  • branches/timadditionaltypes/pyramid/restParser.py

    r110 r114  
    5151 
    5252def 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', 
    5454                  doctitle=0, initial_header_level=1): 
    5555    """ 
     
    6464      string is desired, use the default value of "unicode" . 
    6565    """ 
     66    try: 
     67        input_string = input_string.decode('utf-8') 
     68    except: 
     69        input_string = input_string.decode('iso-8859-1') 
     70         
    6671    parts = html_parts( 
    6772        input_string=input_string, source_path=source_path, 
  • branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/.cache.dump

    r100 r114  
    145145(g50 
    146146g6 
    147 S'<p><a class="reference" href="http://www.europython.com">EuroPython</a> 2004 is taking place in G\xc3\xb6teborg,\nSweden from June 7-9 2004. Register today or view the programme</p>\n' 
     147S'<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' 
    148148tRp67 
    149149sS'href' 
  • branches/timadditionaltypes/pyramid/test/testdata/build_tests/firstpythontest/expected/index.html

    r100 r114  
    145145 
    146146<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, 
    148148Sweden from June 7-9 2004. Register today or view the programme</p> 
    149149 
  • branches/timadditionaltypes/pyramid/test/tests.py

    r102 r114  
    2323        removeTemp(dir) 
    2424    os.mkdir(dir)      
     25 
     26def 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 
     62from logilab.xmldiff.format import AbstractFormatter 
     63from logilab.xmldiff.objects import f_xpath,A_N2 
     64import types 
     65 
     66class 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 
     85def 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 
    25133 
    26134def compareDirs(actual,expected,skipdirs=[],skipfiles=[]): 
     
    42150                        return False 
    43151                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)) 
    46155                    if len(result) > 0: 
     156                        print '#'*80 
     157                        print filetext1 
     158                        print '<'*80 
     159                        print filetext2 
     160                        print '#'*80 
    47161                        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) 
    49164                        print '='*70 
    50165                        return False 
     
    125240        """ remove all test folders 
    126241        """ 
    127         removeTemp(TEMPFOLDER)          
     242        #removeTemp(TEMPFOLDER)          
    128243     
    129244if __name__ == "__main__": 
  • branches/timadditionaltypes/setup.py

    r96 r114  
    1 from setuptools import setup 
     1#from setuptools import setup 
     2from distutils.core import setup 
    23setup(name='pyramid', 
    3       version='0.2', 
     4      version='0.3', 
    45      description='Pydotorg Website Build System', 
    56      author='Tim Parkin', 
     
    78      url='http://pyramid.pollenation.net', 
    89      packages=['pyramid'], 
    9       scripts=['pyramid/instantwebserver'], 
     10      scripts=['pyramid/instantwebserver','pyramid/pyramid'], 
    1011      )