* calendar.py: all libC functionality now moved to built-in time module
* imghdr.py: added jpeg recognition * torgb.py: added jpeg conversion * tzparse.py: use functions from time instead of calendar * whatsound.py: add /ufs/guido/biin/sgi to $PATH when calling 'whatsound'
This commit is contained in:
parent
9b3bc71598
commit
5cfa5dfe97
|
@ -1,37 +1,16 @@
|
|||
##############################
|
||||
# Calendar support functions #
|
||||
##############################
|
||||
###############################
|
||||
# Calendar printing functions #
|
||||
###############################
|
||||
|
||||
# Revision 2: uses funtions from built-in time module where possible.
|
||||
# Revision 2: uses funtions from built-in time module
|
||||
|
||||
# Import functions and variables from time module
|
||||
from time import gmtime, localtime, mktime
|
||||
from time import gmtime, localtime, mktime, asctime, ctime
|
||||
from time import timezone, altzone, daylight, tzname
|
||||
|
||||
# Exception raised for bad input (with string parameter for details)
|
||||
error = 'calendar.error'
|
||||
|
||||
# Abbreviated names of months (1-based arrays!!!)
|
||||
month_abbr = [' ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
|
||||
# Turn calendar time as returned by localtime() into a string
|
||||
def asctime(arg):
|
||||
year, month, day, hours, mins, secs, wday, yday, isdst = arg
|
||||
return '%s %s %02d %02d:%02d:%02d %04d' % (
|
||||
day_abbr[wday], month_abbr[month], day,
|
||||
hours, mins, secs, year)
|
||||
|
||||
# UNIX-style ctime (except it doesn't append '\n'!)
|
||||
def ctime(secs):
|
||||
return asctime(localtime(secs))
|
||||
|
||||
######################
|
||||
# Non-UNIX additions #
|
||||
######################
|
||||
|
||||
# Calendar printing etc.
|
||||
|
||||
# Note when comparing these calendars to the ones printed by cal(1):
|
||||
# My calendars have Monday as the first day of the week, and Sunday as
|
||||
# the last! (I believe this is the European convention.)
|
||||
|
@ -48,10 +27,12 @@ day_name = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', \
|
|||
'Friday', 'Saturday', 'Sunday']
|
||||
day_abbr = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||
|
||||
# Full names of months (1-based arrays!!!)
|
||||
# Full and abbreviated names of months (1-based arrays!!!)
|
||||
month_name = ['', 'January', 'February', 'March', 'April', \
|
||||
'May', 'June', 'July', 'August', \
|
||||
'September', 'October', 'November', 'December']
|
||||
month_abbr = [' ', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', \
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
|
||||
# Return 1 for leap years, 0 for non-leap years
|
||||
def isleap(year):
|
||||
|
|
|
@ -81,6 +81,12 @@ def test_xbm(h, f):
|
|||
|
||||
tests.append(test_xbm)
|
||||
|
||||
def test_jpeg(h, f):
|
||||
# JPEG data in JFIF format
|
||||
if h[6:10] == 'JFIF':
|
||||
return 'jpeg'
|
||||
|
||||
tests.append(test_jpeg)
|
||||
|
||||
#--------------------#
|
||||
# Small test program #
|
||||
|
|
|
@ -40,6 +40,12 @@ t.append('pnmtoppm', '--')
|
|||
t.append('fromppm $IN $OUT', 'ff')
|
||||
table['rast'] = t
|
||||
|
||||
t = pipes.Template().init()
|
||||
t.append('djpeg', '--')
|
||||
t.append('pnmtoppm', '--')
|
||||
t.append('fromppm $IN $OUT', 'ff')
|
||||
table['jpeg'] = t
|
||||
|
||||
uncompress = pipes.Template().init()
|
||||
uncompress.append('uncompress', '--')
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ def whatraw(filename):
|
|||
from stat import ST_SIZE
|
||||
# XXX "whatsound" should be part of the distribution somehow...
|
||||
cmd = 'whatsound ' + filename + ' 2>/dev/null'
|
||||
cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
|
||||
pipe = os.popen(cmd, 'r')
|
||||
data = pipe.read()
|
||||
sts = pipe.close()
|
||||
|
|
|
@ -40,6 +40,12 @@ t.append('pnmtoppm', '--')
|
|||
t.append('fromppm $IN $OUT', 'ff')
|
||||
table['rast'] = t
|
||||
|
||||
t = pipes.Template().init()
|
||||
t.append('djpeg', '--')
|
||||
t.append('pnmtoppm', '--')
|
||||
t.append('fromppm $IN $OUT', 'ff')
|
||||
table['jpeg'] = t
|
||||
|
||||
uncompress = pipes.Template().init()
|
||||
uncompress.append('uncompress', '--')
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ def tzparse(tzstr):
|
|||
[tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs
|
||||
return (tzname, delta, dstname, daystart, hourstart, dayend, hourend)
|
||||
|
||||
def tzlocaltime(time, params):
|
||||
import calendar
|
||||
def tzlocaltime(secs, params):
|
||||
import time
|
||||
(tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params
|
||||
year, month, days, hours, mins, secs, yday, wday = \
|
||||
calendar.gmtime(time - delta*3600)
|
||||
year, month, days, hours, mins, secs, yday, wday, isdst = \
|
||||
time.gmtime(secs - delta*3600)
|
||||
if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend):
|
||||
tzname = dstname
|
||||
hours = hours + 1
|
||||
|
@ -44,33 +44,39 @@ def tzset():
|
|||
daylight = 1
|
||||
tzname = tzparams[0], tzparams[2]
|
||||
|
||||
def isdst(time):
|
||||
import calendar
|
||||
def isdst(secs):
|
||||
import time
|
||||
(tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \
|
||||
tzparams
|
||||
year, month, days, hours, mins, secs, yday, wday, isdst = \
|
||||
calendar.gmtime(time - delta*3600)
|
||||
time.gmtime(secs - delta*3600)
|
||||
return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend)
|
||||
|
||||
tzset()
|
||||
|
||||
def localtime(time):
|
||||
return tzlocaltime(time, tzparams)
|
||||
def localtime(secs):
|
||||
return tzlocaltime(secs, tzparams)
|
||||
|
||||
def test():
|
||||
from calendar import asctime, gmtime
|
||||
from time import asctime, gmtime
|
||||
import time, sys
|
||||
now = time.time()
|
||||
x = localtime(now)
|
||||
print 'now =', now, '=', asctime(x[:-1]), x[-1]
|
||||
tm = x[:-1] + (0,)
|
||||
print 'now =', now, '=', asctime(tm), x[-1]
|
||||
now = now - now % (24*3600)
|
||||
if sys.argv[1:]: now = now + eval(sys.argv[1])
|
||||
x = gmtime(now)
|
||||
print 'gmtime =', now, '=', asctime(x), 'yday =', x[-2]
|
||||
tm = x[:-1] + (0,)
|
||||
print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2]
|
||||
jan1 = now - x[-2]*24*3600
|
||||
x = localtime(jan1)
|
||||
print 'jan1 =', jan1, '=', asctime(x[:-1]), x[-1]
|
||||
tm = x[:-1] + (0,)
|
||||
print 'jan1 =', jan1, '=', asctime(tm), x[-1]
|
||||
for d in range(85, 95) + range(265, 275):
|
||||
t = jan1 + d*24*3600
|
||||
x = localtime(t)
|
||||
print 'd =', d, 't =', t, '=', asctime(x[:-1]), x[-1]
|
||||
tm = x[:-1] + (0,)
|
||||
print 'd =', d, 't =', t, '=', asctime(tm), x[-1]
|
||||
|
||||
test()
|
||||
|
|
|
@ -56,6 +56,7 @@ def whatraw(filename):
|
|||
from stat import ST_SIZE
|
||||
# XXX "whatsound" should be part of the distribution somehow...
|
||||
cmd = 'whatsound ' + filename + ' 2>/dev/null'
|
||||
cmd = 'PATH=$PATH:/ufs/guido/bin/sgi\n' + cmd
|
||||
pipe = os.popen(cmd, 'r')
|
||||
data = pipe.read()
|
||||
sts = pipe.close()
|
||||
|
|
Loading…
Reference in New Issue