Ejemplo n.º 1
0
def OSPC_getValues_Gen2(logger, fromGen2=True):
    """Get updated values for the SD.StatusDictionary from
     the Gen2 status server, using conversions specified therein."""

    global __entryLineCnt
    global gen2FirstTime, statServerAvailable, g2Stat
    global newvaldict, keynum

    # First time -- check for status server presence, get remote proxy
    if gen2FirstTime:
        gen2FirstTime = False
        if fromGen2:
            g2Stat = g2StatusObj(svcname='status')
        else:
            g2Stat = cachedStatusObj('obs1.sum.subaru.nao.ac.jp')
        statServerAvailable = True

    # Set __entryLineCnt, OSPC_IterCnt; open data log (first time only);
    #   get epochTime and statusKeys
    epochTime, statusKeys = OSPC_getValues_CommonProlog()

    # Separate statusKeys into fetchKeys and telstatKeys
    fetchKeys = []
    for key in statusKeys:
        if not key.startswith('TELSTAT.'):
            fetchKeys.append(key)

    current_keynum = len(fetchKeys)

    try:
        logger.debug('keynum=%d   cur_keynum=%d' % (keynum, current_keynum))
        if not keynum == current_keynum:
            keynum = current_keynum
            newvaldict = dict.fromkeys(fetchKeys, STATNONE)
            newvaldict = g2Stat.fetch(newvaldict)
            logger.debug('fetching from status server...')
        else:
            logger.debug('fetching from mon ...')

        #print "result = ",newvaldict
    except Exception, value:
        keynum = 0
        # set TELSTAT.UNIXTIME
        SD.StatusDictionary['TELSTAT.UNIXTIME'].setValue(hrsec=epochTime)
        # log error
        logger.error(
            "ERROR (OSSC_screenPrintConversions:OSPC_getValues_Gen2):  cannot access remote status object: %s"
            % str(value))
        # set all other variables to None
        for key in statusKeys:
            if key != 'TELSTAT.UNIXTIME':
                SD.StatusDictionary[key].setValue(None)
        # if logging is turned on, write TELSTAT.NODATA, to data log
        if TelStat_cfg.telStatDataLogging:
            __OSPC_writeAliasToLog('TELSTAT.NODATA', 'No Data')
            TelStat_cfg.telStatDataLog_fd.write('\n')
            TelStat_cfg.telStatDataLog_fd.write('\n')
        # end of processing for this cycle -- return
        return
Ejemplo n.º 2
0
def main():
    sc = cachedStatusObj('obs.sum.subaru.nao.ac.jp')
    syslog.openlog("SOSSstatusServer", syslog.LOG_PID,
                   syslog.LOG_WARNING | syslog.LOG_DAEMON)
    while True:
        line = sys.stdin.readline()
        if line == "":
            break
        aliasname = line.strip(' \r\n')
        val = sc.get_statusValue(aliasname)
        sys.stderr.write(str(val) + "\n")
    syslog.closelog()
Ejemplo n.º 3
0
    def __init__(self, options, logger):
        """Constructor for the INSintTester object.
        """

        # Invoke our base class constructor.
        INSintGUI.__init__(self)

        self.logger = logger
        self.insconfig = INSconfig()

        # Set up default connection parameters from command line
        self.obcpnum = options.obcpnum
        self.monunitnum = options.monunitnum
        if not options.obcphost:
            self.obcphost = SOSSrpc.get_myhost(short=True)
        else:
            self.obcphost = options.obcphost
        self.raidpath = options.fitsdir
        self.transfermethod = options.transfermethod
        self.username = options.username
        self.password = options.password

        self.ev_quit = threading.Event()
        self.ev_mainquit = threading.Event()
        self.soss = None

        # Did user specify a Gen2 status source?
        if options.statussvc:
            ro_status = ro.remoteObjectProxy(options.statussvc)
            statusObj = INSint.FetchStatusWrapper_Gen2(ro_status)

        # Did user specify a SOSS status source?
        elif options.statushost:
            from SOSS.status import cachedStatusObj

            statusDict = cachedStatusObj(options.statushost)
            statusObj = INSint.FetchStatusWrapper_SOSS(statusDict)

        # Did user specify a SOSS status file?
        elif options.statusfile:
            try:
                in_f = open(options.statusfile, 'r')
                statusDict = eval(in_f.read())
                in_f.close()

            except Exception, e:
                self.showStatus("Error reading status file '%s': %s" % \
                                (options.statusfile, str(e)))
                statusDict = {}

            statusObj = INSint.FetchStatusWrapper_SOSS(statusDict)
