Friday, April 08, 2005

cvsview.py

change to compare posix timestamp floats instead of strings (what were they thinking?!) I'll be posting this to bugzilla and hope for a patch. This was my first real whirl with python. It has some odd nuances (like enforced indentation), and lousy date/time handling (compared to Java objects). But overall, it's kinda slick. I still prefer Ruby.

-----------
try:
weekday,month,day,ttime,year=date.split(" ")
hour,minute,second=ttime.split(":")
#print year + " " + month + " " + day + " " + ttime +" " + hour + " " + minute+ " " + second
iyear = int(year)
#resolve month to int
imonth = {'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12 }[month]
iday = int(day)
ihour = int(hour)
iminute = int(minute)
isecond = int(second)
cvsdate = datetime.datetime(iyear,imonth,iday,ihour,iminute,isecond,0)
sysmodtime = time.mktime(time.gmtime(os.stat(path).st_mtime))#now a float
sysstruct = time.gmtime(os.stat(path).st_mtime)
print "file " + name
print "sysstruct " + str(sysstruct)
print "modstruct " + str([cvsdate.year,cvsdate.month,cvsdate.day,cvsdate.hour,cvsdate.minute,cvsdate.second,0,0,0])
cvsmodtime = time.mktime([cvsdate.year,cvsdate.month,cvsdate.day,cvsdate.hour,cvsdate.minute,cvsdate.second,0,0,0])#should also be float representation
print "sys " + str(sysmodtime)
print "cvs " + str(cvsmodtime)
except OSError:
state = tree.STATE_MISSING
else:
if cvsmodtime == sysmodtime:
state = tree.STATE_NORMAL
else:
state = tree.STATE_MODIFIED



-----------

No comments: