root/galaxy-central/scripts/tools/re_escape_output.py @ 2

リビジョン 2, 1.0 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
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__()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。