Beispiel #1
0
def run(*args):
    import os, getopt
    pgm = args[0]
    s_opt = 'Hrncgpe:xzhvV'
    l_opt = ['html', 'recursive',
             'not-normalize-space','exclude-comments','ext-ges','ext-pes'
             'encoding=', 'xupdate',
             'ezs', # DEPRICATED
             'help', 'verbose', 'version', 'profile=']
    # process command line options
    try:
        (opt, args) = getopt.getopt(args[1:], s_opt, l_opt)
    except getopt.error:
        sys.stderr.write ('Unkwnown option')
        usage(pgm)
        sys.exit(-1)
    recursive, html = 0, 0
    xupd, ezs, verbose= 0, 0, 0
    norm_sp, include_comment, ext_ges, ext_pes = 1, 1, 0, 0
    encoding = 'UTF-8'
    prof = ''
    for o in opt:
        if o[0] == '-r' or o[0] == '--recursive':
            recursive = 1
        elif o[0] == '-H' or o[0] == '--html':
            html = 1
        elif o[0] == '-n' or o[0] == '--not-normalize-space':
            norm_sp = 0
        elif o[0] == '-c' or o[0] == '--exclude-comments':
            include_comment = 0
        elif o[0] == '-g' or o[0] == '--ext-ges':
            ext_ges = 1
        elif o[0] == '-p' or o[0] == '--ext-pes':
            ext_ges = 1
        elif o[0] == '-e' or o[0] == '--encoding':
            encoding = o[1] 
        elif o[0] == '-x' or o[0] == '--xupdate':
            xupd = 1
        elif o[0] == '-z' or o[0] == '--ezs':
            ezs = 1
        elif o[0] == '-v' or o[0] == '--verbose':
            verbose = 1
        elif o[0] == '-p' or o[0] == '--profile':
            prof = o[1] 
        elif o[0] == '-h' or o[0] == '--help':
            usage(pgm)
            sys.exit(0)
        elif o[0] == '-V' or o[0] == '--version':
            from __init__ import modname, version
            print '%s version %s' % (modname, version)
            sys.exit(0)
    if len(args) != 2:
        usage(pgm)
        sys.exit(-2)
    file1, file2 = args[0], args[1]
    exit_status = 0
    # if args are directory    
    if os.path.isdir(file1) and os.path.isdir(file2):
        from misc import process_dirs, list_print
        common, deleted, added = process_dirs(file1, file2, recursive)
        
        list_print(deleted[0], 'FILE:', 'deleted')
        list_print(deleted[1], 'DIRECTORY:', 'deleted')
        list_print(added[0], 'FILE:', 'added')
        list_print(added[1], 'DIRECTORY:', 'added')
        exit_status += len(deleted[0])+len(deleted[1])+len(added[0])+len(added[1])
        for file in common[0]:
            print '-'*80
            print 'FILE:', file
            diffs = process_files(os.path.join(file1, file), os.path.join(file2, file),
                                  norm_sp, xupd, ezs, verbose,
                                  ext_ges, ext_pes, include_comment, encoding, html)
            if diffs:
                exit_status += diffs
    # if  args are files
    elif os.path.isfile(file1) and os.path.isfile(file2):
        if prof:
            import profile, pstats, time
            t = time.clock()
            profile.run('process_files(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'% (
              repr(file1), repr(file2), repr(norm_sp), repr(xupd),
              repr(ezs), repr(verbose), repr(ext_ges), repr(ext_pes),
              repr(include_comment),repr(encoding), repr(html)),
                        prof)
            print 'Time:',`time.clock()-t`
            p = pstats.Stats(prof)
            p.sort_stats('time','calls').print_stats(.25)
            p.sort_stats('cum','calls').print_stats(.25)
            
        else:
            exit_status = process_files(file1, file2, norm_sp, xupd, ezs, verbose,
                                        ext_ges, ext_pes, include_comment, encoding, html)
    else:
        print file1, 'and', file2,\
              'are not comparable, or not directory nor regular files'
    sys.exit(exit_status)
Beispiel #2
0
if __name__ == '__main__':
    from xml.dom.ext import StripXml, PrettyPrint
    from xml.dom.ext.reader.Sax2 import Reader
    import sys
    reader = Reader()
    file = open(sys.argv[1],'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree = tree_from_dom(d)
    file = open(sys.argv[2],'r')
    fragment = reader.fromStream(file)
    d = StripXml(fragment)
    file.close()
    tree2 = tree_from_dom(d)
    from objects import repr
    print 'Source tree', repr(tree)
    print 'Destination tree', repr(tree2)
    #from ezs import EzsCorrector
    #strategy = EzsCorrector()
    from fmes import FmesCorrector
    strategy = FmesCorrector(0.59, 0.5)
    #from ezs import process
    actions = strategy.process_trees(tree, tree2)
    from format import xupdate_dom
    PrettyPrint(
        xupdate_dom(
        reader.fromString('<root/>'),
        actions))
Beispiel #3
0
        sys.exit(-1)
    # convert xml files to tree
    try:
        from input import tree_from_stream
        tree1 = tree_from_stream(fh1, norm_sp, ext_ges, ext_pes, include_comment,
                                 encoding, html)
        tree2 = tree_from_stream(fh2, norm_sp, ext_ges, ext_pes, include_comment,
                                 encoding, html)
        fh1.close (); fh2.close ()
    except SAXParseException, msg:
        print msg
        return

    if verbose:
        from objects import repr, N_ISSUE, N_CHILDS
        print "Source tree\n", repr(tree1)
        print "Destination tree\n", repr(tree2)
        print 'Source tree has', tree1[N_ISSUE], 'nodes'
        print 'Destination tree has', tree2[N_ISSUE], 'nodes'
    # output formatter
    if xupd:
        from format import XUpdatePrinter
        formatter = XUpdatePrinter()
    else:
        from format import InternalPrinter
        formatter = InternalPrinter()
    # choose and apply tree to tree algorithm
    if ezs:
        from ezs import EzsCorrector
        strategy = EzsCorrector(formatter)
    else: