1 from __future__ 
import division, absolute_import
 
    6 from twistedActor 
import BaseActor, CommandError
 
   10 __all__ = [
"loadInst"]
 
   12 def loadInst(instDir, instName, gcViewName=None, writeToUsers=None, cmd=None):
 
   13     """!Create an instrument block for the specified instrument 
   15     @param[in] instDir  path to instrument dir (typically tcc.base.getInstDir()) 
   16     @param[in] instName  name of instrument (e.g. "DIS"); case is ignored; may be an abbreviation if unique 
   17     @param[in] gcViewName  name of guide camera view; unlike instName, this may not be an abbreviation; 
   18                 if "" or None then no guide camera view is loaded 
   19     @param[in] writeToUsers  tccActor.writeToUsers or a similar function; if None, write to stdout 
   20     @param[in] cmd  command (twistedActor.BaseCmd) associated with this request, or None 
   23     @throw CommandError if instrument not found or name not unique 
   25     @warning: does not update the AxeLim block (you must do that separately) 
   27     if writeToUsers 
is None:
 
   28         writeToUsers = BaseActor.writeToStdOut
 
   29     gcViewName = gcViewName 
or ""  
   32     instGlobExpr = 
"i_[a-z][a-z][0-9]_%s*.dat" % (instName.lower(),)
 
   33     instFilePathList = glob.glob(os.path.join(instDir, instGlobExpr))
 
   34     if not instFilePathList:
 
   35         raise CommandError(
"Could not find instrument %r in %r" % (instName, instDir))
 
   36     if len(instFilePathList) > 1:
 
   37         raise CommandError(
"Found more than one instrument named %r in %r" % (instName, instDir))
 
   38     instFilePath = instFilePathList[0]
 
   39     instFileName = os.path.basename(instFilePath)
 
   40     instPosName, fullInstName = instFileName.split(
"_", 2)[1:3]
 
   41     fullInstName = fullInstName[:-4] 
 
   43     def fileExists(fileName):
 
   44         return os.path.isfile(os.path.join(instDir, fileName))
 
   49     defFileName = 
"default.dat" 
   50     if not fileExists(
"default.dat"):
 
   51         raise RuntimeError(
"Could not find default file %r in %r" % (defFileName, instDir))
 
   52     dataFileNameList.append(defFileName)
 
   54     instPosFileName = 
"ip_%s.dat" % (instPosName,)
 
   55     if fileExists(instPosFileName):
 
   56         dataFileNameList.append(instPosFileName)    
 
   59         gcViewFileName = 
"v_%s_%s.dat" % (instPosName, gcViewName)
 
   60         if not fileExists(gcViewFileName):
 
   61             raise RuntimeError(
"Could not find guide camera view file %r in %r" % (gcViewFileName, instDir))
 
   62         dataFileNameList.append(gcViewFileName)
 
   64     dataFileNameList.append(instFileName)
 
   67     inst = tcc.base.Inst()
 
   68     for fileName 
in dataFileNameList:
 
   69         filePath = os.path.join(instDir, fileName)
 
   70         inst.loadPath(filePath)
 
   71     writeToUsers(
"i", 
"InstFiles=%s" % (
", ".join(
'"%s"' % (fileName,) 
for fileName 
in dataFileNameList),), cmd=cmd)
 
   74     inst.instName = fullInstName
 
   75     inst.gcViewName = gcViewName
 
   76     inst.instPos.setName(instPosName.upper())
 
def loadInst
Create an instrument block for the specified instrument.