From 538a471246c9eaaa3163cb86cc74a5c0c190326e Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 9 Sep 2013 14:12:00 +0000 Subject: [PATCH] updated $Id$ handling. added (colored) my script's name reporting. --- processing/post/filterTable.py | 14 +++++++++----- processing/post/showTable.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/processing/post/filterTable.py b/processing/post/filterTable.py index b1f85ec2d..e905831fc 100755 --- a/processing/post/filterTable.py +++ b/processing/post/filterTable.py @@ -3,6 +3,9 @@ import os,re,sys,fnmatch,math,string,damask from optparse import OptionParser, Option +scriptID = '$Id$' +scriptName = scriptID.split()[1] + # ----------------------------- class extendableOption(Option): # ----------------------------- @@ -33,7 +36,7 @@ Filter rows according to condition and columns by either white or black listing. Examples: 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\" " -""" + string.replace('$Id$','\n','\\n') +""" + string.replace(scriptID,'\n','\\n') ) @@ -55,16 +58,17 @@ parser.set_defaults(condition = '') files = [] 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: for name in filenames: 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 --------------------------------------- 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 = { \ '_row_': 0, @@ -72,7 +76,7 @@ for file in files: table = damask.ASCIItable(file['input'],file['output'],False) # make unbuffered ASCII_table 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:])) labels = [] diff --git a/processing/post/showTable.py b/processing/post/showTable.py index 588594af5..95a7e70a9 100755 --- a/processing/post/showTable.py +++ b/processing/post/showTable.py @@ -3,6 +3,8 @@ import os,sys,string,damask from optparse import OptionParser +scriptID = '$Id$' +scriptName = scriptID.split()[1] # -------------------------------------------------------------------- # MAIN @@ -10,7 +12,7 @@ from optparse import OptionParser parser = OptionParser(usage='%prog [options] [file[s]]', description = """ 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 = [] 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: for name in filenames: 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 --------------------------------------- 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.head_read() # read ASCII header info if options.head or options.info: file['output'].write('\n'.join(table.info)+'\n')