| |
- Argument
- Birchmod
- HTMLWriter
- Htmlutils
- SimpleXML
class Argument |
|
The purpose of this class is to provide a simplified and common way
for all scripts retrieve arguments from the command line parameters provided (sys.argv)
This is done by declaring an Argument variable, and specifying any advanced attributes
with the various augmentation methods provided.
BUG: Argument will split up a quoted command line argument containing blanks into individual
tokens. Eg. 'this should be a single argument'.
DEPRECATED in favor of optparse. Even optparse is deprecated in favor of agrparse,
but argparse is new in Python 2.7. Therefore, it is safer to use optparse, which has
a very similar syntax to argparse, unless you are sure you will be using Python 2.7 or later.
It is also worth mentioning that optparse will correctly parse command line arguments
enclosed in quotes. There have been reports that
argparse will break up strings between blank spaces.
Examples:
# optional arguments with parameters
self.AInf = Argument("-inf", str, BM)
self.AInf.set_optional()
self.AOutf = Argument("-outf", str, BM)
self.AOutf.set_optional()
# optional argument with no parameters ie. switch
self.AInvert = Argument("-inv", str, BM)
self.AInvert.set_is_switch()
self.AInvert.set_optional()
# required arguments at a specific position.
Ainfile = Argument("", str, BM)
Ainfile.set_position(-2)
Aoutfile = Argument("", str, BM)
Aoutfile.set_position(-1)
try:
if (BM.arg_given("-inf")):
self.InFormat = self.AInf.fetch()
if (BM.arg_given("-outf")):
self.OutFormat = self.AOutf.fetch()
self.Invert = BM.arg_given("-inv")
self.Ifn = Ainfile.fetch()
self.Ofn = Aoutfile.fetch()
except ValueError:
BM.printusage() |
|
Methods defined here:
- __init__(self, arg_id, arg_type, BMOD)
- Initializer:
arg_id: The command line flag that specifies an argument parameter is to follow,
ex: "-o outfile"
type: The type that the argument is. This must be a basic type, such as str, float, bool.
if you are unsure if something is a basic type, try running "type(yourtypename)" at interpretter
BM: a pointer to the Birchmod module for the class using this argument (they are coupled)
- add_exclusive(self, exclude)
- Add an argument (flag) to the list of mutually exclusive argument flags for this Argument's flag
- fetch(self)
- This method attempts to fetch the argument with the specified attributes from sys.argv
- set_is_switch(self)
- if this argument is just a switch (with no parameters), set this to true (ex ls -l, -l is a switch)
- set_optional(self)
- Use this if the paramter passed is NOT required
- set_position(self, position)
- Specify the position on sys.argv where the argument is always found.
Argument 0 is the name of the program, so argument 1 is the first argument.
Note that arguments near the end can be specified by len(sys.argv)-X,
where X is the index from the end. "-1" refers to the last argument, "-2"
refers to the next to last argument, etc.
|
class Birchmod |
|
Purpose:
This class provides common safety features to scripts,
as well as making user interactions more intuitive.
In particular, this class is intended to provide
user-readable information when an error occurs |
|
Methods defined here:
- __init__(self, prog, use)
- Initializes birchmod to contain the program usage and program name
- arg_given(self, argId)
- Returns true if "argId" was a string passed on the command line
- documentor(self)
- called by using "pydoc {path to script} pydoc" * note must pass "pydoc" as an argument to toggle documentation mode*
- exit_success(self)
- Used to indicate to the user that a script did execute, and completed successfully
- file_error(self, file_name)
- Called when reading a file fails, used to provide more comprehensive output
- getEmailAddr(self)
- return user's email address
This is currently a bit of a hack. We need to find a better way to do this.
1. If MAILID environment variable is set, use that.
2. If MAILID="", then use the mailid in $BIRCH/local/admin/BIRCH.properties
- getHomeDir(self)
- return the location of the user's home directory
- printusage(self)
- Called when a program performs an illegal operation. Causes program to print its appropriate usage, and exit nicely
- rmrf(self, path)
- Mimics the behavior or unix rm -rf for the given path
- untar(self, file, path='.')
- Extracts the tarfile given by file to current working directory by default, or path
- wget(self, url, name)
- Downloads from url specified to the filename/path specified and displays progress
|
class HTMLWriter |
|
Methods for writing html to a file |
|
Methods defined here:
- __init__(self)
- Initializes arguments:
indentwidth=3
col=0
lpad=""
- end(self, htmlfile, tagname)
- Write end tag
@param htmlfile: The of the html file to write tag for
@type htmlfile: str
@param tagname: The name of the tag to write
@type tagname: str
- end_page(self, htmlfile)
- FIXME
@param htmlfile:
@type htmlfile:
- indent(self)
- **indent is not currently used by htmlwriter**
decrease indent using identwidth blank spaces
- indent_text(self, htmlfile, text)
- FIXME
@param htmlfile:
@type htmlfile:
@param text:
@type text:
- link(self, htmlfile, url, attributes, text)
- FIXME
@param htmlfile:
@type htmlfile:
@param url:
@type url:
@param attributes:
@type attributes:
@param text:
@type text:
- page_title(self, htmlfile, title)
- Write title
@param htmlfile: The name of the html file to add the title to
@type htmlfile: str
@param title: The title to write
@type title: str
- start(self, htmlfile, tagname, attributes)
- Write begin tag, with attributes
@param htmlfile: The name of the html file to write the tag for
@type htmlfile: str
@param tagname: The name of the tag
@type tagname: str
@param attributes: The tag information itself
@type attributes: str
- start_page(self, htmlfile, title)
- FIXME
@param htmlfile:
@type htmlfile:
@param title:
@type title:
- undent(self)
- **undent is not currently used by htmlwriter**
decrease indent using identwidth blank spaces
|
class Htmlutils |
| |
Methods defined here:
- __init__(self, CATDICT, PROGDICT)
- FIXME
@param CATDICT:
@type CATDICT:
@param PROGDICT:
@type PROGDICT:
- cmp_to_key(self, mycmp)
- this function simplifies the transition to python 3 by eleiminating the need for the "cmp" function
this was a recommended workaround for using "cmp"'s in sorts (recommended by: http://wiki.python.org/moin/HowTo/Sorting/)
- get_prefix(self, fn, p)
- FIXME
@param fn:
@type fn:
@param p:
@type p:
- name_to_url(self, name, doc_prefix)
- FIXME
@param name:
@type name:
@param doc_prefix:
@type doc_prefix:
- tokenize(self, line)
- FIXME
@param line:
@type line:
|
class SimpleXML |
|
Simple methods for working wth XML files as an alternative to xml or defusedxml |
|
Methods defined here:
- GetXMLField(self, File, FieldName)
- return a string value from a field of the form <FieldName>Value</FieldName>
This function ONLY returns the first field in the file that matches the
pattern, regardless of how many subsequent fields may match.
- __init__(self)
| |