110
110
# Make a Subversion client object
111
111
svnclient = pysvn.Client()
113
# For time calculations
114
seconds_per_day = 86400 # 60 * 60 * 24
116
timezone_offset = time.altzone
118
timezone_offset = time.timezone
114
121
# application/json is the "best" content type but is not good for
115
122
# debugging because Firefox just tries to download it
180
187
mtime = os.path.getmtime(path)
181
188
listing["."] = {"isdir" : True,
182
"mtime" : mtime, "mtime_nice" : time.ctime(mtime)}
189
"mtime" : mtime, "mtime_nice" : make_date_nice(mtime),
190
"mtime_short" : make_date_nice_short(mtime)}
184
192
# Listing is a nested object inside the top-level JSON.
185
193
listing = {"listing" : listing}
211
219
type = conf.mimetypes.default_mimetype
213
221
d["mtime"] = file_stat.st_mtime
214
d["mtime_nice"] = time.ctime(file_stat.st_mtime)
222
d["mtime_nice"] = make_date_nice(file_stat.st_mtime)
223
d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
217
226
def PysvnStatus_to_fileinfo(path, status):
247
256
type = conf.mimetypes.default_mimetype
249
258
d["mtime"] = file_stat.st_mtime
250
d["mtime_nice"] = time.ctime(file_stat.st_mtime)
259
d["mtime_nice"] = make_date_nice(file_stat.st_mtime)
260
d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
252
262
# Here if, eg, the file is missing.
253
263
# Can't get any more information so just return d
255
265
return filename, d
267
def make_date_nice(seconds_since_epoch):
268
"""Given a number of seconds elapsed since the epoch,
269
generates a string representing the date/time in human-readable form.
270
"ddd mmm dd, yyyy h:m a"
272
#return time.ctime(seconds_since_epoch)
273
return time.strftime("%a %b %d, %Y %I:%M %p",
274
time.localtime(seconds_since_epoch))
276
def make_date_nice_short(seconds_since_epoch):
277
"""Given a number of seconds elapsed since the epoch,
278
generates a string representing the date in human-readable form.
279
Does not include the time.
280
This function generates a very compact representation."""
281
# Use a "naturalisation" algorithm.
282
days_ago = (int(time.time() - timezone_offset) / seconds_per_day
283
- int(seconds_since_epoch - timezone_offset) / seconds_per_day)
285
# Dates today or yesterday, return "today" or "yesterday".
291
return str(days_ago) + " days ago"
292
# Dates in the last 5 days, return "n days ago".
293
# Other dates, return a short date format.
294
# If within the same year, omit the year (mmm dd)
295
if time.localtime(seconds_since_epoch).tm_year==time.localtime().tm_year:
296
return time.strftime("%b %d", time.localtime(seconds_since_epoch))
297
# Else, include the year (mmm dd, yyyy)
299
return time.strftime("%b %d, %Y", time.localtime(seconds_since_epoch))