Table of Contents
Utility for generating run files.
Defines a file object with an additional 'add()' method.
A RunFile object is basically a file object with an additional add() method defined on it. This add() function has side-effects designed to make it easier to compose a RunFile than with the conventional File methods.
For example, assuming you have varX with X equal to 1 through 7 already defined,
If we opened "run202.bas" it would contain the contents added via the add() method.
In order to display a "%" character use two characters in a row as in,
This will display a single "%" character within the runfile.
Note
The RunFile inherits from the built-in file object, and as such behaves just like a file.
- add(formatstr, *args)
Writes to file, appends n, and converts all args to strings.
- Arguments:
- formatstr : string
- Your standard c-style format string, embedded with %s's since all args will be converted to strings
- *args : variable-argument list
- A N-long list of arguments matching the number of %s's located in the format string; each argument will be converted to a string (if its not a string already).
Note
There are some side-effects associated with this function call. These side-effects are intended and are,
- appends a n to the end of the format string for each call to add()
- converts all args to strings (and strings remain strings), thus you don't have to worry about integers and all that
- additm(index, formatstr, *args)
Writes to file if and only if the index value is not in the OMMISION_LIST.
It writes to a file if the index variable is defined, and also increments an ITM[n] variable. If the specified index is 0, then validation is ignored, and the line is written regardless of the contents.
This essentially mimics the old med-style ITM#[n] runfile composition command.
For example,
a = 1
b = ""
c = 10
d = 20
runfile = runfile.Open("myrunfile.a", "wt")
runfile.additm(2, " %s %s", a, b)
runfile.additm(0, " %s", c) # added regardless of c's value.
runfile.additm(1, " %s", d)
runfile.close()Would result in a runfile that looked like this,
ITM1 10
ITM2 20Because the first additm() called had the 2nd value, b, containing a blank string, which exists in the runfile.OMMISION_LIST.
- Arguments:
- index : integer
- Index you want to make sure exists, or 0 if you don't care. The index is not zero based.
- formatstr : string
- Same as add() attribute.
- *args : variable-argument list
- Same as add() attribute.
Note
The are some side-effects associated with this function call, and they are
- Increments internal item count by one if a write is performed.
- Other side-effects similar to the add() method.
- addtmp(index, formatstr, *args)
Functions like additm, except doesn't write out an "ITM[n]" string.
Essentially the same validation behavior as the additm() function. Except, a ITM[n] string is not written out the runfile.
- Arguments:
- index : integer
- Index into the args that you want to validate. The index is *not zero based.
- formatstr : string
- Same as add() attribute.
- *args : variable-argument list
- Same as add() attribute.
- setoutputhook(hookfn)
Set a function to dump strings to prior to dumping to the file.
Useful for debugging runfile creations, this lets you basically stream the format strings to both the file and to some other stream (say sys.stdout).
For example, say you want to stream the strings printed to the file also to the console, you would do the following,
rf = runfile.openrunfile("myfile.a", "wt")
rf.setoutputhook(sys.stdout.write)Presto, now all the strings sent to myfile.a will also be sent to the console.
- Arguments:
- hookfn : function
- A function that accepts strings; or None if you want to disable the hook.
Constructs a RunFile object.
Provides a simple means for opening a runfile object for writing.
Warning
DEPRECATED (as of MineSight® Grail v1.1)
Prefer to use the openrunfile() function instead.
[1] | "Built-in Functions" Python Library Reference. 21 December 2001. 14 May 2004. <http://www.python.org/doc/2.2/lib/built-in-funcs.html> |