MadrigalDBAdmin is a class that allows modifications to be made to the Madrigal database
dbAdminObj = madrigal.admin.MadrigalDBAdmin()
expDir = dbAdminObj.createMadrigalExperiment(/home/hyperion/brideout/mlh050429c.000 ,
Dummy experiment ,
0,
test exp ,
30,
1)
Non-standard Python modules used: None
Change history:
Written by Bill Rideout May. 5, 2005
Methods
|
|
|
|
__checkOpenMadrigalMetadata__
|
__checkOpenMadrigalMetadata__ ( self )
__checkOpenMadrigalMetadata__ is a method that check the openmadrigal site for any
updates to the following metadata files:
siteTab.txt - the list of all Madrigal installations
2. instTab.txt - the list of all Madrigal instruments
3. instType.txt - the list of all instrument categories
If an update is available, and the existing metadata file is an old one, it will be updated.
However, if the local Madrigal adminstrator edits one of these files, then the file will
not be updated. If you want to change these files, it is best to contact the OpenMadrigal
development administrator (madrigal@haystack.mit.edu)
Exceptions
|
|
IOError, 'Problem with url %s' %( thisUrl )
|
|
|
__init__
|
__init__ ( self, madDB=None )
__init__ initializes MadrigalDBAdmin
Inputs: madDB - Existing MadrigalDB object. Default = None.
Returns: void
Affects:
Sets self.__madDB to MadrigalDB object
Sets self.__madInst to MadrigalInstrument object
|
|
__updateGlobalMetadata__
|
__updateGlobalMetadata__ ( self )
__updateGlobalMetadata__ is a private method to update metadata/expTabAll.txt and metadata/fileTabAll.txt
from the main madrigal server.
|
|
__updateLocalMetadata__
|
__updateLocalMetadata__ ( self )
__updateLocalMetadata__ is a private method to update metadata/expTab.txt and metadata/fileTab.txt
from the local metadata in the experiments[0-9]* directory
|
|
__walkExpDir__
|
__walkExpDir__ (
self,
arg,
dirname,
names,
)
__walkExpDir__ is a private method called by os.path.walk. arg is a dict with keys:
1. extText = text of combined expTab.txt to be appended to
2. fileText = text of combined fileTab.txt to be appended to
3. presentCount = total experiments done so far
4. localSiteId = local site id (int)
Sets values in arg
|
|
addMadrigalFile
|
addMadrigalFile (
self,
expDir,
madFilename,
permission,
fileDesc,
category=1,
kindat=None,
notify=True,
fileAnalyst='',
fileAnalystEmail='',
includeCachedHdf5=True,
iniFile=None,
)
addMadrigalFile adds a new file to an experiment using metadata read from madFilename.
Inputs:
expDir - full path to experiment directory (as returned by createMadriogalExperiment)
madFilename - full path to the complete Madrigal file. Basename will be maintained.
permission - 0 (public) or 1 (private).
fileDesc - file description
category - 1=default, 2=variant, 3=history, or 4=realtime. Default is 1 (default file)
kindat - if not None (the default), use this kindat instead of what is found in the file.
notify - if True (the default), send a message to all registered users. If False, do not.
fileAnalyst - full name of file Analyst. Default is ''
fileAnalystEmail - email of file Analyst. Default is ''
includeCachedHdf5 - if True (the default) create cached Hdf5 file. If False, do not.
iniFile - the ini file to use for creating a cached hdf5 file. If None, uses default ini file
$MADROOT/cachedFiles.ini. Ignored if not includeCachedHdf5
Returns: None
Exceptions
|
|
'File %s already exists - must be deleted first' %( filename )
ValueError, ' file %s does not yet exist' %(os.path.join( expDir, 'fileTab.txt' ) )
ValueError, 'More than one kindat value found in file: %s' %(str( kindatList ) )
ValueError, 'No kindat values found in file'
ValueError, 'category must be 1=default, 2=variant, 3=history, or 4=realtime; not %s' %(str( category ) )
ValueError, 'fileAnalyst cannot contain a comma'
ValueError, 'fileAnalystEmail cannot contain a comma'
ValueError, 'fileDesc not a string'
ValueError, 'fileDesc string in fileTab.txt cannot contain a comma: <%s> is illegal' %( fileDesc )
ValueError, 'permission must be either 0 or 1, not %s' %(str( permission ) )
|
|
|
|
|
addWebFile
|
addWebFile (
self,
expDir,
source,
relativePath,
)
addWebFile writes a non-Madrigal file meant to be displayed on the web to somewhere within a Madrigal experiment directory.
All needed directories will be created if needed.
Inputs:
expDir - full path to experiment directory
source - local web file to write to Madrigal
relativePath - path relative to expDir to write source file to. If relativePath ends
with /, then basename from source used. Otherwise, basename from relativePath used.
Returns: None
Affects: writes a non-Madrigal file to expDir on Madrigal
Exceptions
|
|
ValueError, '%s not a valid experiment directory - no fileTab.txt' %( expDir )
|
|
|
appendRTMadrigalFile
|
appendRTMadrigalFile (
self,
expDir,
rtFilename,
rtFile,
)
appendRTMadrigalFile allows appending to a realtime Madrigal file.
Fails if rtFilename does not match one listed in fileTab.txt. If the file doesn't exist, will
create it, and will then check that the format is unblocked binary. This is because unblocked binary
is written by logical record, without physical records that may later be modified. If the file does
exist, rtFile will be appended with checking the file format.
Inputs:
expDir - full path to experiment directory (as returned by createRTExperiment)
rtFilename - basename of realtime file to be writtem
rtFile - a string containing the new realtime file contents
Returns: None
Raises exception if rtFilename does not match one listed in fileTab.txt, or if format != unblocked binary
when new file is created.
Exceptions
|
|
ValueError, 'Expected file %s to be UnblockedBinary, is %s' %( os.path.join( expDir, rtFilename ), filetype )
ValueError, 'Filename %s not found in fileTab.txt' %( rtFilename )
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|
changeExpStatus
|
changeExpStatus (
self,
expDir,
expUrl=None,
expName=None,
siteID=None,
startDatetime=None,
endDatetime=None,
inst=None,
security=None,
PI=None,
PIEmail=None,
)
changeExpStatus is used to change attributes in expTab.txt. If None, no change.
Inputs:
expDir - full path to experiment directory. Required. Example:
"/opt/madrigal/experiments/1998/mlh/20jan98". If None, do not change.
expUrl - must be in form <cgi base>/madtoc/YYYY/<3 letter lower case inst code>/<expDir>
example: http://www.haystack.mit.edu/cgi-bin/madtoc/1997/mlh/03dec97g.
If None, do not change.
expName - experiment name. Quotes required if contains spaces. Example: "World Day"
If None, do not change.
siteID - Madrigal siteID (int) of where data will be stored. Error raised if not the siteID
of the local Madrigal site. Example: 4. If None, do not change.
startDatetime - new start datetime of experiment (UT). If None, do not change.
endDatetime - new end datetime of experiment (UT). If None, do not change.
inst - new instrument code (int). Example: 30. If None, do not change. Prints
warning if not found in instTab.txt
security - new security code. Allowed values are 0 for public, 1 for private (limited IP range access)
-1 for ignore, 2 for archived experiment, 3 for private (limited IP range access) archived
experiment. If None, do not change.
PI - name of PI. If None, no change
PIEmail - PI email. If None, no change
Exceptions
|
|
ValueError, 'Setting experiment to a siteID %i different from this site\'s id %i' %(siteID, self.__madDB.getSiteID() )
ValueError, 'The experiment url you are setting this experiment to <%s> conflicts with experiment directory %s' %( expUrl, expDir )
ValueError, 'Unable to open expTab.txt in %s' %( expDir )
ValueError, 'expTab.txt in %s has %i experiments, should have exactly 1' %(expDir, expTabInfo.getExpCount() )
ValueError, 'security must be in (-1, 0, 1, 2, 3), not %i' %( inst )
ValueError, 'startDatetime %s must be before endDatetime %s' %(str( startDatetime ), str( endDatetime ) )
|
|
|
changeFileStatus
|
changeFileStatus (
self,
expDir,
filename,
category=None,
fileDesc=None,
permission=None,
kindat=None,
fileAnalyst=None,
fileAnalystEmail=None,
)
changeFileStatus is used to change category, fileDesc, or permission of a register file in fileTab.txt.
Inputs:
expDir - full path to experiment directory
filename - basename of existing Madrigal file already registered in fileTab.txt
permission - 0 (public) or 1 (private). If None (default), leave unchanged.
fileDesc - file description. If None (default), leave unchanged.
category - 1=default, 2=variant, or 3=history. If None (default), leave unchanged.
kindat - kindat (int). If None (default), leave unchanged.
fileAnalyst - name of file analyst. If None (default), leave unchanged.
fileAnalystEmail - email of file analyst. If None (default), leave unchanged.
Exceptions
|
|
ValueError, 'Madrigal file %s not found in %s' %(filename, os.path.join( expDir, 'fileTab.txt' ) )
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|
createMadrigalExperiment
|
createMadrigalExperiment (
self,
madFilename,
expTitle,
permission,
fileDesc,
instCode=None,
category=1,
optChar='',
dirName=None,
kindat=None,
experimentsDirNum=None,
PI='',
PIEmail='',
fileAnalyst='',
fileAnalystEmail='',
includeCachedHdf5=True,
iniFile=None,
notify=True,
)
createMadrigalExperiment creates a new experiment on Madrigal using metadata read from madFilename.
Inputs:
madFilename - full path to the complete Madrigal file. Basename will be maintained.
expTitle - experiment title
permission - 0 (public) or 1 (private) or -1 (ignore).
fileDesc - file description
instCode - instrument code. If default (None), instrument code is taken from file, but error
is thrown if more than one kinst found.
category - 1=default, 2=variant, 3=history, or 4=realtime. Default is 1 (default file)
optChar - optional character to be added to experiment directory if no dirName
given. If dirName argument given, this argument ignored. optChar
is used if the default directory name DDmmmYY is used for
more than one experiment created for a given instrument on a given day.
For example, if --optChar=h for a MLH experiment on September 12, 2005,
then the experiment directory created would be experiments/2005/mlh/12sep05h.
dirName - directory name to use for experiment. If None (the default), the directory
name will be the default name DDmmmYY[optChar]. Cannot contain "/"
kindat - if not None (the default), use this kindat instead of what is found in the file.
experimentsDirNum - the number to be appended to the experiments directory, if experiments
directory being used is of the form experiments[0-9]* instead of just
experiments. For example, if experimentsDirNum is 7, then the experiment
would be created in MADROOT/experiments7 instead of MADROOT/experiments.
PI- full name of principal investigator. The default is ''
PIEmail - email of principal investigator. The default is ''
fileAnalyst -full name of file analyst. The default is ''
fileAnalystEmail - email of file analyst,. The default is ''
includeCachedHdf5 - if True (the default) create cached Hdf5 file. If False, do not.
iniFile - the ini file to use for creating a cached hdf5 file. If None, uses default ini file
$MADROOT/cachedFiles.ini. Ignored if not includeCachedHdf5
notify - if True (the default), send a message to all registered users. If False, do not.
Returns:
Full path to directory created
Exceptions
|
|
IOError, 'Directory %s already exists' %( expDir )
ValueError, 'More than one kindat value found in file: %s' %(str( kindatList ) )
ValueError, 'More than one kinst value found in file: %s' %(str( kinstList ) )
ValueError, 'No kindat values found in file'
ValueError, 'No kinst values found in file'
ValueError, 'PI cannot contain a comma'
ValueError, 'PI not a string'
ValueError, 'PIEmail cannot contain a comma'
ValueError, 'PIEmail not a string'
ValueError, 'Unable to find mnemonic for kinst %i' %( instCode )
|
ValueError, 'category must be 1=default, 2=variant, 3=history, or 4=realtime; not %s' %(str( category ) )
ValueError, 'dirName must be base directory name, not %s' %( dirName )
ValueError, 'expTitle cannot contain a comma'
ValueError, 'expTitle not a string'
ValueError, 'fileAnalyst cannot contain a comma'
ValueError, 'fileAnalyst not a string'
ValueError, 'fileAnalystEmail cannot contain a comma'
ValueError, 'fileAnalystEmail not a string'
ValueError, 'fileDesc cannot contain a comma'
ValueError, 'fileDesc not a string'
|
ValueError, 'no such directory %s' %( experimentsDir )
ValueError, 'optChar must be an empty or a one character string, not %s' %(str( optChar ) )
ValueError, 'permission must be either 0 or 1 or -1, not %s' %(str( permission ) )
|
|
|
|
createRTExperiment
|
createRTExperiment (
self,
startTime,
numDays,
instrument,
expTitle,
rtFilenameList,
kindatList,
permissionList,
fileDescList,
optChar='',
endTime=None,
security=0,
dirName=None,
experimentsDirNum=None,
PI='',
PIEmail='',
fileAnalystList=None,
fileAnalystEmailList=None,
notify=True,
)
createRTExperiment creates a new experiment on Madrigal in preparation for realtime data.
Since the experiment is presumably not yet complete, metadata such as the duration of the experiment
must be estimated. This metadata will be overwritten when the first batch file is added.
Inputs:
startTime - experiment start time. If a number, assumed to be seconds since 1/1/1970. May also
be a datetime.datetime object
numDays - number of days the experiment is estimated to run. Ignored if optional endTime given.
instrument - instrument code or 3-letter Madrigal mnenonic
expTitle - experiment title
rtFilenameList - list of realtime filenames to be created
kindatList - list of ints of kindats for each realtime file. Len = len(rtFilenameList)
permissionList - list of 0 (public) or 1 (private). Len = len(rtFilenameList)
fileDescList - list of realtime file descriptions
optChar - optional character to be added to experiment directory if no dirName
given. If dirName argument given, this argument ignored. optChar
is used if the default directory name DDmmmYY is used for
more than one experiment created for a given instrument on a given day.
For example, if --optChar=h for a MLH experiment on September 12, 2005,
then the experiment directory created would be experiments/2005/mlh/12sep05h.
endTime - optional end date and time of experiment. If a number, assumed to be seconds since
1/1/1970. May also be a datetime.datetime object
security - experiment security setting. If 0 (the default) public. If 1, private.
If -1, entire experiment ignored. Any given file permission is the more
restricted of experiment permission and file permission.
dirName - directory name to use for experiment. If None (the default), the directory
name will be the default name DDmmmYY[optChar]. Cannot contain "/"
experimentsDirNum - the number to be appended to the experiments directory, if experiments
directory being used is of the form experiments[0-9]* instead of just
experiments. For example, if experimentsDirNum is 7, then the experiment
would be created in MADROOT/experiments7 instead of MADROOT/experiments.
PI- full name of principal investigator. The default is ''
PIEmail - email of principal investigator. The default is ''
fileAnalystList - list of full names of file analysts, one for each file. If None, the default,
File Analyst = ''
fileAnalystEmailList - list of emails of file analysts, one for each file. If None, the default,
File Analyst email = ''
notify - if True (the default), send a message to all registered users. If False, do not.
Returns:
Full path to directory created
Exceptions
|
|
'optChar must be an empty or a one character string, not %s' %(str( optChar ) )
IOError, 'Directory %s already exists' %( expDir )
ValueError, '%s not a legal instrument mnemonic or code' %(str( instrument ) )
ValueError, '%s not a legal instrument mnemonic' %(str( instrument ) )
ValueError, 'Experiment start time %s after end time %s' %(str( startTime ), str( endTime ) )
ValueError, 'PI cannot contain a comma'
ValueError, 'PI not a string'
ValueError, 'PIEmail cannot contain a comma'
ValueError, 'PIEmail not a string'
ValueError, 'dirName must be base directory name, not %s' %( dirName )
|
ValueError, 'expTitle cannot contain a comma'
ValueError, 'expTitle not a string'
ValueError, 'fileAnalyst cannot contain a comma'
ValueError, 'fileAnalystEmail cannot contain a comma'
ValueError, 'fileAnalystEmailList must only contain strings'
ValueError, 'fileAnalystList must only contain strings'
ValueError, 'fileDesc cannot contain a comma'
ValueError, 'fileDescList must only contain strings'
ValueError, 'filename cannot contain a comma'
ValueError, 'kindatList must contain integers of value 0 (public) or 1 (private)'
|
ValueError, 'kindatList must contain integers'
ValueError, 'length of fileAnalystEmailList not equal length of rtFilenameList'
ValueError, 'length of fileAnalystList not equal length of rtFilenameList'
ValueError, 'length of fileDescList not equal length of rtFilenameList'
ValueError, 'length of kindatList not equal length of rtFilenameList'
ValueError, 'length of permissionList not equal length of rtFilenameList'
ValueError, 'no such directory %s' %( experimentsDir )
ValueError, 'numDays must not be negative'
ValueError, 'rtFilenameList must contain strings without /'
ValueError, 'rtFilenameList must contain strings'
|
|
|
|
overwriteMadrigalFile
|
overwriteMadrigalFile (
self,
expDir,
madFilename,
notify=True,
includeCachedHdf5=True,
iniFile=None,
)
overwriteMadrigalFile overwrites a file already registered in fileTab.txt.
Automatically updates expTab.txt with any start or end experiment times.
Inputs:
expDir - full path to experiment directory
madFilename - full path to the new Madrigal file. Basename must match that of one in fileTab.txt.
notify - if True (the default), send a message to all registered users. If False, do not.
includeCachedHdf5 - if True (the default) create cached Hdf5 file. If False, do not.
iniFile - the ini file to use for creating a cached hdf5 file. If None, uses default ini file
$MADROOT/cachedFiles.ini. Ignored if not includeCachedHdf5
Returns: None
Affects: Overwrites existing Madrigal file. May modify expTab.txt with new start/end times
Exceptions
|
|
ValueError, '%s not found in %s' %(filename, os.path.join( expDir, 'fileTab.txt' ) )
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|
removeMadrigalFile
|
removeMadrigalFile (
self,
expDir,
madFilename,
)
removeMadrigalFile removes a file already registered in fileTab.txt.
Automatically updates expTab.txt with any start or end experiment times.
Inputs:
expDir - full path to experiment directory
madFilename - Name of Madrigal file to be removed. Basename must match that of one in fileTab.txt.
Returns: None
Affects: Removes existing Madrigal file and removes its line from fileTab.txt. May modify expTab.txt
with new start/end times
Exceptions
|
|
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|
updateExpTab
|
updateExpTab ( self, expDir )
updateExpTab rewrites expTab.txt based on all the Madrigal files registered in fileTab.txt.
Inputs:
expDir - full path to experiment directory
Returns: None
Affects: rewrites expTab.txt in expDir based on all the Madrigal files registered in fileTab.txt.
Exceptions
|
|
ValueError, 'Unable to open expTab.txt in %s' %( expDir )
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|
updateMaster
|
updateMaster ( self, skipGeo=False )
updateMaster is a method to update the local metadata.
Replaces the former tcl script.
Gathers data from experiment directories into metadata/expTab.txt and metadata/fileTab.txt.
Also gathers metadata from OpenMadrigal to update metadata/expTabAll.txt and metadata/fileAllTab.txt,
to update high level metadata siteTab.txt, instTab.txt, instType.txt, madCatTab.txt, parcods.tab.
Also updates geophysical data.
|
|
writeRTMadrigalFile
|
writeRTMadrigalFile (
self,
expDir,
rtFilename,
rtFile,
)
writeRTMadrigalFile writes a realtime Madrigal file to a Madrigal experiment directory.
Fails if rtFilename does not match one listed in fileTab.txt.
Inputs:
expDir - full path to experiment directory (as returned by createRTExperiment)
rtFilename - basename of realtime file to be writtem
rtFile - a string containing the realtime file contents
Returns: None
Raises exception if rtFilename does not match one listed in fileTab.txt.
Exceptions
|
|
ValueError, 'Filename %s not found in fileTab.txt' %( rtFilename )
ValueError, 'Unable to open fileTab.txt in %s' %( expDir )
|
|
|