RCS file: RCS/tconfpy.py,v Working file: tconfpy.py head: 2.112 branch: locks: strict access list: symbolic names: keyword substitution: kv total revisions: 103; selected revisions: 103 description: tconfpy - A Configuration File Parser For Python Applications ---------------------------- revision 2.112 date: 2005/01/20 08:44:40; author: tundra; state: Exp; lines: +3 -3 References to "recursive" changed to "circular". ---------------------------- revision 2.111 date: 2005/01/20 00:31:24; author: tundra; state: Exp; lines: +33 -5 Added logic to prevent recursive includes. Added SymbolTable.Visited to track and return files processed. ---------------------------- revision 2.110 date: 2005/01/19 23:39:29; author: tundra; state: Exp; lines: +13 -5 Added logic to check each entry in an in-memory parse to make sure it is a string. ---------------------------- revision 2.109 date: 2005/01/19 23:24:19; author: tundra; state: Exp; lines: +8 -13 Changed to return TotalLines along with the other stuff. Cleaned up line counting in both file and in-memory parse frontends. ---------------------------- revision 2.108 date: 2005/01/19 23:03:25; author: tundra; state: Exp; lines: +15 -9 Switched to copy.copy for initializing passed symbol and template tables. Cleaned up returned symbol table to only pass back the documented stuff. ---------------------------- revision 2.107 date: 2005/01/19 11:08:24; author: tundra; state: Exp; lines: +120 -81 Broke out symbol table validation feature into ValidateSymbolTable(). Both passed symbol and template tables are now checked for validity. Initial value for each passed symbol is checked for valid type. Template names are checked to make sure they do not contain namespace separators. ---------------------------- revision 2.106 date: 2005/01/19 10:03:33; author: tundra; state: Exp; lines: +7 -10 Fixed bug wherein templates were not properly being identified within namespaces. ---------------------------- revision 2.105 date: 2005/01/17 22:27:21; author: tundra; state: Exp; lines: +3 -3 Minor formatting change for PROGINFO and mkmsg.proginfo. ---------------------------- revision 2.104 date: 2005/01/14 09:54:16; author: tundra; state: Exp; lines: +29 -15 Implemented ability to use boolean state within existential tests. ---------------------------- revision 2.103 date: 2005/01/14 08:30:49; author: tundra; state: Exp; lines: +2 -2 Use textual copyright symbol so it renders properly on different platforms. ---------------------------- revision 2.102 date: 2005/01/14 08:15:52; author: tundra; state: Exp; lines: +47 -7 Implemented support for in-memory parsing of configurations stored in a list. ---------------------------- revision 2.101 date: 2005/01/13 23:03:24; author: tundra; state: Exp; lines: +3 -10 Minor editorial cleanups, removal of unused variables. ---------------------------- revision 2.100 date: 2005/01/13 22:55:58; author: tundra; state: Exp; lines: +6 -1 Branched to the 2.x release because the API is no longer backward compatible. Changed template semantics so that 'templatevar=' causes the variable to be instantiated with its default value. ---------------------------- revision 1.188 date: 2005/01/13 22:08:37; author: tundra; state: Exp; lines: +46 -39 Further cleanup of SymbolTable instance variables. Made 'Template' a first-class object in its own right. ---------------------------- revision 1.187 date: 2005/01/13 20:45:50; author: tundra; state: Exp; lines: +125 -164 Converted Symbol Table to a first-class object in its own right. ---------------------------- revision 1.186 date: 2005/01/13 10:36:24; author: tundra; state: Exp; lines: +10 -4 Added ability to pass name of calling program to the API via the 'CallingProgram' keyword parameter. This allows the calling program to change the default program ID string used in messages produced during the parse. ---------------------------- revision 1.185 date: 2004/05/02 08:06:07; author: tundra; state: Exp; lines: +32 -14 BUGFIX: The content of literal blocks inside a False conditional block was being reported as a syntax error. ---------------------------- revision 1.184 date: 2004/04/27 23:53:35; author: tundra; state: Exp; lines: +2 -2 Fixed default value for TemplatesOnly. ---------------------------- revision 1.183 date: 2004/04/27 22:21:30; author: tundra; state: Exp; lines: +11 -1 Added ReturnPredefs API option. ---------------------------- revision 1.182 date: 2004/04/27 01:54:04; author: tundra; state: Exp; lines: +70 -16 Added variable templating feature. ---------------------------- revision 1.181 date: 2004/04/24 19:08:28; author: tundra; state: Exp; lines: +3 -3 Swapped .OSTYPE and .PLATFORM definitions. ---------------------------- revision 1.180 date: 2004/04/17 19:09:53; author: tundra; state: Exp; lines: +2 -1 Added .OSTYPE to predefined system variables. ---------------------------- revision 1.179 date: 2004/04/17 01:02:04; author: tundra; state: Exp; lines: +32 -3 Added code to properly condition variable references within existential conditional statements. ---------------------------- revision 1.178 date: 2004/04/16 23:59:45; author: tundra; state: Exp; lines: +32 -34 Rewrote the existential conditional code so that variable names and references are treated consistently with the rest of the program. ---------------------------- revision 1.177 date: 2004/04/16 20:23:22; author: tundra; state: Exp; lines: +10 -10 Changed order of formal parameters in API so debug is last. Slight change to format and content of several error messages. ---------------------------- revision 1.176 date: 2004/04/16 05:48:53; author: tundra; state: Exp; lines: +179 -185 Restructured and simplified NAMESPACE code considerably. Changed NAMESPACE semantics to match that of other variables wrt LegalVals. Ensured that "" is always legal for NAMESPACE. Got rid of the AllowNewNamespaces option. ---------------------------- revision 1.175 date: 2004/04/14 23:33:12; author: tundra; state: Exp; lines: +6 -5 Created symbolic value PERIOD. Changed predefined NSSEP to PERIOD. ---------------------------- revision 1.174 date: 2004/04/14 22:46:24; author: tundra; state: Exp; lines: +11 -6 Added startup check to make sure initially passed namespace is legit. ---------------------------- revision 1.173 date: 2004/04/14 22:18:39; author: tundra; state: Exp; lines: +9 -24 Fixed bug that prevented environment variables from being derefenced. Removed unnecessary validation checks in variable assignment code. ---------------------------- revision 1.172 date: 2004/04/14 21:23:35; author: tundra; state: Exp; lines: +4 -3 Insured that [NAMESPACE] always relative to root namespace. ---------------------------- revision 1.171 date: 2004/04/14 20:53:25; author: tundra; state: Exp; lines: +90 -51 Reorganized code to use a common symbol name validation routine. Wrote logic to explicitly check for illegal first character in symbol names. Wrote logic to check symbol names for illegal characters throughout. ---------------------------- revision 1.170 date: 2004/04/14 02:26:08; author: tundra; state: Exp; lines: +44 -42 Combined reserved and predfined symbols into a single data dictionary. ---------------------------- revision 1.169 date: 2004/04/13 23:06:01; author: tundra; state: Exp; lines: +41 -29 Implemented check to prevent namespaces with leading ENVIRO character. ---------------------------- revision 1.168 date: 2004/04/13 21:40:07; author: tundra; state: Exp; lines: +52 -22 Fixed a number of subtle bugs involving namespace handling for variable names and references. ---------------------------- revision 1.167 date: 2004/04/08 22:56:37; author: tundra; state: Exp; lines: +7 -1 Added check to make sure a variable name does not contain DELIML or DELIMR. ---------------------------- revision 1.166 date: 2004/04/08 22:46:52; author: tundra; state: Exp; lines: +39 -17 Cleaned up all manner of bugs having to do with variable names containing whitespace and references involving them. Added explicit check for nested variable references. ---------------------------- revision 1.165 date: 2004/04/08 17:11:09; author: tundra; state: Exp; lines: +4 -4 Changed API argument from InitialSymTbl to InitialSymTable. ---------------------------- revision 1.164 date: 2004/04/08 15:51:26; author: tundra; state: Exp; lines: +28 -6 Added code to verify that LegalVals is a list for each variable passed in the initial symbol table. Added to to insure that the initial namespace passed by the calling program is also present in the NAMESPACE LegalVals list. ---------------------------- revision 1.163 date: 2004/04/07 08:54:08; author: tundra; state: Exp; lines: +72 -46 Added support for AllowNewNamespaces option. Added debug output whenever a namespace is changed. ---------------------------- revision 1.162 date: 2004/04/07 00:10:37; author: tundra; state: Exp; lines: +16 -6 Added support for AllowNewVars API option. ---------------------------- revision 1.161 date: 2004/04/06 19:50:17; author: tundra; state: Exp; lines: +8 -6 Suppress attempts to name variables with leading $ or #. ---------------------------- revision 1.160 date: 2004/04/02 09:21:19; author: tundra; state: Exp; lines: +7 -1 Added code to prevent variable names beginning with DOLLAR. ---------------------------- revision 1.159 date: 2004/04/02 09:11:55; author: tundra; state: Exp; lines: +4 -4 Sorted error and warning messages in the source code. ---------------------------- revision 1.158 date: 2004/04/02 08:59:43; author: tundra; state: Exp; lines: +19 -15 Restrucured predefined symbols for ease of maintenance and to make use of the platform module. ---------------------------- revision 1.157 date: 2004/04/02 08:04:52; author: tundra; state: Exp; lines: +7 -2 Corrected return logic in the face of an API error to use the newer style return object. ---------------------------- revision 1.156 date: 2004/04/01 22:09:22; author: tundra; state: Exp; lines: +9 -3 Added predefined variable dump on direct invocation. ---------------------------- revision 1.155 date: 2004/04/01 21:13:00; author: tundra; state: Exp; lines: +23 -1 Implemented several pre-defined variables to reflect running system. ---------------------------- revision 1.154 date: 2004/04/01 20:38:03; author: tundra; state: Exp; lines: +34 -5 Changed return mechanics to use an object instead of a tuple of lists. Changed error message for errors found at EOF to reflect this location. ---------------------------- revision 1.153 date: 2004/03/31 22:40:02; author: tundra; state: Exp; lines: +28 -11 Moved direct invocation logic to end of file. Added a __all__ entry at the end of the file to explicitly name the public symbols. ---------------------------- revision 1.152 date: 2004/03/31 22:07:05; author: tundra; state: Exp; lines: +5 -5 Cleaned up the string too short/too long error messages. ---------------------------- revision 1.151 date: 2004/03/31 21:46:13; author: tundra; state: Exp; lines: +2 -2 Changed VarDescriptor base class to inherent from 'object'. This makes it possible to use the 'super' operation when subclassing from this base. ---------------------------- revision 1.150 date: 2004/03/31 21:40:42; author: tundra; state: Exp; lines: +52 -5 Changed the file open logic to only trap on an IO Error. Other errors fall through and cause a Python error exit. Necessary so that program errors are not caught and treated like a bad file open. Implemented the ELSE directive. ---------------------------- revision 1.149 date: 2004/03/27 01:24:34; author: tundra; state: Exp; lines: +13 -12 Retructured CondStack to prepare the way for ELSE directives. ---------------------------- revision 1.148 date: 2004/03/27 00:56:25; author: tundra; state: Exp; lines: +31 -7 Inhibited declaration/reference of null-named variable. Inhibited declaration/reference of variables with whitespace in their name. ---------------------------- revision 1.147 date: 2004/03/25 10:43:45; author: tundra; state: Exp; lines: +356 -331 Major code reorganization to fix problem with nested conditionals and prepare the way for the ELSE operator. Many other incidental bugs found and fixed. ---------------------------- revision 1.146 date: 2004/03/25 07:03:20; author: tundra; state: Exp; lines: +52 -10 Added Legal Values checking for all relevant types. ---------------------------- revision 1.145 date: 2004/03/25 06:21:11; author: tundra; state: Exp; lines: +11 -11 Cleaned up bugs in the bounds checking logic. ---------------------------- revision 1.144 date: 2004/03/25 05:34:58; author: tundra; state: Exp; lines: +51 -21 Further cleanup of API validation logic. ---------------------------- revision 1.143 date: 2004/03/25 04:42:50; author: tundra; state: Exp; lines: +16 -8 Added more detail to errors encountered while validating symbol table passed to API. ---------------------------- revision 1.142 date: 2004/03/25 01:29:17; author: tundra; state: Exp; lines: +24 -2 Added further sanity checking of any symbol table passed into the API. ---------------------------- revision 1.141 date: 2004/03/25 00:52:31; author: tundra; state: Exp; lines: +41 -5 Implemented Min/Max enforcement for ints/floats/strings. ---------------------------- revision 1.140 date: 2004/03/25 00:18:44; author: tundra; state: Exp; lines: +31 -6 Implemented type enforcement and recognition of legal boolean assignment strings. ---------------------------- revision 1.139 date: 2004/03/24 23:34:59; author: tundra; state: Exp; lines: +12 -8 Corrected code so that both NAMESPACE= and .NAMESPACE= work equivalently. ---------------------------- revision 1.138 date: 2004/03/24 23:11:42; author: tundra; state: Exp; lines: +15 -1 Further cleanup of NAMESPACE handling. Made all variable derefrencing relative to the current NAMESPACE context by default. ---------------------------- revision 1.137 date: 2004/03/24 22:32:53; author: tundra; state: Exp; lines: +7 -2 Added logic to suppress redefinition of reserved symbols. ---------------------------- revision 1.136 date: 2004/03/24 22:25:47; author: tundra; state: Exp; lines: +30 -17 Cleaned up NAMESPACE logic considerably. Modified variable deferencing code/regex to permit null-named variable []. ---------------------------- revision 1.135 date: 2004/03/24 11:09:07; author: tundra; state: Exp; lines: +45 -4 Added NAMESPACE capabilities. ---------------------------- revision 1.134 date: 2004/03/24 10:08:33; author: tundra; state: Exp; lines: +14 -3 Implemented semantics for new variables: The first value assigned to a new variable is set to be its default value. Also fixed a bug wherein existing values' descriptors were being overwritten with a new descriptor. ---------------------------- revision 1.133 date: 2004/03/24 09:56:05; author: tundra; state: Exp; lines: +15 -5 Added code to protect Read Only variables from being changed. ---------------------------- revision 1.132 date: 2004/03/24 09:33:44; author: tundra; state: Exp; lines: +22 -16 Added basic check of symbol table passed to API to confirm a valid variable descriptor object has been passed for each variable. ---------------------------- revision 1.131 date: 2004/03/24 08:47:55; author: tundra; state: Exp; lines: +26 -22 Extraneous text on IFALL/ANY/NONE lines now generates error and sets condition to False. This was done for semantic consistency with other directives. Fixed bug that was causing malformed ENDIF lines to not be reported as an error. ---------------------------- revision 1.130 date: 2004/03/22 17:56:10; author: tundra; state: Exp; lines: +16 -6 Corrected Literal line processing code to detect extra LITERAL and ENDLITERAL statements. Corrected semantics of Literal line processing so that these directives are ignored within False conditional blocks. ---------------------------- revision 1.129 date: 2004/03/21 14:25:20; author: tundra; state: Exp; lines: +2 -7 Changed ENDIF logic to be strict and require nothing else be on the line. This was done for consistencey with ENDLITERAL. ---------------------------- revision 1.128 date: 2004/03/21 14:10:52; author: tundra; state: Exp; lines: +8 -5 BUGFIX: Comments were not being passed in literal blocks. Reorganized relevant code. ---------------------------- revision 1.127 date: 2004/03/21 14:05:42; author: tundra; state: Exp; lines: +24 -24 Reorganize the code slightly to that blank lines would be passed during Literal line processing (rather than ignored as in all other cases). ---------------------------- revision 1.126 date: 2004/03/21 14:00:18; author: tundra; state: Exp; lines: +54 -14 Implement Literal line processing with- and without variable substitutions. ---------------------------- revision 1.125 date: 2004/03/21 13:07:50; author: tundra; state: Exp; lines: +18 -15 Added literals and API changes to support Literal line processing. Cleaned up table of legal boolean values. ---------------------------- revision 1.124 date: 2004/03/20 01:04:36; author: tundra; state: Exp; lines: +16 -2 Implemented logic for variable assignment. ---------------------------- revision 1.123 date: 2004/03/20 00:02:09; author: tundra; state: Exp; lines: +30 -40 Implemented variable descriptor as an object rather than a list for simplicity of use. Removed explicit __all__[]. ---------------------------- revision 1.122 date: 2004/03/19 22:41:17; author: tundra; state: Exp; lines: +45 -17 Cleaned up file open error reporting for consistent format with other error messages. Implemented IF EQUIV/NOTEQUIV conditional testing. ---------------------------- revision 1.121 date: 2004/03/19 11:03:33; author: tundra; state: Exp; lines: +15 -6 Added ability to use environment variable references throughout. ---------------------------- revision 1.120 date: 2004/03/19 10:16:16; author: tundra; state: Exp; lines: +81 -67 Cleaned up and simplified error detection and reporting. Added ability to use variable references in INCLUDE statements. Factored out state setting code so all conditionals share the same exit block. Finished skeleton of parser. Code stubs now exist for all legal statement forms and an error handler exists for all remaining illegal forms. ---------------------------- revision 1.119 date: 2004/03/16 10:35:47; author: tundra; state: Exp; lines: +95 -55 Restructured the error/warning/debug message reporting logic to report message type along with the detail. Generally cleaned up various message types. ---------------------------- revision 1.118 date: 2004/03/16 03:18:19; author: tundra; state: Exp; lines: +44 -21 Corrected logic to check for extraneous text on IFALL, IFANY, IFNONE lines. Added code to enforce a space after any conditional or directive token. ---------------------------- revision 1.117 date: 2004/03/15 00:19:56; author: tundra; state: Exp; lines: +95 -44 Changed existential conditionals to be IFALL, IFANY, IFNONE. Added code to force check for extraneous text on an existential conditional. ---------------------------- revision 1.116 date: 2004/03/14 21:03:36; author: tundra; state: Exp; lines: +2 -2 Changed debug statement regarding non-included lines clearer. ---------------------------- revision 1.115 date: 2004/03/14 20:59:08; author: tundra; state: Exp; lines: +34 -15 Cleaned up error messages. Reinstialled skeleton for NOTEQUIV processing. Broke out conditional introducer as explicit token. ---------------------------- revision 1.114 date: 2004/03/14 09:57:13; author: tundra; state: Exp; lines: +29 -24 Implemented .ifnot logic. Relaxed requirements so that .if/not only requires one or more [var] references. ---------------------------- revision 1.113 date: 2004/03/14 09:04:52; author: tundra; state: Exp; lines: +58 -25 Completed logic for existential conditional and final .endif counts. Modified variable deref logic to report reference attempts to undefined variables. ---------------------------- revision 1.112 date: 2004/03/14 04:43:53; author: tundra; state: Exp; lines: +36 -14 Expanded DerefVar() to properly replace all variable references. Put in basic support for .if [var] form. ---------------------------- revision 1.111 date: 2004/03/14 01:39:00; author: tundra; state: Exp; lines: +98 -21 Consolidated the builtins into the master symbol table. Defined indexing constants to manipulate a variable descriptor entry. ---------------------------- revision 1.110 date: 2004/03/13 00:19:04; author: tundra; state: Exp; lines: +16 -7 Changed line parser logic to provide debug indication that a line parsed to blank and was ignored. ---------------------------- revision 1.109 date: 2004/03/12 10:14:02; author: tundra; state: Exp; lines: +19 -13 Added Variable Reference regular expression and matching object. ---------------------------- revision 1.108 date: 2004/03/12 09:22:19; author: tundra; state: Exp; lines: +20 -13 Slight code reorganization and comment cleanup. ---------------------------- revision 1.107 date: 2004/03/12 09:10:02; author: tundra; state: Exp; lines: +16 -14 Improved formatting of error, warning, and debug messages. ---------------------------- revision 1.106 date: 2004/03/12 08:32:35; author: tundra; state: Exp; lines: +38 -7 Added parsing for .endif and .include directives. ---------------------------- revision 1.105 date: 2004/03/12 00:58:52; author: tundra; state: Exp; lines: +30 -34 Removed status from return API. Not needed - implied by contents of the Error Messages list. ---------------------------- revision 1.104 date: 2004/03/12 00:38:47; author: tundra; state: Exp; lines: +100 -41 Added support for embedding reserved words and symbols. Implemented .include logic. ---------------------------- revision 1.103 date: 2004/03/09 23:39:33; author: tundra; state: Exp; lines: +131 -67 Cleaned up API and return data structures. Added facility for line conditioning. Added Debug support. ---------------------------- revision 1.102 date: 2004/03/09 09:50:32; author: tundra; state: Exp; lines: +81 -7 Created skeleton for parser logic, API, and return logic. ---------------------------- revision 1.101 date: 2004/03/09 08:14:04; author: tundra; state: Exp; lines: +9 -9 Cleaned up formatted output. ---------------------------- revision 1.100 date: 2004/03/09 08:00:01; author: tundra; state: Exp; lines: +60 -29 Added formatted warning and error message output. ---------------------------- revision 1.0 date: 2003/12/13 01:00:28; author: tundra; state: Exp; Initial revision ---------------------------- =============================================================================