gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 46992 - in gump/trunk/python/gump: core document/xdocs process run stats/mysql test timing utils
Date Tue, 21 Sep 2004 18:29:15 GMT
Author: ajack
Date: Tue Sep 21 11:29:14 2004
New Revision: 46992

Modified:
   gump/trunk/python/gump/core/config.py
   gump/trunk/python/gump/document/xdocs/documenter.py
   gump/trunk/python/gump/process/launcher.py
   gump/trunk/python/gump/run/gumpenv.py
   gump/trunk/python/gump/stats/mysql/statsdb.py
   gump/trunk/python/gump/test/timing.py
   gump/trunk/python/gump/timing/keeper.py
   gump/trunk/python/gump/utils/timing.py
Log:
Some work on datetime (gosh this stuff is harder than would be nice!)

Modified: gump/trunk/python/gump/core/config.py
==============================================================================
--- gump/trunk/python/gump/core/config.py	(original)
+++ gump/trunk/python/gump/core/config.py	Tue Sep 21 11:29:14 2004
@@ -67,8 +67,8 @@
     DATETIME_PRESENTATION_FORMAT='%a, %d %b %Y %H:%M:%S (%Z)'
     TIME_PRESENTATION_FORMAT='%H:%M:%S (%Z)'
     
-    UTC_DATETIME_PRESENTATION_FORMAT='%a, %d %b %Y %H:%M:%S (UTC)'
-    UTC_TIME_PRESENTATION_FORMAT='%H:%M:%S (UTC)'
+    UTC_DATETIME_PRESENTATION_FORMAT='%a, %d %b %Y %H:%M:%S (%Z)'
+    UTC_TIME_PRESENTATION_FORMAT='%H:%M:%S (%Z)'
     
     TIMEOUT=60*60 # 60 minutes (in seconds)
     

Modified: gump/trunk/python/gump/document/xdocs/documenter.py
==============================================================================
--- gump/trunk/python/gump/document/xdocs/documenter.py	(original)
+++ gump/trunk/python/gump/document/xdocs/documenter.py	Tue Sep 21 11:29:14 2004
@@ -2298,7 +2298,7 @@
             workRow.setStyle(stateName(work.state).upper())
                 
             if isinstance(work,TimedWorkItem):      
-                workRow.createData(work.result.start.isoformat())
+                workRow.createData(work.getStart().getLocal())
                 workRow.createData(secsToElapsedTimeString(work.getElapsedSecs()))
             else:
                 workRow.createData('N/A')
@@ -2366,8 +2366,8 @@
                 workList.createEntry("Termination Signal: ", str(work.result.signal))
             workList.createEntry("Exit Code: ", str(work.result.exit_code))
                                 
-            workList.createEntry("Start Time: ", work.result.start.isoformat())
-            workList.createEntry("End Time: ", work.result.end.isoformat())
+            workList.createEntry("Start Time: ", work.getStart().getLocal())
+            workList.createEntry("End Time: ", work.getEnd().getLocal())
             e = secsToElapsedTimeString(work.getElapsedSecs())
             if e : workList.createEntry("Elapsed Time: ", e)
                    

Modified: gump/trunk/python/gump/process/launcher.py
==============================================================================
--- gump/trunk/python/gump/process/launcher.py	(original)
+++ gump/trunk/python/gump/process/launcher.py	Tue Sep 21 11:29:14 2004
@@ -46,7 +46,7 @@
    	"""	
     
     outputFile=None
-    start=datetime.datetime.now()
+    start=getLocalNow()
     try:
       try:          
  
@@ -148,7 +148,7 @@
               os.remove(outputFile)
         
       # Keep time information
-      end=datetime.datetime.now()
+      end=getLocalNow()
       result.start=start
       result.end=end 
 	  

Modified: gump/trunk/python/gump/run/gumpenv.py
==============================================================================
--- gump/trunk/python/gump/run/gumpenv.py	(original)
+++ gump/trunk/python/gump/run/gumpenv.py	Tue Sep 21 11:29:14 2004
@@ -48,9 +48,6 @@
 # Classes
 ###############################################################################
 
-# Local time zone, in offset from UTC
-TZ='%+.2d:00' % (-time.timezone/3600)
-
 class GumpEnvironment(Annotatable,Workable,Propogatable):
     """
     	Represents the environment that Gump is running within.
@@ -93,8 +90,8 @@
         self.depotHome = None
         
         # Timezone and offset from UTC
