[hg] galaxy 3501: Add a helper script that will re.escape files; ...
details: http://www.bx.psu.edu/hg/galaxy/rev/e4592fc99acc changeset: 3501:e4592fc99acc user: Dan Blankenberg <dan@bx.psu.edu> date: Tue Mar 09 15:25:23 2010 -0500 description: Add a helper script that will re.escape files; useful for creating files valid for re_match and re_match_multiline comparisons in tool tests. diffstat: scripts/tools/re_escape_output.py | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diffs (38 lines): diff -r c67b5628f348 -r e4592fc99acc scripts/tools/re_escape_output.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/tools/re_escape_output.py Tue Mar 09 15:25:23 2010 -0500 @@ -0,0 +1,34 @@ +#! /usr/bin/python + +""" +Escapes a file into a form suitable for use with tool tests using re_match or re_match_multiline (when -m/--multiline option is used) + +usage: re_escape_output.py [options] input_file [output_file] + -m: Use Multiline Matching +""" + +import optparse, re + +def __main__(): + #Parse Command Line + parser = optparse.OptionParser() + parser.add_option( "-m", "--multiline", action="store_true", dest="multiline", default=False, help="Use Multiline Matching") + ( options, args ) = parser.parse_args() + input = open( args[0] ,'rb' ) + if len( args ) > 1: + output = open( args[1], 'wb' ) + else: + if options.multiline: + suffix = 're_match_multiline' + else: + suffix = 're_match' + output = open( "%s.%s" % ( args[0], suffix ), 'wb' ) + if options.multiline: + lines = [ re.escape( input.read() ) ] + else: + lines = [ "%s\n" % re.escape( line.rstrip( '\n\r' ) ) for line in input ] + output.writelines( lines ) + output.close() + +if __name__ == "__main__": + __main__()
participants (1)
-
Greg Von Kuster