~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/listing.py

  • Committer: wagrant
  • Date: 2008-07-16 05:19:47 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:892
fileservice_lib: Give date pretty-printing functions to common.date.
svnlogservice: Use pretty-printing functions from common.date.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
import os
102
102
import sys
103
103
import stat
104
 
import time
105
104
import mimetypes
106
105
import urlparse
107
106
from cgi import parse_qs
110
109
import pysvn
111
110
 
112
111
import common.svn
 
112
import common.date
113
113
from common import (util, studpath)
114
114
import conf.mimetypes
115
115
 
120
120
# TODO check settings!
121
121
ignore_dot_files = True
122
122
 
123
 
# For time calculations
124
 
seconds_per_day = 86400 # 60 * 60 * 24
125
 
if time.daylight:
126
 
    timezone_offset = time.altzone
127
 
else:
128
 
    timezone_offset = time.timezone
129
 
 
130
123
# Mime types
131
124
# application/json is the "best" content type but is not good for
132
125
# debugging because Firefox just tries to download it
277
270
        d["type"] = type
278
271
        d["type_nice"] = util.nice_filetype(fullpath)
279
272
    d["mtime"] = file_stat.st_mtime
280
 
    d["mtime_nice"] = make_date_nice(file_stat.st_mtime)
281
 
    d["mtime_short"] = make_date_nice_short(file_stat.st_mtime)
 
273
    d["mtime_nice"] = common.date.make_date_nice(file_stat.st_mtime)
 
274
    d["mtime_short"] = common.date.make_date_nice_short(file_stat.st_mtime)
282
275
    return d
283
276
 
284
277
def file_to_fileinfo(path, filename):
341
334
    d.update(_stat_fileinfo(fullpath, wrapped))
342
335
 
343
336
    return filename, d
344
 
 
345
 
def make_date_nice(seconds_since_epoch):
346
 
    """Given a number of seconds elapsed since the epoch,
347
 
    generates a string representing the date/time in human-readable form.
348
 
    "ddd mmm dd, yyyy h:m a"
349
 
    """
350
 
    #return time.ctime(seconds_since_epoch)
351
 
    return time.strftime("%a %b %d %Y, %I:%M %p",
352
 
        time.localtime(seconds_since_epoch))
353
 
 
354
 
def make_date_nice_short(seconds_since_epoch):
355
 
    """Given a number of seconds elapsed since the epoch,
356
 
    generates a string representing the date in human-readable form.
357
 
    Does not include the time.
358
 
    This function generates a very compact representation."""
359
 
    # Use a "naturalisation" algorithm.
360
 
    days_ago = (int(time.time() - timezone_offset) / seconds_per_day
361
 
        - int(seconds_since_epoch - timezone_offset) / seconds_per_day)
362
 
    if days_ago <= 5:
363
 
        # Dates today or yesterday, return "today" or "yesterday".
364
 
        if days_ago == 0:
365
 
            return "Today"
366
 
        elif days_ago == 1:
367
 
            return "Yesterday"
368
 
        else:
369
 
            return str(days_ago) + " days ago"
370
 
        # Dates in the last 5 days, return "n days ago".
371
 
    # Other dates, return a short date format.
372
 
    # If within the same year, omit the year (mmm dd)
373
 
    if time.localtime(seconds_since_epoch).tm_year==time.localtime().tm_year:
374
 
        return time.strftime("%b %d", time.localtime(seconds_since_epoch))
375
 
    # Else, include the year (mmm dd, yyyy)
376
 
    else:
377
 
        return time.strftime("%b %d, %Y", time.localtime(seconds_since_epoch))