diff --git a/twander.py b/twander.py index ce7b2a1..d40e0bf 100755 --- a/twander.py +++ b/twander.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "twander" -RCSID = "$Id: twander.py,v 3.165 2005/01/24 11:55:28 tundra Exp $" +RCSID = "$Id: twander.py,v 3.166 2005/01/24 20:33:19 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -22,6 +22,7 @@ # Imports # #----------------------------------------------------------# +from commands import getstatusoutput import getopt import mutex import os @@ -316,6 +317,7 @@ REFRESHAFTER = '+' # Indicate we want a refresh after a command runs SHOWDRIVES = '\\\\' # Logical directory name for Win32 Drive Lists STRICTMATCH = CMDESCAPE # Tells wildcard system to enforce strict matching +STRIPNL = '-' # Tells variable execution to replace newlines with spaces TTLMAXDIR = 60 # Maximum length of current directory path to show in titlebar TTLDIR2LONG = "..." # String to place at front of long dir paths in titlebar @@ -558,6 +560,7 @@ COMMENT = r"#" # Comment introducer string ENVVBL = r'$' # Symbol denoting an environment variable FAKEFIELD = r'#FAKEFIELD' # Unsplittable field used to preserve PROMPT/YESNO content +VAREXECUTE = r'`' # Indicate we want content of variable name to be executed # Names Of Conditionals, Directives, And Pre-Defined Symbols @@ -732,6 +735,7 @@ wBADRHS = "Ignoring Line %s.\nOption Assignment Has Bad Righthand Side:\n\n%s" wBADSCNUM = "Ignoring Line %s.\nShortcut Number Must Be From 1-12:\n\n%s" wBADSORTFLD = "Don't Know How To Sort By: %s\n\nWill Sort By %s Instead." +wBADVAREXEC = "Ignoring Line %s.\nExecution Of Variable %s Failed:\n\n%s" wBADYESNODFLT = "Bad Default Argument For Yes/No Prompt: '%s'\nCommand '%s' Aborted" wCONFOPEN = "Cannot Open Configuration File:\n%s" wEXTRAENDIF = "Ignoring Line %s!\nNo Conditional Block To End:\n\n%s" @@ -4264,6 +4268,42 @@ WrnMsg(wBADENVVBL % (num, x, line)) return "" + # Process variable execution + + elif vbl[0] == vbl[-1] == VAREXECUTE: + + # Strip indicators + + vbl = vbl[1:-1] + + # Find out if user wants newlines stripped + + stripnl = False + if vbl[0] == STRIPNL: + stripnl = True + vbl = vbl[1:] + + results = getstatusoutput(vbl) + + # Replace with results if there was no error + + if not results[0]: + + result = results[1] + + # Strip newlines if asked to + if stripnl: + result = result.replace('\n', ' ') + + # Place results into command string + + cmd = cmd.replace(x, result) + + # If there was an error, warn user, and terminate further processing + else: + WrnMsg(wBADVAREXEC % (num, x, line)) + return "" + # Process references to undefined variables else: WrnMsg(wUNDEFVBL % (num, x, line))