-        self.timezone=time.timezone
-        self.timezoneOffset=TZ
+        self.timezone=time.tzname
+        self.timezoneOffset=time.timezone
         
     def checkEnvironment(self,exitOnError=False):
         """ 

Modified: gump/trunk/python/gump/stats/mysql/statsdb.py
==============================================================================
--- gump/trunk/python/gump/stats/mysql/statsdb.py	(original)
+++ gump/trunk/python/gump/stats/mysql/statsdb.py	Tue Sep 21 11:29:14 2004
@@ -37,6 +37,7 @@
 from gump.model.state import *
 
 import gump.utils.mysql
+import gump.utils.timing
   
 class StatisticsDB:
     """
@@ -242,7 +243,7 @@
     # Project
     ps=stats.getProjectStats('test')
     ps.successes+=1
-    ps.first=datetime.datetime.now()
+    ps.first=getLocalNow()
     stats.putProjectStats(ps)     
     if len(sys.argv) > 1:
         stats.delProjectStats(ps)

Modified: gump/trunk/python/gump/test/timing.py
==============================================================================
--- gump/trunk/python/gump/test/timing.py	(original)
+++ gump/trunk/python/gump/test/timing.py	Tue Sep 21 11:29:14 2004
@@ -77,12 +77,6 @@
         rough=getGeneralDifferenceDescription(self.now, twoYearsBefore)
         self.assertInString('Date Diff String', '2 years', rough)
         
-    def testRandomStuff(self):
-        # :TODO: Clean this up, just moved it here so as not to lose it.
-        secsToElapsedTimeTriple(1340)
-        secsToElapsedTimeString(1340)
-        elapsedTimeTripleToString(secsToElapsedTimeTriple(1340))
-  
     def testTimeStampSet(self):
         set=TimeStampSet('Test1')
         set.stamp('Stamp1')
@@ -93,17 +87,35 @@
         time.sleep(10)
         set.stamp('Stamp3')
         
+        # Create the first range
         range1=TimeStampRange('Range1')
         time.sleep(5)
         range1.setEnd()
         range1.setExternal(True)
         set.registerRange(range1)
         
+        # Create the second range
         range2=TimeStampRange('Range2')
         time.sleep(5)
         range2.setEnd()
         range2.setExternal(False)
         set.registerRange(range2)
         
-        #set.dump()
-        set.getTotalTimes()
\ No newline at end of file
+        set.dump()
+        set.getTotalTimes()
+        
+        self.assertGreater('Time passes', range1.getStart(), range1.getEnd())        
+        self.assertGreater('Time passes', range2.getStart(), range2.getEnd())        
+        self.assertGreater('Time passes', range1.getEnd(), range2.getEnd())
+        
+        self.assertGreater('Time passes', set.getStart(), set.getEnd())
+        
+    def testUTCTimes(self):
+        stamp1=TimeStamp('S1')
+        stamp2=TimeStamp('S2')
+        
+        t1=stamp1.getUtc()
+        t2=stamp2.getUtc()
+        
+        self.assertIn('UTC', 'UTC', t1)
+        self.assertIn('UTC', 'UTC', t2)
\ No newline at end of file

