From d7bfa80c63d60f66232c60f525a3c98415902d01 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 21 May 1997 21:31:39 +0000 Subject: [PATCH] Lots of new features: - got rid of the separate search page - added an index (lists the questions with links to the answers) - add a mechanism to add new entries - add a way to list most recently edited entries first --- Tools/faqwiz/faqmain.py | 210 ++++++++++++++++++++++++++++++++++------ 1 file changed, 183 insertions(+), 27 deletions(-) diff --git a/Tools/faqwiz/faqmain.py b/Tools/faqwiz/faqmain.py index d1e6a55a338..bc02accd479 100644 --- a/Tools/faqwiz/faqmain.py +++ b/Tools/faqwiz/faqmain.py @@ -1,10 +1,32 @@ #! /depot/sundry/plat/bin/python1.4 -"""Interactive FAQ project.""" +"""Interactive FAQ project. + +XXX TO DO + +- use cookies to keep Name/email the same +- explanation of editing somewhere +- various embellishments, GIFs, crosslinks, hints, etc. +- create new sections +- rearrange entries +- delete entries +- log changes +- send email on changes +- optional staging of entries until reviewed? +- review revision log and older versions +- freeze entries +- username/password for editors +- Change references to other Q's and whole sections +- Browse should display menu of 7 sections & let you pick + (or frontpage should have the option to browse a section or all) +- support adding annotations, too + +""" import cgi, string, os NAMEPAT = "faq??.???.htp" +NAMEREG = "^faq\([0-9][0-9]\)\.\([0-9][0-9][0-9]\)\.htp$" class FAQServer: @@ -22,7 +44,7 @@ class FAQServer: method() KEYS = ['req', 'query', 'name', 'text', 'commit', 'title', - 'author', 'email', 'log'] + 'author', 'email', 'log', 'section', 'number', 'add'] def __getattr__(self, key): if key not in self.KEYS: @@ -38,12 +60,15 @@ class FAQServer: Python FAQ (alpha 1)

Python FAQ Front Page

+

Search the FAQ

+
@@ -54,7 +79,52 @@ class FAQServer: Please exercise discretion when editing, don't be rude, etc. """ - def do_browse(self): + def do_index(self): + print """ + Python FAQ Index +

Python FAQ Index

+ """ + names = os.listdir(os.curdir) + names.sort() + section = None + for name in names: + headers, text = self.read(name) + if headers: + title = headers['title'] + i = string.find(title, '.') + nsec = title[:i] + if nsec != section: + if section: + print """ +

+

  • Add new entry (at this point) + + """ % section + section = nsec + print "

    Section %s

    " % section + print "
      " + print '
    • %s' % ( + name, cgi.escape(title)) + if section: + print """ +

      +

    • Add new entry + (at this point) +
    + """ % section + else: + print "No FAQ entries?!?!" + + def do_show(self): + name = self.name + headers, text = self.read(name) + if not headers: + print "Invalid file name", name + return + self.show(name, headers['title'], text, 1) + + def do_all(self): print """ Python FAQ

    Python FAQ

    @@ -62,13 +132,20 @@ class FAQServer: """ names = os.listdir(os.curdir) names.sort() - n = 0 + section = None for name in names: headers, text = self.read(name) if headers: - self.show(name, headers['title'], text, 1) + title = headers['title'] + i = string.find(title, '.') + nsec = title[:i] + if nsec != section: + section = nsec + print "

    Section %s

    " % section + print "
    " + self.show(name, title, text, 1) n = n+1 - if not n: + if not section: print "No FAQ entries?!?!" def do_roulette(self): @@ -94,17 +171,35 @@ class FAQServer: else: print "No FAQ entries?!?!" - def do_search(self): + def do_recent(self): + import fnmatch, stat + names = os.listdir(os.curdir) + now = time.time() + list = [] + for name in names: + if not fnmatch.fnmatch(name, NAMEPAT): + continue + try: + st = os.stat(name) + except os.error: + continue + tuple = (st[stat.ST_MTIME], name) + list.append(tuple) + list.sort() + list.reverse() print """ - Search the Python FAQ -

    Search the Python FAQ

    - - - - - -
  • + Python FAQ, Most Recently Modified First +

    Python FAQ, Most Recently Modified First

    +
    """ + n = 0 + for (mtime, name) in list: + headers, text = self.read(name) + if headers: + self.show(name, headers['title'], text, 1) + n = n+1 + if not n: + print "No FAQ entries?!?!" def do_query(self): import regex @@ -129,6 +224,43 @@ class FAQServer: if not n: print "No hits." + def do_add(self): + section = self.section + if not section: + print """ + How to add a new FAQ entry +

    How to add a new FAQ entry

    + + Go to the FAQ index + and click on the "Add new entry" link at the end + of the section to which you want to add the entry. + """ + return + try: + nsec = string.atoi(section) + except ValueError: + print "Bad section number", nsec + names = os.listdir(os.curdir) + max = 0 + import regex + prog = regex.compile(NAMEREG) + for name in names: + if prog.match(name) >= 0: + s1, s2 = prog.group(1, 2) + n1, n2 = string.atoi(s1), string.atoi(s2) + if n1 == nsec: + if n2 > max: + max = n2 + if not max: + print "Can't add new sections yet." + return + num = max+1 + name = "faq%02d.%03d.htp" % (nsec, num) + self.name = name + self.add = "yes" + self.number = str(num) + self.do_edit() + def do_edit(self): name = self.name headers, text = self.read(name) @@ -141,7 +273,13 @@ class FAQServer: """ title = headers['title'] print "
    " - self.showedit(name, headers, text) + self.showedit(name, title, text) + if self.add: + print """ + + + + """ % (self.add, self.section, self.number) print """ @@ -165,6 +303,7 @@ class FAQServer: print """ Python FAQ Review Form

    Python FAQ Review Form

    +
    """ self.show(name, title, text) print "" @@ -184,7 +323,13 @@ class FAQServer:

    """ - self.showedit(name, headers, text) + self.showedit(name, title, text) + if self.add: + print """ + + + + """ % (self.add, self.section, self.number) print """
    @@ -220,9 +365,9 @@ class FAQServer: print "No changes." # XXX Should exit more ceremoniously return - # Check that the question number didn't change + # Check that the FAQ entry number didn't change if string.split(title)[:1] != string.split(oldtitle)[:1]: - print "Don't change the question number please." + print "Don't change the FAQ entry number please." # XXX Should exit more ceremoniously return remhost = os.environ["REMOTE_HOST"] @@ -285,6 +430,7 @@ class FAQServer: sts = p.close() if not sts: print """ + Python FAQ Entry Edited

    Python FAQ Entry Edited


    """ @@ -299,8 +445,7 @@ class FAQServer: if output: print "
    %s
    " % cgi.escape(output) - def showedit(self, name, headers, text): - title = headers['title'] + def showedit(self, name, title, text): print """ Title: