コード例 #1
0
        def load_pass():
            try:
                passwd_file = '%s/.vnc/passwd' % os.environ['HOME']
                in_f = open(passwd_file, 'r')
                passwd = in_f.read()
                in_f.close()

                return ro.binary_encode(passwd)
            except IOError, e:
                self.logger.error("Cannot read password file '%s': %s" %
                                  (passwd_file, str(e)))
                return None
コード例 #2
0
    def process(self, agheader, datatime, data_na):
        """Process AG data packet.
        _agheader_ is a string corresponding to the AG header string.
        _datatime_ is the data time (as float) of the data.
        _data_na_ is a numpy of the pixel data.
        """
        self.logger.debug("time: %8.4f  header: %s" % (datatime, agheader))

        # Get data size reported by ag header
        (height, width) = data_na.shape

        # print out intervals of receiving image
        self.logger.debug("data intervals (%s - %s)" %
                          (datatime, self.previous))

        # put an image into queue if there is more than one second intervals
        # between current and previous coming image
        if (self.previous == None) or \
               ((datatime - self.previous) >= self.delta):

            # set current time to previous
            self.previous = datatime

            ###########################
            ## server-client version ##
            ###########################

            if self.display != None:

                self.logger.debug("encoding data for remote display")

                # Encode buffer for XMLRPC transport
                encoded_image = ro.binary_encode(data_na.tostring())

                self.logger.debug("calling guider_display")

                # Call object to display buffer
                try:
                    res = self.display.guider_display(encoded_image, width,
                                                      height)
                    if res != ro.OK:
                        self.logger.error("guider_display call failed: %d" %
                                          (res))
                except Exception, e:
                    self.logger.error("guider_display call failed: %s" %
                                      (str(e)))
コード例 #3
0
def client(options, data, is_binary):

    datafile = None
    if options.datafile:
        datafile = open(options.datafile, 'a')

    auth = None
    if options.auth:
        auth = options.auth.split(':')

    # Get handle to server
    testro = ro.remoteObjectProxy(options.svcname,
                                  auth=auth,
                                  secure=options.secure)

    print "Starting '%s' client..." % (options.svcname)
    size = len(data)

    time1 = time.time()

    if is_binary:
        data = ro.binary_encode(data)

    time2 = time.time()

    amount = 0.0
    for i in xrange(options.count):
        res = testro.recv(data, is_binary)
        amount += size

    tottime = time.time() - time1
    # Average time if more than one call made
    if options.count > 1:
        tottime = tottime / options.count

    print "Time taken: %f secs (%f bytes/sec) (enc: %f secs) " % \
          (tottime, amount/tottime, time2-time1)

    if datafile:
        # total bytes, count, total time, encode time, avg rate
        datafile.write("%d %d %f %f %f\n" %
                       (size * options.count, options.count, tottime,
                        time2 - time1, amount / tottime))
        datafile.close()
コード例 #4
0
    def _playSound(self,
                   buffer,
                   format=None,
                   encode=True,
                   compress=None,
                   filename=None,
                   priority=20):

        ## if compress == None:
        ##     compress = self.compress

        with self.lock:
            if self.muted:
                self.logger.warn("play sound buffer: mute is ON")
                return ro.OK

        if compress:
            beforesize = len(buffer)
            buffer = ro.compress(buffer)
            aftersize = len(buffer)
            self.logger.debug("Compressed audio buffer %d->%d bytes." %
                              (beforesize, aftersize))

        if encode:
            buffer = ro.binary_encode(buffer)
            self.logger.debug("Encoded audio buffer for transport.")

        try:
            self.monitor.setvals(self.channels,
                                 self.tag,
                                 buffer=buffer,
                                 format=format,
                                 filename=filename,
                                 compressed=compress,
                                 priority=priority)

        except Exception, e:
            self.logger.error("Error submitting remote sound: %s" % str(e))
コード例 #5
0
    def update_image(self, image):
        self.logger.debug("Updating gui image...%s" % image)
        data = image.get_data()

        objname = image.get_keyword('OBJECT', 'Noname')
        try:
            viewer = self.aginfo.viewer
            deriver = image.get('deriver', None)
            if deriver:
                deriver.deriveAll(image)

            height, width = data.shape
            data = data.byteswap(True)
            buf = ro.binary_encode(data.tostring())
            header = image.get_header()
            self.logger.debug("Header is %s" % (str(header)))

            metadata = {}
            guiding = image.get('hasregion', False)
            metadata['guiding'] = guiding
            if guiding:
                metadata['region'] = image.get('region')

            aghdr = {}
            aghdr.update(image.get('agheader'))
            metadata['agheader'] = aghdr
            metadata['agtime'] = image.get('agtime')

            name = self.agkey
            ## viewer.display_fitsbuf(name, name, buf, width, height,
            ##                        0, header, metadata)
            viewer.callGlobalPlugin(
                "foo", "VGW", 'display_fitsbuf',
                (name, name, buf, width, height, 0, header, metadata), {})
        except Exception, e:
            self.logger.error("Error updating fits image (%s): %s" %
                              (self.agkey, str(e)))
コード例 #6
0
        modtime = time.mktime(vec)

        # read fits buffer
        try:
            fits_f = open(fitspath, 'r')

            fitsbuf = fits_f.read()
            fits_f.close()

        except IOError, e:
            raise DAQerror("Error opening fits file '%s': %s" %
                           (fitspath, str(e)))

        # Encode buffer for XMLRPC transport
        fitsbuf = ro.binary_encode(fitsbuf)

        print "Transmitting %s ..." % frameid
        svc.archive_fitsbuf(frameid, fitsbuf, modtime)


def server(logger, options, args):

    ev_quit = threading.Event()

    daq_obj = DAQdoor(logger,
                      ev_quit,
                      interval=options.interval,
                      fifopath=options.fifopath,
                      fitsdir=options.fitsdir)
コード例 #7
0
        if interface:
            interface.ro_start(wait=True)

        while not ev_quit.isSet():
            # Get time before work
            begintime = time.time()

            try:
                # Get output string to write to file
                result = output(templ, status, oldvals, options)

                # If we are using a remote service, call it here with the
                # buffer contents...
                if ro_svc:
                    buf = ro.binary_encode(result)
                    ro_svc.putFile(buf)

                # Otherwise use the more conventional (and slower) scp copy.
                else:
                    # Use another output file if specified
                    if not options.outputfile:
                        web_f = sys.stdout
                    else:
                        try:
                            web_f = open(options.outputfile, 'w')

                        except IOError, e:
                            raise ltcsError("Error opening output file '%s': %s\n" % \
                                            (options.outputfile, str(e)))