Modified: gump/trunk/python/gump/timing/keeper.py
==============================================================================
--- gump/trunk/python/gump/timing/keeper.py	(original)
+++ gump/trunk/python/gump/timing/keeper.py	Tue Sep 21 11:29:14 2004
@@ -36,6 +36,10 @@
         """
         if isinstance(event,gump.run.gumprun.InitializeRunEvent):
             self.run.setStart()
+            print 'KEEPER: START'
         elif isinstance(event,gump.run.gumprun.FinalizeRunEvent):  
             self.run.setEnd()
+            print 'KEEPER: STOP'
+            
+        self.run.times.dump()
             

Modified: gump/trunk/python/gump/utils/timing.py
==============================================================================
--- gump/trunk/python/gump/utils/timing.py	(original)
+++ gump/trunk/python/gump/utils/timing.py	Tue Sep 21 11:29:14 2004
@@ -30,8 +30,63 @@
 from gump.utils import getIndent
 from gump.core.config import default, setting
 
+ZERO = datetime.timedelta(0)
+HOUR = datetime.timedelta(hours=1)
+
+class UTC(datetime.tzinfo):
+    """UTC"""
+
+    def utcoffset(self, dt):
+        return ZERO
+
+    def tzname(self, dt):
+        return "UTC"
+
+    def dst(self, dt):
+        return ZERO
+
+UTC_TIMEZONE_INFO = UTC()
+
 ZERO_DELTA=datetime.timedelta(seconds=0)
 
+STDOFFSET = datetime.timedelta(seconds = -time.timezone)
+if time.daylight:
+    DSTOFFSET = datetime.timedelta(seconds = -time.altzone)
+else:
+    DSTOFFSET = STDOFFSET
+DSTDIFF = DSTOFFSET - STDOFFSET
+
+class LocalTimezone(datetime.tzinfo):
+
+    def utcoffset(self, dt):
+        if self._isdst(dt):
+            return DSTOFFSET
+        else:
+            return STDOFFSET
+
+    def dst(self, dt):
+        if self._isdst(dt):
+            return DSTDIFF
+        else:
+            return ZERO
+
+    def tzname(self, dt):
+        return time.tzname[self._isdst(dt)]
+
+    def _isdst(self, dt):
+        tt = (dt.year, dt.month, dt.day,
+              dt.hour, dt.minute, dt.second,
+              dt.weekday(), 0, -1)
+        stamp = time.mktime(tt)
+        tt = time.localtime(stamp)
+        return tt.tm_isdst > 0
+
+LOCAL_TIMEZONE_INFO = LocalTimezone()
+
+
+def getLocalNow():
+    return datetime.datetime.now(LOCAL_TIMEZONE_INFO)
+
 def deltaToSecs(delta):
     """
     	Convert a delta into it's total seconds
@@ -166,19 +221,20 @@
     def __init__(self,name,stamp=None):
         self.name=name               
         if not stamp:
-            stamp=datetime.datetime.now()
+            stamp=getLocalNow()
         self.timestamp=stamp       
         
-    # Representations:
+    # UTC Representation:
     def getUtc(self):
-        if hasattr(self,'utc'): return self.utc 
-        self.utc=self.timestamp.strftime(setting.UTC_DATETIME_PRESENTATION_FORMAT)
+        if hasattr(self,'utc'): return self.utc
+        utc=self.timestamp.utctimetuple()
+        self.utc=time.strftime(setting.UTC_DATETIME_PRESENTATION_FORMAT, utc)
         return self.utc
         
-    # Representations:
+    # Local Representation:
     def getLocal(self):
         if hasattr(self,'local'): return self.local 
-        self.local=self.timestamp.strftime(setting.UTC_DATETIME_PRESENTATION_FORMAT)
+        self.local=self.timestamp.strftime(setting.DATETIME_PRESENTATION_FORMAT)
         return self.local
     
     def getTimestamp(self):
@@ -189,8 +245,7 @@
         return False
         
     def __str__(self):
-        return 'TimeStamp: '+self.name+' : '+ \
-                toDateTime(self.timestamp) 
+        return 'TimeStamp: '+self.name+' : ' + toDateTime(self.timestamp) 
                 
     def __cmp__(self,other):
         return (self.timestamp < other.timestamp)
@@ -263,14 +318,10 @@
         self.startTimeStamp=start        
         self.endTimeStamp=start
         
-    def registerStamp(self,stamp):  
-        # :TODO: don't assume stored in time order
-        self.endTimeStamp=stamp  
+    def registerStamp(self,stamp):   
         return self.store(stamp)
         
-    def registerRange(self,range):  
-        # :TODO: don't assume stored in time order
-        self.endTimeStamp=range.getEnd()         
+    def registerRange(self,range): 
         return self._store(range)
             
     def stamp(self,sname):
@@ -284,8 +335,17 @@
     def _store(self,stamp):
         # Store for posterity
         self.append(stamp) 
+        
+        # Update 
+        self._updateEnd(stamp)
+                 
         return stamp
         
+    def _updateEnd(self,stamp):
+        # :TODO: don't assume stored in time order
+        self.endTimeStamp=stamp  
+        
+        
     def getElapsedSecs(self):
         return self.endTimeStamp.getTimestamp() - self.startTimeStamp.getTimestamp()
         
@@ -370,7 +430,7 @@
     def hasStart(self):
         return self.times.hasStart()
         
-    def setStart(self,comment=None):
+    def setStart(self,comment='Start'):
         self.times.setStart(comment)
         
     def getStart(self):
@@ -379,7 +439,7 @@
     def hasEnd(self):
         return self.times.hasEnd()
         
-    def setEnd(self,comment=None):
+    def setEnd(self,comment='End'):
         self.times.setEnd(comment)
         
     def getEnd(self):

Mime
View raw message