Added marks for very recently (24 hours) and recently (7 days)

modified files.  Added and used global now, entry.getmtime(), and
entry.emit_marks().
This commit is contained in:
Guido van Rossum 1997-05-26 19:46:56 +00:00
parent fd67f738dd
commit 7a241071d4

View file

@ -14,6 +14,7 @@ file as a string literal.
import sys, string, time, os, stat, regex, cgi, faqconf import sys, string, time, os, stat, regex, cgi, faqconf
from faqconf import * # This imports all uppercase names from faqconf import * # This imports all uppercase names
now = time.time()
class FileError: class FileError:
def __init__(self, file): def __init__(self, file):
@ -158,7 +159,6 @@ def send_my_cookie(ui):
value = "%s/%s/%s" % (ui.author, ui.email, ui.password) value = "%s/%s/%s" % (ui.author, ui.email, ui.password)
import urllib import urllib
value = urllib.quote(value) value = urllib.quote(value)
now = time.time()
then = now + COOKIE_LIFETIME then = now + COOKIE_LIFETIME
gmt = time.gmtime(then) gmt = time.gmtime(then)
print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value), print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value),
@ -243,8 +243,25 @@ class FaqEntry:
p.close() p.close()
self.version = version self.version = version
def getmtime(self):
if not self.last_changed_date:
return 0
try:
return os.stat(self.file)[stat.ST_MTIME]
except os.error:
return 0
def emit_marks(self):
mtime = self.getmtime()
if mtime >= now - DT_VERY_RECENT:
emit(MARK_VERY_RECENT, self)
elif mtime >= now - DT_RECENT:
emit(MARK_RECENT, self)
def show(self, edit=1): def show(self, edit=1):
emit(ENTRY_HEADER, self) emit(ENTRY_HEADER1, self)
self.emit_marks()
emit(ENTRY_HEADER2, self)
pre = 0 pre = 0
for line in string.split(self.body, '\n'): for line in string.split(self.body, '\n'):
if not string.strip(line): if not string.strip(line):
@ -461,20 +478,18 @@ class FaqWizard:
self.last_changed(files) self.last_changed(files)
self.format_index(files, localrefs=1) self.format_index(files, localrefs=1)
self.format_all(files, edit=0) self.format_all(files, edit=0)
sys.exit(0) sys.exit(0) # XXX Hack to suppress epilogue
def last_changed(self, files): def last_changed(self, files):
latest = 0 latest = 0
for file in files: for file in files:
try: entry = self.dir.open(file)
st = os.stat(file) if entry:
except os.error: mtime = mtime = entry.getmtime()
continue
mtime = st[stat.ST_MTIME]
if mtime > latest: if mtime > latest:
latest = mtime latest = mtime
print time.strftime(LAST_CHANGED, print time.strftime(LAST_CHANGED, time.localtime(now))
time.localtime(time.time())) emit(EXPLAIN_MARKS)
def format_all(self, files, edit=1, headers=1): def format_all(self, files, edit=1, headers=1):
sec = 0 sec = 0
@ -495,7 +510,9 @@ class FaqWizard:
def do_index(self): def do_index(self):
self.prologue(T_INDEX) self.prologue(T_INDEX)
self.format_index(self.dir.list(), add=1) files = self.dir.list()
self.last_changed(files)
self.format_index(files, add=1)
def format_index(self, files, add=0, localrefs=0): def format_index(self, files, add=0, localrefs=0):
sec = 0 sec = 0
@ -519,6 +536,7 @@ class FaqWizard:
emit(LOCAL_ENTRY, entry) emit(LOCAL_ENTRY, entry)
else: else:
emit(INDEX_ENTRY, entry) emit(INDEX_ENTRY, entry)
entry.emit_marks()
if sec: if sec:
if add: if add:
emit(INDEX_ADDSECTION, sec=sec) emit(INDEX_ADDSECTION, sec=sec)
@ -529,18 +547,16 @@ class FaqWizard:
days = 1 days = 1
else: else:
days = string.atof(self.ui.days) days = string.atof(self.ui.days)
now = time.time()
try: try:
cutoff = now - days * 24 * 3600 cutoff = now - days * 24 * 3600
except OverflowError: except OverflowError:
cutoff = 0 cutoff = 0
list = [] list = []
for file in self.dir.list(): for file in self.dir.list():
try: entry = self.dir.open(file)
st = os.stat(file) if not entry:
except os.error:
continue continue
mtime = st[stat.ST_MTIME] mtime = entry.getmtime()
if mtime >= cutoff: if mtime >= cutoff:
list.append((mtime, file)) list.append((mtime, file))
list.sort() list.sort()
@ -763,7 +779,7 @@ class FaqWizard:
except IOError, why: except IOError, why:
self.error(CANTWRITE, file=file, why=why) self.error(CANTWRITE, file=file, why=why)
return return
date = time.ctime(time.time()) date = time.ctime(now)
emit(FILEHEADER, self.ui, os.environ, date=date, _file=f, _quote=0) emit(FILEHEADER, self.ui, os.environ, date=date, _file=f, _quote=0)
f.write('\n') f.write('\n')
f.write(self.ui.body) f.write(self.ui.body)