MadrigalMetadata is a private class that parses a Madrigal metadata file.
This private class is used by all classes that need to parse a Madrigal
metadata file. If the class is called with the name of the metadata file only,
the metadata file is assumed to be at $MAD_ROOT/metadata. If a full path name is
given that includes a directory separator, then that is used instead. The getList
method returns a list with one item for each line in the file. That item for each
line is simply a list of strings found in the line. The following is an example
metadata file and the list the method getList would return.
Metadata file example:
Tom, Dick,,Harry
,,Joe,
Sally, Jane,Joe, Dick
The list returned by getList example:
[['Tom', 'Dick', '', 'Harry'],
['', '', 'Joe', ''],
['Sally', 'Jane', 'Joe', 'Dick']]
Non-standard Python modules used:
None
MadrigalError exception thrown if:
Unable to open metadata file.
All lines in metadata file do not have same number of items
Change history:
Written by Bill Rideout Nov. 8, 2001
Methods
|
|
__getFullPath
__init__
__parseLine
getList
toString
|
|
__getFullPath
|
__getFullPath ( self, filename )
getFullPath returns the full path name of the metafile.
Inputs: filename passed in as argument
Returns: The full path name of the metafile. If the filename argument already is
a full path, filename is returned unchanged. If the filename is simply the name
of a metadata file, then $MAD_ROOT/metadata is appended
Affects: Nothing
Exceptions: None
|
|
__init__
|
__init__ (
self,
metadataFileName,
madDB=None,
allowedLenList=None,
)
__init__ initializes the MadrigalCategoryList by reading from __privateList.
Inputs: String metadataFileName - if not a full path, then MadrigalDB.getMetadataDir
is included.
Existing MadrigalDB object, by default = None.
allowedLenList - a list of allowed lengths (integers) for data lines. If None (the default),
then the rule is that all lengths must be the same.
Returns: void
Affects: Initializes private member variable __categoryList.
Exceptions: None.
Exceptions
|
|
madrigal.admin.MadrigalError("Unable to open metadata file " + self.__fileName, traceback.format_exception(sys.exc_info() [ 0 ], sys.exc_info() [ 1 ], sys.exc_info() [ 2 ] ) )
|
|
|
__parseLine
|
__parseLine ( self, line )
__parseLine adds a list of items in line to __fileList.
Inputs: Line of file to parse (String).
Returns: void
Affects: Adds a list of items in line to self.__fileList.
Exceptions: None.
Exceptions
|
|
madrigal.admin.MadrigalError("Wrong number of items found in metadata file " + self.__fileName + " at line " + str(len( self.__fileList ) ), [traceback.format_exc() ] )
|
|
|
getList
|
getList ( self )
getList returns the list of lists of items in each line in the metafile.
Inputs: None
Returns: The list of lists of items in each line in the metafile. That is, each
item in the returned list is itself a list, representing a single line in the
metafile. That single line's list is the list of items in that line.
Affects: Nothing
Exceptions: None
|
|
toString
|
toString ( self )
toString returns a simple string representation of a MadrigalMetadata object.
Inputs: None
Returns: String describing a simple representation of a __MadrigalMetadat object.
Affects: Nothing
Exceptions: None
|
|