def main(options, args):

    # create a handle to the status system whether gen2 or soss
    if options.soss:
        sc = cachedStatusObj(host=options.statushost)

    else:
        sc = g2StatusObj(host=options.statushost, svcname=options.statussvc)

    if options.regex:
        info = statusInfo()
        regexes = map(re.compile, args)
        args = []
        for alias in info.getAliasNames():
            for regex in regexes:
                if regex.match(alias):
                    args.append(alias)
        args.sort()

    # fetch the list of status items (returns a dict)
    res = sc.get_statusValuesList(args)

    # print the key/values out, interpreting as necessary
    idx = 1
    for aliasname in args:
        try:
            aliasdef = sc.info.get_aliasDef(aliasname)

        except statusError, e:
            # this means that StatusAlias.pro does not contain this name
            aliasdef = None

        val = res.pop(0)

        if (aliasdef != None) and (aliasdef.stype == 'B'):
            if options.raw:
                print "%0x" % val
            else:
                print "% 3d : [%s]=[%0x]" % (idx, aliasname, val)
        else:
            if options.raw:
                print "%s" % str(val)
            else:
                print "% 3d : [%s]=[%s]" % (idx, aliasname, str(val))
        idx += 1
Ejemplo n.º 5
0
def main(options, args):

    # Create a SOSS status object
    statusObj = cachedStatusObj(host=options.statushost)

    try:
        # One shot or..continuous?
        if options.interval == None:
            getAliases(statusObj, args)

        else:
            while True:
                getAliases(statusObj, args)
                print "---------------------------------"

                time.sleep(options.interval)

    except KeyboardInterrupt:
        print "Received keyboard interrupt!"
Ejemplo n.º 6
0
def main(options, args):

    # Create status object
    sc = cachedStatusObj(host=options.statushost)

    # If "ALL" given as command line arg, then grab it, otherwise it is a
    # list of aliases
    if (len(args) == 1) and (args[0].upper() == "ALL"):
        if options.tables:
            args = sc.getTableNames()
        else:
            args = sc.getAliasNames()

    if options.statussvc:
        import remoteObjects as ro
        ro.init()
        
        sc = ro.remoteObjectProxy(options.statussvc)
        
        (d, errorlist) = captureAliasesGen2(sc, args)

    else:
        (d, errorlist) = captureAliases(sc, args)

    if options.g2prime:
        g2PrimeAliases(sc, d)
        
    # Dump Python readable repn to stdout
    #print repr(d)
    print "#\n# SOSS status snapshot: %s\n#\n" % (time.ctime())
    pprint.pprint(d)

    if len(errorlist) > 0:
        sys.stderr.write("ERRORS fetching:\n")
        for (aliasname, errstr) in errorlist:
            sys.stderr.write("%16s: %s\n" % (aliasname, errstr))
