17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
import os, types, re, time, types
20
from stat import S_ISREG, S_ISDIR, ST_MODE, ST_SIZE
20
from stat import S_ISREG, S_ISDIR, S_ISLNK, ST_MODE, ST_SIZE
22
22
from errors import bailout
84
86
## XXX: Could alternatively read /proc/sys/kernel/random/uuid on
85
87
## Linux, but we need something portable for other systems;
86
88
## preferably an implementation in Python.
87
bailout('uuids not allowed!')
88
return chomp(os.popen('uuidgen').readline())
90
return chomp(file('/proc/sys/kernel/random/uuid').readline())
92
return chomp(os.popen('uuidgen').readline())
91
96
if s and (s[-1] == '\n'):
134
139
uid = os.getuid()
135
140
w = pwd.getpwuid(uid)
136
realname, junk = w.pw_gecos.split(',', 1)
142
comma = gecos.find(',')
146
realname = gecos[:comma]
137
147
return '%s <%s@%s>' % (realname, w.pw_name, socket.getfqdn())
138
148
except ImportError:
162
172
def compare_files(a, b):
163
173
"""Returns true if equal in contents"""
164
174
# TODO: don't read the whole thing in one go.
165
result = a.read() == b.read()
170
def format_date(t, inutc=False):
186
def local_time_offset(t=None):
187
"""Return offset of local zone from GMT, either at present or at time t."""
188
# python2.3 localtime() can't take None
192
if time.localtime(t).tm_isdst and time.daylight:
195
return -time.timezone
198
def format_date(t, offset=0, timezone='original'):
171
199
## TODO: Perhaps a global option to use either universal or local time?
172
200
## Or perhaps just let people set $TZ?
175
203
assert isinstance(t, float)
205
if timezone == 'utc':
178
206
tt = time.gmtime(t)
208
elif timezone == 'original':
211
tt = time.gmtime(t + offset)
212
elif timezone == 'local':
182
213
tt = time.localtime(t)
184
zonename = time.tzname[1]
185
offset = - time.altzone
187
zonename = time.tzname[0]
188
offset = - time.timezone
214
offset = local_time_offset(t)
216
bailout("unsupported timezone format %r",
217
['options are "utc", "original", "local"'])
190
219
return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
191
+ ' ' + zonename + ' '
192
+ '%+03d%02d' % (offset / 3600, (offset / 60) % 60))
220
+ ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
195
223
def compact_date(when):