diff --git a/processing/post/permuteData.py b/processing/post/permuteData.py new file mode 100755 index 000000000..95b0b1926 --- /dev/null +++ b/processing/post/permuteData.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python + +import os,re,sys,math,numpy,string +import damask +from collections import defaultdict +from optparse import OptionParser, Option + +scriptID = '$Id$' +scriptName = scriptID.split()[1] + +# ----------------------------- +class extendableOption(Option): +# ----------------------------- +# used for definition of new option parser action 'extend', which enables to take multiple option arguments +# taken from online tutorial http://docs.python.org/library/optparse.html + + ACTIONS = Option.ACTIONS + ("extend",) + STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",) + TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",) + ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",) + + def take_action(self, action, dest, opt, value, values, parser): + if action == "extend": + lvalue = value.split(",") + values.ensure_value(dest, []).extend(lvalue) + else: + Option.take_action(self, action, dest, opt, value, values, parser) + + +# -------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------- + +parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ +Permute all values in given column(s). + +""" + string.replace(scriptID,'\n','\\n') +) + +parser.add_option('-l','--label', dest='label', action='extend', type='string', + help='heading(s) of column to permute', + metavar='