Ejemplo n.º 7
0
    # frameids asynchronously
    if options.framehost:
        try:
            frameint = rpcFrameObj(options.framehost)

        except rpc.PortMapError, e:
            logger.error("Can't connect to portmapper on framehost (%s)" % \
                         options.framehost)
            sys.exit(1)
    else:
        frameint = None

    # Specified a status server for the instrument to use to fetch
    # status (not via the DAQtk status mechanism)
    if options.statushost:
        statusObj = cachedStatusObj(options.statushost)

    else:
        statusObj = None

    # Create the instrument object
    simcam = Instrument(logger, ev_quit=ev_quit, 
                        ocsint=daqtk, frameint=frameint,
                        statusObj=statusObj, obcpnum=options.obcpnum,
                        threadPool=threadPool,
                        allowNoPara=options.noparaok)

    # Load the personalities.  User can specify several cams to be loaded
    # on the command line.  Also, cams can be given aliases.
    for (alias, cam) in camlist:
        simcam.loadPersonality(cam, alias=alias)
def main(options, args):

    # Create top level logger.
    logger = ssdlog.make_logger('EnvMonitor', options)

    # Create status object to be shared by all interested parties
    if options.statsvc:
        # Specified Gen2 status
        status_obj = Gen2StatusObject(options.statsvc)

    else:
        # Specified SOSS status
        status_obj = st.cachedStatusObj(options.statint)

    # callback for popping up wind monitor
    def showWindDirection():
        global windWindow

        if windWindow:
            windWindow.deiconify()
            #windWindow.show()
            return

        # Create the base frame for the widgets
        WindMonitor(status_obj, logger)

    # Create the base frame for the widgets
    root = Tk()
    Pmw.initialise(root)
    root.title("Environment Monitor")
    root.tk.call('tk', 'scaling', 1)
    if options.geometry:
        root.geometry(options.geometry)
    else:
        root.geometry("433x742")

    def dialogResult(result):
        global quitDialog
        #print 'You clicked on ', result
        quitDialog.deactivate(result)
        if result == 'Yes':
            root.quit()

    def askAboutQuitting():
        # Create the dialog.
        global quitDialog
        quitDialog = Pmw.Dialog(None,
                                buttons=('No', 'Yes'),
                                defaultbutton='Yes',
                                title='Quit Environment Monitor?',
                                command=dialogResult)
        quitDialog.geometry("300x45")
        quitDialog.activate(globalMode=1)
        quitDialog.withdraw()

    def _delete_main_window():
        askAboutQuitting()

    root.protocol("WM_DELETE_WINDOW", _delete_main_window)

    row = 0
    widget1 = sg.StatusGraph(root,
                             title="Wind direction (deg) N:0 E:90",
                             statusKeys=("TSCL.WINDD", ),
                             maxDeltas=(300, ),
                             gconfig=(None, "black", "white", (0, 360, 90), 1,
                                      0, 1),
                             background="#f5fffc",
                             statusObj=status_obj)
    widget1.grid(row=row, column=0)
    widget1.tick()
    row += 1

    widget2 = sg.StatusGraph(
        root,
        title="Wind Speed(m/s)",
        statusKeys=("TSCL.WINDS_O", "TSCL.WINDS_I"),
        alarmValues=(10, 15),
        #gconfig = (None, "black", "white", (-1,20,5), 1, 0, 1),
        background="#f7fff4",
        statusObj=status_obj)
    widget2.grid(row=row, column=0)
    widget2.tick()
    row += 1

    widget3 = sg.StatusGraph(root,
                             title="Temperature(C)",
                             statusKeys=("TSCL.TEMP_O", "TSCL.TEMP_I"),
                             statusObj=status_obj)
    widget3.grid(row=row, column=0)
    widget3.tick()
    row += 1

    widget4 = sg.StatusGraph(root,
                             title="Humidity(%)",
                             statusKeys=("TSCL.HUMI_O", "TSCL.HUMI_I"),
                             alarmValues=(80, 80),
                             background="#fffff6",
                             size=(112, 430),
                             displayTime=True,
                             lconfig=THINDEFAULTLINE,
                             statusObj=status_obj)
    widget4.grid(row=row, column=0)
    widget4.tick()
    row += 1

    widget5 = sg.StatusGraph(root,
                             title="Air Pressure(hPa) :",
                             size=(97, 430),
                             statusKeys=("TSCL.ATOM", ),
                             statusFormats=("%0.1f", ),
                             lconfig=THINDEFAULTLINE,
                             statusObj=status_obj)
    widget5.grid(row=row, column=0)
    widget5.tick()
    row += 1

    widget6 = sg.StatusGraph(root,
                             title="Rain Gauge(mm/h) :",
                             statusKeys=("TSCL.RAIN", ),
                             statusFormats=("%0.1f", ),
                             alarmValues=(50, ),
                             size=(93, 430),
                             background="#f4f4f4",
                             statusObj=status_obj)
    widget6.grid(row=row, column=0)
    widget6.tick()
    row += 1

    widget7 = sg.StatusGraph(root,
                             title="Seeing Size(arcsec)",
                             statusKeys=("TSCL.SEEN", "VGWD.FWHM.AG"),
                             alarmValues=(1, 1),
                             statusFormats=("TSC: %0.1f", "VGW: %0.1f"),
                             displayTime=True,
                             statusObj=status_obj)
    widget7.grid(row=row, column=0)
    widget7.tick()
    row += 1

    #    widget8 = sg.StatusGraph(root, title="Sky Transparency(%) :",
    #                                statusKeys=("TSCL.THRU",),
    #                                background="#f4f4f4",
    #                                displayTime=True, statusObj=status_obj)
    #    widget8.grid(row=row, column=0)
    #    widget8.tick()
    #    row +=1

    bottomframe = Frame(root, width=440)
    buttons = Pmw.ButtonBox(bottomframe)
    buttons.add('Quit',
                command=askAboutQuitting,
                font=('Helvetica', 12, 'bold'))
    buttons.grid(row=0, column=0)

    resourceframe = ResourceMonitor(bottomframe, status_obj, logger)
    resourceframe.grid(row=0, column=1)
    resourceframe.tick()

    buttons = Pmw.ButtonBox(bottomframe)
    buttons.add('Wind Direction',
                command=showWindDirection,
                font=('Helvetica', 12, 'bold'))
    buttons.grid(row=0, column=2)
    bottomframe.grid(row=row, column=0)
    row += 1

    try:
        try:
            root.mainloop()

        except KeyboardInterrupt:
            logger.error("Received keyboard interrupt!")

    except Exception, e:
        logger.error("Top-level exception raised: %s" % str(e))
        raise e
