Beispiel #1
0
    def difference(self, epoch):
        '''
        Overriden.

        Raises: TypeNotFoundExImpl
        '''
        #epoch is SWIG generated
        if isinstance(epoch, acstimeSWIG.Epoch):
            return_value = acstimeSWIG.EpochHelper.difference(self, epoch)
            #convert it into a CORBA type
            return acstime.Duration(return_value.value)
        #epoch is CORBA generated
        elif isinstance(epoch, acstime.Epoch):
            #convert it into the SWIG generated class
            value = epoch.value
            epoch = acstimeSWIG.Epoch()
            epoch.value = value
            return_value = acstimeSWIG.EpochHelper.difference(self, epoch)
            #convert it into a CORBA type
            return acstime.Duration(return_value.value)
        #let them also use simple types...
        elif isinstance(epoch, long):
            value = epoch
            epoch = acstimeSWIG.Epoch()
            epoch.value = value
            return_value = acstimeSWIG.EpochHelper.difference(self, epoch)
            #convert it into a CORBA type
            return acstime.Duration(return_value.value)
        else:
            raise TypeNotFoundExImpl()
Beispiel #2
0
    def errorTraceToString(self, error_trace, ws):
        '''
        Converts an error trace to a human-readable string.
        
        Parameters: error_trace is an errortrace
        ws is whitespace

        Returns: Nothing

        Raises: Nothing
        '''
        #figure out a nice format for time first
        epoch = acstime.Duration(
            error_trace.timeStamp)  #convert to an ACS epoch
        timehelper = TimeUtil()
        epoch = timehelper.epoch2py(epoch)  #convert to Python time
        epoch = gmtime(epoch)  #convert to gm time
        epoch = asctime(epoch)  #convert to nice string format

        nice_space = "            "
        for i in range(0, len(ws) / 4):
            nice_space = nice_space + "    "

        message = "ErrorTrace ("
        message = message + "TimeStamp=" + epoch + "," + linesep
        message = message + nice_space + "File=" + str(
            error_trace.file) + "," + linesep
        message = message + nice_space + "Line=" + str(
            error_trace.lineNum) + "," + linesep
        message = message + nice_space + "Routine=" + str(
            error_trace.routine) + "," + linesep
        message = message + nice_space + "Host=" + str(
            error_trace.host) + "," + linesep
        message = message + nice_space + "Process=" + str(
            error_trace.process) + "," + linesep
        message = message + nice_space + "Thread=" + str(
            error_trace.thread) + "," + linesep
        message = message + nice_space + "Type=" + str(
            error_trace.errorType) + "," + linesep
        message = message + nice_space + "Code=" + str(
            error_trace.errorCode) + "," + linesep
        message = message + nice_space + "ShortDescrip=" + str(
            error_trace.shortDescription) + "," + linesep
        message = message + nice_space + "Severity=" + str(
            error_trace.severity) + "," + linesep
        message = message + nice_space + "Data: "
        for i in error_trace.data:
            message = message + "Name=" + str(i.name) + ", Value=" + str(
                i.value) + "; "
        message = message + ")" + linesep

        return message
def duration2py(duration):
    '''
        Convert an ACS duration to a Python duration.

        Parameters: duration is in units of 100 nanoseconds

        Return: duration converted to seconds

        Raises: Nothing
        '''
    if isinstance(duration, long):
        duration = acstime.Duration(duration)

    sec = float(duration.value) / float(10000000L)
    return sec
# Get the current time from the standard CLOCK1 Clock device and add 3 seconds to it
# This is when the timeout will occur.
start = long(getTimeStamp().value) + long(30000000)

# Get the standard Timer component which will
# schedule the timeout
timer = simpleClient.getDefaultComponent("IDL:alma/acstime/Timer:1.0")

# Create timeout handler and schedule its timeout
myHandler = TimeoutHandlerImpl()
myHandler2 = TimeoutHandlerImpl()

# A Duration of 0 implies the timeout will only occur once
id1 = timer.schedule(simpleClient.activateOffShoot(myHandler),
                     acstime.Epoch(start),
                     acstime.Duration(long(20000000)))

# A Duration of 0 implies the timeout will only occur once
id2 = timer.schedule(simpleClient.activateOffShoot(myHandler2),
                     acstime.Epoch(start),
                     acstime.Duration(long(0)))

# Give it ten seconds to run
sleep(10)

timer.cancel(long(id1))

# Give it ten more seconds to run
sleep(10)

# Release it
Beispiel #5
0
 def testDuration2PyNegative(self):
     '''TimeUtil.duration2py handles negative values correctly '''
     rtn = self.th.duration2py(acstime.Duration(-1))
     self.assertEqual(-1, rtn)
Beispiel #6
0
 def testDuration2PyZero(self):
     '''TimeUtil.duration2py handles 0 value correctly'''
     rtn = self.th.duration2py(acstime.Duration(0))
     self.assertEqual(True, isinstance(rtn, long))
     self.assertEqual(0, rtn)
Beispiel #7
0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307  USA
#
# @(#) $Id: acspyTestTimehelper.py,v 1.1.1.1 2012/03/07 17:40:45 acaproni Exp $
###############################################################################
'''
Tests the Python Time System.
'''
###############################################################################
import acstime
from Acspy.Common import TimeHelper

print "getTimeStamp is:", TimeHelper.getTimeStamp()

obj = TimeHelper.TimeUtil()

print "January 1, 1970 is:", obj.py2epoch(0).value, " in ACS time"

print "January 1, 1970 is:", obj.epoch2py(acstime.Epoch(
    obj.py2epoch(0).value)), " in Python time"

print "October 15, 1582 is:", obj.py2epoch(obj.epoch2py(
    acstime.Epoch(0))).value, " in ACS time"

print "October 15, 1582 is:", obj.epoch2py(acstime.Epoch(0)), " in Python time"

print "1000 seconds is:", obj.py2duration(1000).value, " in ACS time"

print "1000 seconds is:", obj.duration2py(
    acstime.Duration(obj.py2duration(1000).value)), " in Python time"