using damasks extentable option + correct version string

This commit is contained in:
Martin Diehl 2014-10-16 14:56:44 +00:00
parent ff0f619015
commit dc7a4bb978
2 changed files with 15 additions and 33 deletions

View File

@ -1,11 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,sys,string,damask import os,sys,string
from optparse import OptionParser from optparse import OptionParser
import damask
scriptID = '$Id$' scriptID = '$Id$'
scriptName = scriptID.split()[1] scriptName = scriptID.split()[1][:-3]
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# MAIN # MAIN
@ -13,8 +14,8 @@ scriptName = scriptID.split()[1]
parser = OptionParser(usage='%prog [options] [file[s]]', description = """ parser = OptionParser(usage='%prog [options] [file[s]]', description = """
Show components of given ASCIItable(s). 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)') parser.add_option('-a','--head', dest='head', action='store_true', help='output all heading (info + labels)')

View File

@ -1,46 +1,27 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 no BOM -*- # -*- coding: UTF-8 no BOM -*-
import os,re,sys,string,numpy,damask import os,re,sys,string
from optparse import OptionParser, Option import numpy as np
from optparse import OptionParser
scriptID = '$Id$' import damask
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)
scriptID = string.replace('$Id$','\n','\\n')
scriptName = scriptID.split()[1][:-3]
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# MAIN # 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). Sort rows by given column label(s).
Examples: Examples:
With coordinates in columns "x", "y", and "z"; sorting with x slowest and z fastest varying index: --label x,y,z. 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='<LIST>', parser.add_option('-l','--label', dest='keys', action='extend', metavar='<string LIST>',
help='list of column labels (a,b,c,...)') help='list of column labels (a,b,c,...)')
parser.add_option('-r','--reverse', dest='reverse', action='store_true', parser.add_option('-r','--reverse', dest='reverse', action='store_true',
help='reverse sorting') help='reverse sorting')
@ -87,7 +68,7 @@ for file in files:
for column in table.labels_index(options.keys): for column in table.labels_index(options.keys):
cols += [table.data[:,column]] cols += [table.data[:,column]]
ind = numpy.lexsort(cols) ind = np.lexsort(cols)
if options.reverse: if options.reverse:
ind = ind[::-1] ind = ind[::-1]