diff --git a/appendall.py b/appendall.py index 293abfe..b694778 100755 --- a/appendall.py +++ b/appendall.py @@ -3,11 +3,11 @@ # Copyright (c) 2014 TundraWare Inc., Des Plaines, IL 60018 USA # All Rights Reserved. For Terms Of Use See: appendall-license.txt # For Program Updates See: http://www.tundraware.com/Software/appendall -# $Id: appendall.py,v 1.100 2014/11/21 20:30:27 tundra Exp $ +# $Id: appendall.py,v 1.101 2014/11/21 21:00:53 tundra Exp $ # Embed the source control ID string for use by program -CVSID='$Id: appendall.py,v 1.100 2014/11/21 20:30:27 tundra Exp $' +CVSID='$Id: appendall.py,v 1.101 2014/11/21 21:00:53 tundra Exp $' ##### # Program Information @@ -29,7 +29,7 @@ # List Of All Legal Options - Update This When You Add More!!!! ##### -OPTIONSLIST = '-f:hv' +OPTIONSLIST = '-hv' #----------------------------------------------------------# @@ -48,7 +48,6 @@ import getopt import os import sys -# import tconfpy # Uncomment this and code below to parse config files #----------------------------------------------------------# @@ -73,6 +72,7 @@ # Literals ##### +COMMENT = '#' #----------------------------------------------------------# @@ -94,6 +94,7 @@ eBADARG = "Invalid command line: %s!" eERROR = "ERROR" +eNOTEXT = "Missing Text To Append!" ##### @@ -116,7 +117,6 @@ uTable = [PROGVER, "usage: " + PROGNAME + " [%s]" % optionslist, " where,", - " -f file Configuration file to use", " -h Print this help information", " -v Print detailed version information", ] @@ -143,47 +143,6 @@ #----------------------------------------------------------# -def ColumnPad(list, padchar=" ", padwidth=20): - - retval = "" - for l in list: - l = str(l) - retval += l + ((padwidth - len(l)) * padchar) - - return retval.strip() - -# End of 'ColumnPad()' - - -##### -# Print A Debug Message -##### - -def DebugMsg(msg): - PrintStderr(PROGNAME + " " + dDEBUG + ": " + msg) - -# End of 'DebugMsg()' - - -##### -# Dump The State Of The Program -##### - -def DumpState(): - - # Dump the command line - DebugMsg(ColumnPad(["Command Line", sys.argv])) - - # Names of all the state variables we want dumped - state = [ - ] - - for k in state: - DebugMsg(ColumnPad([k, eval(k)])) - -# End of 'DumpState()' - - ##### # Print An Error Message ##### @@ -195,16 +154,6 @@ ##### -# Print An Info Message -##### - -def InfoMsg(imsg): - PrintStderr(PROGNAME + " " + iINFO + ": " + imsg) - -# End of 'InfoMsg()' - - -##### # Print To stderr ##### @@ -257,9 +206,6 @@ for opt, val in opts: - if opt == "-f": - CFGFILE=val - if opt == "-h": Usage() sys.exit(0) @@ -268,22 +214,35 @@ PrintStdout(CVSID) sys.exit(0) -# Processing of the configuration file below requires installation of -# the freely available TundraWare Inc. 'tconfpy' parser and then -# uncommenting the code below. The parser can be found at: -# -# http://www.tundraware.com/Software/tconfpy -# -# Process the configuration file -# -#retval = tconfpy.ParseConfig(CFGFILE, CallingProgram="%s %s " % (PROGNAME, VERSION)) -# -# Print any errors or warning generated by the parse -# -# for x in (retval.ErrMsgs, retval.WarnMsgs): -# for y in x: -# print y -# -# If there were any errors, we're done -#if retval.ErrMsgs: -# sys.exit(0) + +# Get text to append + +try: + text = sys.argv[1] + +except: + ErrorMsg(eNOTEXT) + sys.exit(1) + + +for line in sys.stdin.readlines(): + + # Get rid of linefeeds - we'll add them back later + + if line[-1] == "\n": + line = line[:-1] + + # Ignore comments text, and blank lines + + if line.split(COMMENT)[0].strip(): + + parts = line.split(COMMENT) + if len(parts) == 1: + line = parts[0] + text + + else: + line = parts[0] + text + COMMENT + parts[1] + + + PrintStdout(line) +