From dc7a4bb9784e0b3ef48b5b0fb406d28ddeed6231 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 16 Oct 2014 14:56:44 +0000 Subject: [PATCH] using damasks extentable option + correct version string --- processing/post/showTable.py | 9 +++++---- processing/post/sortTable.py | 39 +++++++++--------------------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/processing/post/showTable.py b/processing/post/showTable.py index 63bf63adf..8a9d77b3c 100755 --- a/processing/post/showTable.py +++ b/processing/post/showTable.py @@ -1,11 +1,12 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,sys,string,damask +import os,sys,string from optparse import OptionParser +import damask scriptID = '$Id$' -scriptName = scriptID.split()[1] +scriptName = scriptID.split()[1][:-3] # -------------------------------------------------------------------- # MAIN @@ -13,8 +14,8 @@ scriptName = scriptID.split()[1] parser = OptionParser(usage='%prog [options] [file[s]]', description = """ Show components of given ASCIItable(s). -""" + string.replace(scriptID,'\n','\\n') -) + +""", version = scriptID) parser.add_option('-a','--head', dest='head', action='store_true', help='output all heading (info + labels)') diff --git a/processing/post/sortTable.py b/processing/post/sortTable.py index 3f2762e2f..9f0952e2f 100755 --- a/processing/post/sortTable.py +++ b/processing/post/sortTable.py @@ -1,46 +1,27 @@ #!/usr/bin/env python # -*- coding: UTF-8 no BOM -*- -import os,re,sys,string,numpy,damask -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) - +import os,re,sys,string +import numpy as np +from optparse import OptionParser +import damask +scriptID = string.replace('$Id$','\n','\\n') +scriptName = scriptID.split()[1][:-3] # -------------------------------------------------------------------- # MAIN # -------------------------------------------------------------------- -parser = OptionParser(option_class=extendableOption, usage='%prog options [file[s]]', description = """ +parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """ Sort rows by given column label(s). Examples: With coordinates in columns "x", "y", and "z"; sorting with x slowest and z fastest varying index: --label x,y,z. -""" + string.replace(scriptID,'\n','\\n') -) +""", version = scriptID) -parser.add_option('-l','--label', dest='keys', action='extend', metavar='', +parser.add_option('-l','--label', dest='keys', action='extend', metavar='', help='list of column labels (a,b,c,...)') parser.add_option('-r','--reverse', dest='reverse', action='store_true', help='reverse sorting') @@ -87,7 +68,7 @@ for file in files: for column in table.labels_index(options.keys): cols += [table.data[:,column]] - ind = numpy.lexsort(cols) + ind = np.lexsort(cols) if options.reverse: ind = ind[::-1]