Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a24107

Browse files
committed
Added marks for very recently (24 hours) and recently (7 days)
modified files. Added and used global now, entry.getmtime(), and entry.emit_marks().
1 parent fd67f73 commit 7a24107

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

Tools/faqwiz/faqwiz.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import sys, string, time, os, stat, regex, cgi, faqconf
1616
from faqconf import * # This imports all uppercase names
17+
now = time.time()
1718

1819
class FileError:
1920
def __init__(self, file):
@@ -158,7 +159,6 @@ def send_my_cookie(ui):
158159
value = "%s/%s/%s" % (ui.author, ui.email, ui.password)
159160
import urllib
160161
value = urllib.quote(value)
161-
now = time.time()
162162
then = now + COOKIE_LIFETIME
163163
gmt = time.gmtime(then)
164164
print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value),
@@ -243,8 +243,25 @@ def load_version(self):
243243
p.close()
244244
self.version = version
245245

246+
def getmtime(self):
247+
if not self.last_changed_date:
248+
return 0
249+
try:
250+
return os.stat(self.file)[stat.ST_MTIME]
251+
except os.error:
252+
return 0
253+
254+
def emit_marks(self):
255+
mtime = self.getmtime()
256+
if mtime >= now - DT_VERY_RECENT:
257+
emit(MARK_VERY_RECENT, self)
258+
elif mtime >= now - DT_RECENT:
259+
emit(MARK_RECENT, self)
260+
246261
def show(self, edit=1):
247-
emit(ENTRY_HEADER, self)
262+
emit(ENTRY_HEADER1, self)
263+
self.emit_marks()
264+
emit(ENTRY_HEADER2, self)
248265
pre = 0
249266
for line in string.split(self.body, '\n'):
250267
if not string.strip(line):
@@ -461,20 +478,18 @@ def do_compat(self):
461478
self.last_changed(files)
462479
self.format_index(files, localrefs=1)
463480
self.format_all(files, edit=0)
464-
sys.exit(0)
481+
sys.exit(0) # XXX Hack to suppress epilogue
465482

466483
def last_changed(self, files):
467484
latest = 0
468485
for file in files:
469-
try:
470-
st = os.stat(file)
471-
except os.error:
472-
continue
473-
mtime = st[stat.ST_MTIME]
474-
if mtime > latest:
475-
latest = mtime
476-
print time.strftime(LAST_CHANGED,
477-
time.localtime(time.time()))
486+
entry = self.dir.open(file)
487+
if entry:
488+
mtime = mtime = entry.getmtime()
489+
if mtime > latest:
490+
latest = mtime
491+
print time.strftime(LAST_CHANGED, time.localtime(now))
492+
emit(EXPLAIN_MARKS)
478493

479494
def format_all(self, files, edit=1, headers=1):
480495
sec = 0
@@ -495,7 +510,9 @@ def format_all(self, files, edit=1, headers=1):
495510

496511
def do_index(self):
497512
self.prologue(T_INDEX)
498-
self.format_index(self.dir.list(), add=1)
513+
files = self.dir.list()
514+
self.last_changed(files)
515+
self.format_index(files, add=1)
499516

500517
def format_index(self, files, add=0, localrefs=0):
501518
sec = 0
@@ -519,6 +536,7 @@ def format_index(self, files, add=0, localrefs=0):
519536
emit(LOCAL_ENTRY, entry)
520537
else:
521538
emit(INDEX_ENTRY, entry)
539+
entry.emit_marks()
522540
if sec:
523541
if add:
524542
emit(INDEX_ADDSECTION, sec=sec)
@@ -529,18 +547,16 @@ def do_recent(self):
529547
days = 1
530548
else:
531549
days = string.atof(self.ui.days)
532-
now = time.time()
533550
try:
534551
cutoff = now - days * 24 * 3600
535552
except OverflowError:
536553
cutoff = 0
537554
list = []
538555
for file in self.dir.list():
539-
try:
540-
st = os.stat(file)
541-
except os.error:
556+
entry = self.dir.open(file)
557+
if not entry:
542558
continue
543-
mtime = st[stat.ST_MTIME]
559+
mtime = entry.getmtime()
544560
if mtime >= cutoff:
545561
list.append((mtime, file))
546562
list.sort()
@@ -763,7 +779,7 @@ def commit(self, entry):
763779
except IOError, why:
764780
self.error(CANTWRITE, file=file, why=why)
765781
return
766-
date = time.ctime(time.time())
782+
date = time.ctime(now)
767783
emit(FILEHEADER, self.ui, os.environ, date=date, _file=f, _quote=0)
768784
f.write('\n')
769785
f.write(self.ui.body)

0 commit comments

Comments
 (0)