updated $Id$ handling.

added (colored) my script's name reporting.
This commit is contained in:
Philip Eisenlohr 2013-09-09 14:12:00 +00:00
parent ec6587e7f5
commit 538a471246
2 changed files with 17 additions and 8 deletions

View File

@ -3,6 +3,9 @@
import os,re,sys,fnmatch,math,string,damask import os,re,sys,fnmatch,math,string,damask
from optparse import OptionParser, Option from optparse import OptionParser, Option
scriptID = '$Id$'
scriptName = scriptID.split()[1]
# ----------------------------- # -----------------------------
class extendableOption(Option): class extendableOption(Option):
# ----------------------------- # -----------------------------
@ -33,7 +36,7 @@ Filter rows according to condition and columns by either white or black listing.
Examples: Examples:
Every odd row if x coordinate is positive -- " #ip.x# >= 0.0 and #_row_#%2 == 1 ). Every odd row if x coordinate is positive -- " #ip.x# >= 0.0 and #_row_#%2 == 1 ).
All rows where label 'foo' equals 'bar' -- " #s#foo# == \"bar\" " All rows where label 'foo' equals 'bar' -- " #s#foo# == \"bar\" "
""" + string.replace('$Id$','\n','\\n') """ + string.replace(scriptID,'\n','\\n')
) )
@ -55,16 +58,17 @@ parser.set_defaults(condition = '')
files = [] files = []
if filenames == []: if filenames == []:
files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout}) files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr})
else: else:
for name in filenames: for name in filenames:
if os.path.exists(name): if os.path.exists(name):
files.append({'name':name, 'input':open(name), 'output':open(name+'_tmp','w')}) files.append({'name':name, 'input':open(name), 'output':open(name+'_tmp','w'), 'croak':sys.stderr})
# ------------------------------------------ loop over input files --------------------------------------- # ------------------------------------------ loop over input files ---------------------------------------
for file in files: for file in files:
if file['name'] != 'STDIN': print file['name'] if file['name'] != 'STDIN': file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
specials = { \ specials = { \
'_row_': 0, '_row_': 0,
@ -72,7 +76,7 @@ for file in files:
table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table
table.head_read() # read ASCII header info table.head_read() # read ASCII header info
table.info_append(string.replace('$Id$','\n','\\n') + \ table.info_append(string.replace(scriptID,'\n','\\n') + \
'\t' + ' '.join(sys.argv[1:])) '\t' + ' '.join(sys.argv[1:]))
labels = [] labels = []

View File

@ -3,6 +3,8 @@
import os,sys,string,damask import os,sys,string,damask
from optparse import OptionParser from optparse import OptionParser
scriptID = '$Id$'
scriptName = scriptID.split()[1]
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# MAIN # MAIN
@ -10,7 +12,7 @@ from optparse import OptionParser
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('$Id$','\n','\\n') """ + string.replace(scriptID,'\n','\\n')
) )
@ -30,15 +32,18 @@ parser.set_defaults(nolabels = False)
files = [] files = []
if filenames == []: if filenames == []:
files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout}) files.append({'name':'STDIN', 'input':sys.stdin, 'output':sys.stdout, 'croak':sys.stderr})
else: else:
for name in filenames: for name in filenames:
if os.path.exists(name): if os.path.exists(name):
files.append({'name':name, 'input':open(name), 'output':sys.stdout}) files.append({'name':name, 'input':open(name), 'output':sys.stdout, 'croak':sys.stderr})
# ------------------------------------------ extract labels --------------------------------------- # ------------------------------------------ extract labels ---------------------------------------
for file in files: for file in files:
if file['name'] != 'STDIN': file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels) # make unbuffered ASCII_table table = damask.ASCIItable(file['input'],file['output'],buffered=False,labels=not options.nolabels) # make unbuffered ASCII_table
table.head_read() # read ASCII header info table.head_read() # read ASCII header info
if options.head or options.info: file['output'].write('\n'.join(table.info)+'\n') if options.head or options.info: file['output'].write('\n'.join(table.info)+'\n')