PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/tools/re_escape_output.py

https://bitbucket.org/h_morita_dbcls/galaxy-central
Python | 34 lines | 22 code | 4 blank | 8 comment | 6 complexity | 00a091e2d4462975e78bc0fb8b36dcda MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""
 4Escapes a file into a form suitable for use with tool tests using re_match or re_match_multiline (when -m/--multiline option is used)
 5
 6usage: re_escape_output.py [options] input_file [output_file]
 7    -m: Use Multiline Matching
 8"""
 9
10import optparse, re
11
12def __main__():
13    #Parse Command Line
14    parser = optparse.OptionParser()
15    parser.add_option( "-m", "--multiline", action="store_true", dest="multiline", default=False, help="Use Multiline Matching")
16    ( options, args ) = parser.parse_args()
17    input = open( args[0] ,'rb' )
18    if len( args ) > 1:
19        output = open( args[1], 'wb' )
20    else:
21        if options.multiline:
22            suffix = 're_match_multiline'
23        else:
24            suffix = 're_match'
25        output = open( "%s.%s" % ( args[0], suffix ), 'wb' )
26    if options.multiline:
27        lines = [ re.escape( input.read() ) ]
28    else:
29        lines = [ "%s\n" % re.escape( line.rstrip( '\n\r' ) ) for line in input ]
30    output.writelines( lines )
31    output.close()
32
33if __name__ == "__main__":
34    __main__()