Ejemplo n.º 9
0
            in_f = open(infile, 'r')
        except IOError, e:
            print "Can't open input file '%s': %s" % (infile, str(e))
            sys.exit(1)

        # Convert binary file to test data
        data = in_f.read()
        in_f.close()

        client(options, data, True)

    elif select == 'status':
        table = args[0]

        import SOSS.status as st
        status = st.cachedStatusObj(options.statushost)
        status.updateTable(table)

        # Convert binary file to test data
        data = status.cache[table].table

        client(options, data, True)

    elif select == 'calls':
        client2(options)

    else:
        print "I don't know how to do '%s'" % select
        sys.exit(1)

    sys.exit(0)
Ejemplo n.º 10
0
        quit()
        ev_quit.set()

    # Set signal handler for signals
    signal.signal(signal.SIGINT, SigHandler)
    signal.signal(signal.SIGTERM, SigHandler)

    logger.info("Starting status service...")
    try:
        if not options.statint:
            stathost = SOSSrpc.get_myhost(short=True)
        else:
            stathost = options.statint

        #cso = gen2StatusObj(logger, stathost)
        cso = st.cachedStatusObj(stathost)

        # Create mini monitor to reflect to main monitor
        mymonname = ('%s.mon' % svcname)
        minimon = Monitor.Monitor(mymonname, logger, numthreads=15)
        minimon.start()
        minimon.start_server(usethread=True)
        mon_started = True

        if options.monitor:
            # Subscribe main monitor to our updates
            minimon.subscribe(options.monitor, monchannels, {})

            # Subscribe ourselves to the statint feed via main monitor
            minimon.subscribe_remote(options.monitor, ['statint'], {})