cpython/Tools/faqwiz/faqwiz.py

746 lines
17 KiB
Python
Raw Normal View History

1997-05-26 02:43:29 -03:00
"""Generic FAQ Wizard.
This is a CGI program that maintains a user-editable FAQ. It uses RCS
to keep track of changes to individual FAQ entries. It is fully
configurable; everything you might want to change when using this
program to maintain some other FAQ than the Python FAQ is contained in
the configuration module, faqconf.py.
Note that this is not an executable script; it's an importable module.
The actual script in cgi-bin minimal; it's appended at the end of this
file as a string literal.
1997-05-25 21:07:18 -03:00
1997-05-26 02:43:29 -03:00
"""
import sys, string, time, os, stat, regex, cgi, faqconf
from faqconf import * # This imports all uppercase names
1997-05-25 21:07:18 -03:00
class FileError:
def __init__(self, file):
self.file = file
class InvalidFile(FileError):
pass
1997-05-26 02:43:29 -03:00
class NoSuchSection(FileError):
def __init__(self, section):
FileError.__init__(self, NEWFILENAME %(section, 1))
self.section = section
1997-05-25 21:07:18 -03:00
class NoSuchFile(FileError):
def __init__(self, file, why=None):
FileError.__init__(self, file)
self.why = why
1997-05-26 02:43:29 -03:00
def replace(s, old, new):
try:
return string.replace(s, old, new)
except AttributeError:
return string.join(string.split(s, old), new)
def escape(s):
s = replace(s, '&', '&')
s = replace(s, '<', '&lt;')
s = replace(s, '>', '&gt')
return s
1997-05-25 21:07:18 -03:00
def escapeq(s):
s = escape(s)
1997-05-26 02:43:29 -03:00
s = replace(s, '"', '&quot;')
1997-05-25 21:07:18 -03:00
return s
1997-05-26 02:43:29 -03:00
def _interpolate(format, args, kw):
try:
quote = kw['_quote']
except KeyError:
quote = 1
d = (kw,) + args + (faqconf.__dict__,)
m = MagicDict(d, quote)
return format % m
def interpolate(format, *args, **kw):
return _interpolate(format, args, kw)
1997-05-25 21:07:18 -03:00
1997-05-26 02:43:29 -03:00
def emit(format, *args, **kw):
try:
f = kw['_file']
except KeyError:
f = sys.stdout
f.write(_interpolate(format, args, kw))
1997-05-25 21:07:18 -03:00
translate_prog = None
def translate(text):
global translate_prog
if not translate_prog:
url = '\(http\|ftp\)://[^ \t\r\n]*'
email = '\<[-a-zA-Z0-9._]+@[-a-zA-Z0-9._]+'
1997-05-26 02:43:29 -03:00
translate_prog = prog = regex.compile(url + '\|' + email)
1997-05-25 21:07:18 -03:00
else:
prog = translate_prog
i = 0
list = []
while 1:
j = prog.search(text, i)
if j < 0:
break
1997-05-26 02:43:29 -03:00
list.append(escape(text[i:j]))
1997-05-25 21:07:18 -03:00
i = j
url = prog.group(0)
1997-05-26 02:43:29 -03:00
while url[-1] in ');:,.?\'"':
1997-05-25 21:07:18 -03:00
url = url[:-1]
url = escape(url)
if ':' in url:
repl = '<A HREF="%s">%s</A>' % (url, url)
else:
repl = '<A HREF="mailto:%s">&lt;%s&gt;</A>' % (url, url)
list.append(repl)
i = i + len(url)
j = len(text)
1997-05-26 02:43:29 -03:00
list.append(escape(text[i:j]))
1997-05-25 21:07:18 -03:00
return string.join(list, '')
emphasize_prog = None
def emphasize(line):
global emphasize_prog
import regsub
if not emphasize_prog:
1997-05-26 02:43:29 -03:00
pat = '\*\([a-zA-Z]+\)\*'
emphasize_prog = regex.compile(pat)
return regsub.gsub(emphasize_prog, '<I>\\1</I>', line)
1997-05-25 21:07:18 -03:00
def load_cookies():
if not os.environ.has_key('HTTP_COOKIE'):
return {}
raw = os.environ['HTTP_COOKIE']
words = map(string.strip, string.split(raw, ';'))
cookies = {}
for word in words:
i = string.find(word, '=')
if i >= 0:
key, value = word[:i], word[i+1:]
cookies[key] = value
return cookies
def load_my_cookie():
cookies = load_cookies()
try:
1997-05-26 02:43:29 -03:00
value = cookies[COOKIE_NAME]
1997-05-25 21:07:18 -03:00
except KeyError:
return {}
import urllib
value = urllib.unquote(value)
words = string.split(value, '/')
while len(words) < 3:
words.append('')
author = string.join(words[:-2], '/')
email = words[-2]
password = words[-1]
return {'author': author,
'email': email,
'password': password}
1997-05-26 02:43:29 -03:00
def send_my_cookie(ui):
name = COOKIE_NAME
value = "%s/%s/%s" % (ui.author, ui.email, ui.password)
import urllib
value = urllib.quote(value)
now = time.time()
then = now + COOKIE_LIFETIME
gmt = time.gmtime(then)
print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value),
print time.strftime("expires=%a, %d-%b-%x %X GMT", gmt)
class MagicDict:
1997-05-25 21:07:18 -03:00
1997-05-26 02:43:29 -03:00
def __init__(self, d, quote):
1997-05-25 21:07:18 -03:00
self.__d = d
1997-05-26 02:43:29 -03:00
self.__quote = quote
1997-05-25 21:07:18 -03:00
def __getitem__(self, key):
for d in self.__d:
try:
value = d[key]
if value:
1997-05-26 02:43:29 -03:00
value = str(value)
if self.__quote:
value = escapeq(value)
1997-05-25 21:07:18 -03:00
return value
except KeyError:
pass
1997-05-26 02:43:29 -03:00
return ''
1997-05-25 21:07:18 -03:00
class UserInput:
def __init__(self):
self.__form = cgi.FieldStorage()
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError
try:
value = self.__form[name].value
except (TypeError, KeyError):
value = ''
else:
value = string.strip(value)
setattr(self, name, value)
return value
def __getitem__(self, key):
return getattr(self, key)
1997-05-26 02:43:29 -03:00
class FaqEntry:
def __init__(self, fp, file, sec_num):
self.file = file
self.sec, self.num = sec_num
if fp:
import rfc822
self.__headers = rfc822.Message(fp)
self.body = string.strip(fp.read())
else:
self.__headers = {'title': "%d.%d. " % sec_num}
self.body = ''
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError
key = string.join(string.split(name, '_'), '-')
try:
value = self.__headers[key]
except KeyError:
value = ''
setattr(self, name, value)
return value
1997-05-25 21:07:18 -03:00
1997-05-26 02:43:29 -03:00
def __getitem__(self, key):
return getattr(self, key)
def load_version(self):
command = interpolate(SH_RLOG_H, self)
p = os.popen(command)
version = ''
while 1:
line = p.readline()
if not line:
break
if line[:5] == 'head:':
version = string.strip(line[5:])
p.close()
self.version = version
1997-05-25 21:07:18 -03:00
def show(self, edit=1):
1997-05-26 02:43:29 -03:00
emit(ENTRY_HEADER, self)
1997-05-25 21:07:18 -03:00
pre = 0
1997-05-26 02:43:29 -03:00
for line in string.split(self.body, '\n'):
1997-05-25 21:07:18 -03:00
if not string.strip(line):
if pre:
print '</PRE>'
pre = 0
else:
print '<P>'
else:
if line[0] not in string.whitespace:
if pre:
print '</PRE>'
pre = 0
else:
if not pre:
print '<PRE>'
pre = 1
if '/' in line or '@' in line:
line = translate(line)
elif '<' in line or '&' in line:
line = escape(line)
if not pre and '*' in line:
line = emphasize(line)
print line
if pre:
print '</PRE>'
pre = 0
if edit:
print '<P>'
1997-05-26 02:43:29 -03:00
emit(ENTRY_FOOTER, self)
if self.last_changed_date:
emit(ENTRY_LOGINFO, self)
1997-05-25 21:07:18 -03:00
print '<P>'
class FaqDir:
entryclass = FaqEntry
1997-05-26 02:43:29 -03:00
__okprog = regex.compile(OKFILENAME)
1997-05-25 21:07:18 -03:00
def __init__(self, dir=os.curdir):
self.__dir = dir
self.__files = None
def __fill(self):
if self.__files is not None:
return
self.__files = files = []
okprog = self.__okprog
for file in os.listdir(self.__dir):
if okprog.match(file) >= 0:
files.append(file)
files.sort()
def good(self, file):
return self.__okprog.match(file) >= 0
def parse(self, file):
if not self.good(file):
return None
sec, num = self.__okprog.group(1, 2)
return string.atoi(sec), string.atoi(num)
def roulette(self):
self.__fill()
import whrandom
return whrandom.choice(self.__files)
def list(self):
# XXX Caller shouldn't modify result
self.__fill()
return self.__files
def open(self, file):
sec_num = self.parse(file)
if not sec_num:
raise InvalidFile(file)
try:
fp = open(file)
except IOError, msg:
raise NoSuchFile(file, msg)
try:
return self.entryclass(fp, file, sec_num)
finally:
fp.close()
def show(self, file, edit=1):
self.open(file).show(edit=edit)
1997-05-26 02:43:29 -03:00
def new(self, section):
if not SECTION_TITLES.has_key(section):
raise NoSuchSection(section)
maxnum = 0
for file in self.list():
sec, num = self.parse(file)
if sec == section:
maxnum = max(maxnum, num)
sec_num = (section, maxnum+1)
file = NEWFILENAME % sec_num
return self.entryclass(None, file, sec_num)
1997-05-25 21:07:18 -03:00
class FaqWizard:
def __init__(self):
self.ui = UserInput()
self.dir = FaqDir()
def go(self):
1997-05-26 02:43:29 -03:00
print 'Content-type: text/html'
req = self.ui.req or 'home'
1997-05-25 21:07:18 -03:00
mname = 'do_%s' % req
try:
meth = getattr(self, mname)
except AttributeError:
1997-05-26 02:43:29 -03:00
self.error("Bad request type %s." % `req`)
1997-05-25 21:07:18 -03:00
else:
try:
meth()
except InvalidFile, exc:
self.error("Invalid entry file name %s" % exc.file)
except NoSuchFile, exc:
self.error("No entry with file name %s" % exc.file)
1997-05-26 02:43:29 -03:00
except NoSuchSection, exc:
self.error("No section number %s" % exc.section)
1997-05-25 21:07:18 -03:00
self.epilogue()
def error(self, message, **kw):
1997-05-26 02:43:29 -03:00
self.prologue(T_ERROR)
emit(message, kw)
1997-05-25 21:07:18 -03:00
def prologue(self, title, entry=None, **kw):
1997-05-26 02:43:29 -03:00
emit(PROLOGUE, entry, kwdict=kw, title=escape(title))
1997-05-25 21:07:18 -03:00
def epilogue(self):
1997-05-26 02:43:29 -03:00
emit(EPILOGUE)
1997-05-25 21:07:18 -03:00
def do_home(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_HOME)
emit(HOME)
def do_debug(self):
self.prologue("FAQ Wizard Debugging")
form = cgi.FieldStorage()
cgi.print_form(form)
cgi.print_environ(os.environ)
cgi.print_directory()
cgi.print_arguments()
1997-05-25 21:07:18 -03:00
def do_search(self):
query = self.ui.query
if not query:
1997-05-26 02:43:29 -03:00
self.error("Empty query string!")
1997-05-25 21:07:18 -03:00
return
1997-05-26 02:43:29 -03:00
self.prologue(T_SEARCH)
if self.ui.querytype != 'regex':
for c in '\\.[]?+^$*':
if c in query:
query = replace(query, c, '\\'+c)
if self.ui.casefold == 'no':
1997-05-25 21:07:18 -03:00
p = regex.compile(query)
else:
p = regex.compile(query, regex.casefold)
hits = []
for file in self.dir.list():
try:
entry = self.dir.open(file)
except FileError:
constants
if p.search(entry.title) >= 0 or p.search(entry.body) >= 0:
hits.append(file)
if not hits:
1997-05-26 02:43:29 -03:00
emit(NO_HITS, self.ui, count=0)
elif len(hits) <= MAXHITS:
1997-05-25 21:07:18 -03:00
if len(hits) == 1:
1997-05-26 02:43:29 -03:00
emit(ONE_HIT, count=1)
1997-05-25 21:07:18 -03:00
else:
1997-05-26 02:43:29 -03:00
emit(FEW_HITS, count=len(hits))
1997-05-25 21:07:18 -03:00
self.format_all(hits)
else:
1997-05-26 02:43:29 -03:00
emit(MANY_HITS, count=len(hits))
1997-05-25 21:07:18 -03:00
self.format_index(hits)
def do_all(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_ALL)
1997-05-25 21:07:18 -03:00
files = self.dir.list()
self.last_changed(files)
self.format_all(files)
def do_compat(self):
files = self.dir.list()
1997-05-26 02:43:29 -03:00
emit(COMPAT)
1997-05-25 21:07:18 -03:00
self.last_changed(files)
self.format_all(files, edit=0)
sys.exit(0)
def last_changed(self, files):
latest = 0
for file in files:
try:
st = os.stat(file)
except os.error:
continue
mtime = st[stat.ST_MTIME]
if mtime > latest:
latest = mtime
1997-05-26 02:43:29 -03:00
print time.strftime(LAST_CHANGED,
1997-05-25 21:07:18 -03:00
time.localtime(time.time()))
def format_all(self, files, edit=1):
for file in files:
self.dir.show(file, edit=edit)
def do_index(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_INDEX)
self.format_index(self.dir.list(), add=1)
1997-05-25 21:07:18 -03:00
1997-05-26 02:43:29 -03:00
def format_index(self, files, add=0):
1997-05-25 21:07:18 -03:00
sec = 0
for file in files:
try:
entry = self.dir.open(file)
except NoSuchFile:
continue
if entry.sec != sec:
if sec:
1997-05-26 02:43:29 -03:00
if add:
emit(INDEX_ADDSECTION, sec=sec)
emit(INDEX_ENDSECTION, sec=sec)
1997-05-25 21:07:18 -03:00
sec = entry.sec
1997-05-26 02:43:29 -03:00
emit(INDEX_SECTION, sec=sec, title=SECTION_TITLES[sec])
emit(INDEX_ENTRY, entry)
1997-05-25 21:07:18 -03:00
if sec:
1997-05-26 02:43:29 -03:00
if add:
emit(INDEX_ADDSECTION, sec=sec)
emit(INDEX_ENDSECTION, sec=sec)
1997-05-25 21:07:18 -03:00
def do_recent(self):
if not self.ui.days:
days = 1
else:
days = string.atof(self.ui.days)
now = time.time()
try:
cutoff = now - days * 24 * 3600
except OverflowError:
cutoff = 0
list = []
for file in self.dir.list():
try:
st = os.stat(file)
except os.error:
continue
mtime = st[stat.ST_MTIME]
if mtime >= cutoff:
list.append((mtime, file))
list.sort()
list.reverse()
1997-05-26 02:43:29 -03:00
self.prologue(T_RECENT)
1997-05-25 21:07:18 -03:00
if days <= 1:
period = "%.2g hours" % (days*24)
else:
period = "%.6g days" % days
if not list:
1997-05-26 02:43:29 -03:00
emit(NO_RECENT, period=period)
1997-05-25 21:07:18 -03:00
elif len(list) == 1:
1997-05-26 02:43:29 -03:00
emit(ONE_RECENT, period=period)
1997-05-25 21:07:18 -03:00
else:
1997-05-26 02:43:29 -03:00
emit(SOME_RECENT, period=period, count=len(list))
1997-05-25 21:07:18 -03:00
self.format_all(map(lambda (mtime, file): file, list))
1997-05-26 02:43:29 -03:00
emit(TAIL_RECENT)
1997-05-25 21:07:18 -03:00
def do_roulette(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_ROULETTE)
1997-05-25 21:07:18 -03:00
file = self.dir.roulette()
self.dir.show(file)
def do_help(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_HELP)
emit(HELP)
1997-05-25 21:07:18 -03:00
def do_show(self):
entry = self.dir.open(self.ui.file)
1997-05-26 02:43:29 -03:00
self.prologue(T_SHOW)
1997-05-25 21:07:18 -03:00
entry.show()
def do_add(self):
self.prologue(T_ADD)
1997-05-26 02:43:29 -03:00
emit(ADD_HEAD)
sections = SECTION_TITLES.items()
sections.sort()
for section, title in sections:
emit(ADD_SECTION, section=section, title=title)
emit(ADD_TAIL)
1997-05-25 21:07:18 -03:00
def do_delete(self):
self.prologue(T_DELETE)
1997-05-26 02:43:29 -03:00
emit(DELETE)
1997-05-25 21:07:18 -03:00
def do_log(self):
entry = self.dir.open(self.ui.file)
1997-05-26 02:43:29 -03:00
self.prologue(T_LOG, entry)
emit(LOG, entry)
self.rlog(interpolate(SH_RLOG, entry), entry)
1997-05-25 21:07:18 -03:00
def rlog(self, command, entry=None):
output = os.popen(command).read()
1997-05-26 02:43:29 -03:00
sys.stdout.write('<PRE>')
1997-05-25 21:07:18 -03:00
athead = 0
1997-05-26 02:43:29 -03:00
lines = string.split(output, '\n')
1997-05-25 21:07:18 -03:00
while lines and not lines[-1]:
del lines[-1]
if lines:
line = lines[-1]
if line[:1] == '=' and len(line) >= 40 and \
line == line[0]*len(line):
del lines[-1]
for line in lines:
if entry and athead and line[:9] == 'revision ':
rev = string.strip(line[9:])
1997-05-26 02:43:29 -03:00
if rev != '1.1':
emit(DIFFLINK, entry, rev=rev, line=line)
1997-05-25 21:07:18 -03:00
else:
print line
athead = 0
else:
athead = 0
if line[:1] == '-' and len(line) >= 20 and \
line == len(line) * line[0]:
athead = 1
1997-05-26 02:43:29 -03:00
sys.stdout.write('<HR>')
1997-05-25 21:07:18 -03:00
else:
print line
1997-05-26 02:43:29 -03:00
print '</PRE>'
1997-05-25 21:07:18 -03:00
def do_diff(self):
entry = self.dir.open(self.ui.file)
rev = self.ui.rev
r = regex.compile(
1997-05-26 02:43:29 -03:00
'^\([1-9][0-9]?[0-9]?\)\.\([1-9][0-9]?[0-9]?[0-9]?\)$')
1997-05-25 21:07:18 -03:00
if r.match(rev) < 0:
1997-05-26 02:43:29 -03:00
self.error("Invalid revision number: %s." % `rev`)
1997-05-25 21:07:18 -03:00
[major, minor] = map(string.atoi, r.group(1, 2))
if minor == 1:
1997-05-26 02:43:29 -03:00
self.error("No previous revision.")
1997-05-25 21:07:18 -03:00
return
1997-05-26 02:43:29 -03:00
prev = '%d.%d' % (major, minor-1)
self.prologue(T_DIFF, entry)
self.shell(interpolate(SH_RDIFF, entry, rev=rev, prev=prev))
1997-05-25 21:07:18 -03:00
def shell(self, command):
output = os.popen(command).read()
1997-05-26 02:43:29 -03:00
sys.stdout.write('<PRE>')
1997-05-25 21:07:18 -03:00
print escape(output)
1997-05-26 02:43:29 -03:00
print '</PRE>'
1997-05-25 21:07:18 -03:00
def do_new(self):
1997-05-26 02:43:29 -03:00
entry = self.dir.new(section=string.atoi(self.ui.section))
entry.version = '*new*'
self.prologue(T_EDIT)
emit(EDITHEAD)
emit(EDITFORM1, entry, editversion=entry.version)
emit(EDITFORM2, entry, load_my_cookie())
emit(EDITFORM3)
entry.show(edit=0)
1997-05-25 21:07:18 -03:00
def do_edit(self):
entry = self.dir.open(self.ui.file)
entry.load_version()
1997-05-26 02:43:29 -03:00
self.prologue(T_EDIT)
emit(EDITHEAD)
emit(EDITFORM1, entry, editversion=entry.version)
emit(EDITFORM2, entry, load_my_cookie())
emit(EDITFORM3)
1997-05-25 21:07:18 -03:00
entry.show(edit=0)
def do_review(self):
1997-05-26 02:43:29 -03:00
send_my_cookie(self.ui)
if self.ui.editversion == '*new*':
sec, num = self.dir.parse(self.ui.file)
entry = self.dir.new(section=sec)
entry.version = "*new*"
if entry.file != self.ui.file:
self.error("Commit version conflict!")
emit(NEWCONFLICT, self.ui, sec=sec, num=num)
return
else:
entry = self.dir.open(self.ui.file)
entry.load_version()
1997-05-25 21:07:18 -03:00
# Check that the FAQ entry number didn't change
if string.split(self.ui.title)[:1] != string.split(entry.title)[:1]:
1997-05-26 02:43:29 -03:00
self.error("Don't change the entry number please!")
1997-05-25 21:07:18 -03:00
return
# Check that the edited version is the current version
if entry.version != self.ui.editversion:
1997-05-26 02:43:29 -03:00
self.error("Commit version conflict!")
emit(VERSIONCONFLICT, entry, self.ui)
1997-05-25 21:07:18 -03:00
return
1997-05-26 02:43:29 -03:00
commit_ok = ((not PASSWORD
or self.ui.password == PASSWORD)
1997-05-25 21:07:18 -03:00
and self.ui.author
and '@' in self.ui.email
and self.ui.log)
if self.ui.commit:
if not commit_ok:
self.cantcommit()
else:
1997-05-26 02:43:29 -03:00
self.commit(entry)
1997-05-25 21:07:18 -03:00
return
1997-05-26 02:43:29 -03:00
self.prologue(T_REVIEW)
emit(REVIEWHEAD)
1997-05-25 21:07:18 -03:00
entry.body = self.ui.body
entry.title = self.ui.title
entry.show(edit=0)
1997-05-26 02:43:29 -03:00
emit(EDITFORM1, self.ui, entry)
1997-05-25 21:07:18 -03:00
if commit_ok:
1997-05-26 02:43:29 -03:00
emit(COMMIT)
1997-05-25 21:07:18 -03:00
else:
1997-05-26 02:43:29 -03:00
emit(NOCOMMIT)
emit(EDITFORM2, self.ui, entry, load_my_cookie())
emit(EDITFORM3)
1997-05-25 21:07:18 -03:00
def cantcommit(self):
1997-05-26 02:43:29 -03:00
self.prologue(T_CANTCOMMIT)
print CANTCOMMIT_HEAD
1997-05-25 21:07:18 -03:00
if not self.ui.passwd:
1997-05-26 02:43:29 -03:00
emit(NEED_PASSWD)
1997-05-25 21:07:18 -03:00
if not self.ui.log:
1997-05-26 02:43:29 -03:00
emit(NEED_LOG)
1997-05-25 21:07:18 -03:00
if not self.ui.author:
1997-05-26 02:43:29 -03:00
emit(NEED_AUTHOR)
1997-05-25 21:07:18 -03:00
if not self.ui.email:
1997-05-26 02:43:29 -03:00
emit(NEED_EMAIL)
print CANTCOMMIT_TAIL
def commit(self, entry):
file = entry.file
# Normalize line endings in body
if '\r' in self.ui.body:
import regsub
self.ui.body = regsub.gsub('\r\n?', '\n', self.ui.body)
# Normalize whitespace in title
self.ui.title = string.join(string.split(self.ui.title))
# Check that there were any changes
1997-05-25 21:07:18 -03:00
if self.ui.body == entry.body and self.ui.title == entry.title:
1997-05-26 02:43:29 -03:00
self.error("You didn't make any changes!")
1997-05-25 21:07:18 -03:00
return
# XXX Should lock here
try:
os.unlink(file)
except os.error:
pass
try:
1997-05-26 02:43:29 -03:00
f = open(file, 'w')
1997-05-25 21:07:18 -03:00
except IOError, why:
1997-05-26 02:43:29 -03:00
self.error(CANTWRITE, file=file, why=why)
1997-05-25 21:07:18 -03:00
return
date = time.ctime(time.time())
1997-05-26 02:43:29 -03:00
emit(FILEHEADER, self.ui, os.environ, date=date, _file=f, _quote=0)
f.write('\n')
1997-05-25 21:07:18 -03:00
f.write(self.ui.body)
1997-05-26 02:43:29 -03:00
f.write('\n')
1997-05-25 21:07:18 -03:00
f.close()
import tempfile
tfn = tempfile.mktemp()
1997-05-26 02:43:29 -03:00
f = open(tfn, 'w')
emit(LOGHEADER, self.ui, os.environ, date=date, _file=f)
1997-05-25 21:07:18 -03:00
f.close()
command = interpolate(
1997-05-26 02:43:29 -03:00
SH_LOCK + '\n' + SH_CHECKIN,
1997-05-25 21:07:18 -03:00
file=file, tfn=tfn)
p = os.popen(command)
output = p.read()
sts = p.close()
# XXX Should unlock here
if not sts:
1997-05-26 02:43:29 -03:00
self.prologue(T_COMMITTED)
emit(COMMITTED)
1997-05-25 21:07:18 -03:00
else:
1997-05-26 02:43:29 -03:00
self.error(T_COMMITFAILED)
emit(COMMITFAILED, sts=sts)
print '<PRE>%s</PRE>' % escape(output)
1997-05-25 21:07:18 -03:00
try:
os.unlink(tfn)
except os.error:
pass
entry = self.dir.open(file)
entry.show()
wiz = FaqWizard()
wiz.go()
1997-05-26 02:43:29 -03:00
# This bootstrap script should be placed in your cgi-bin directory.
# You only need to edit the first two lines: change
# /usr/local/bin/python to where your Python interpreter lives change
# the value for FAQDIR to where your FAQ lives. The faqwiz.py and
# faqconf.py files should live there, too.
1997-05-25 21:07:18 -03:00
BOOTSTRAP = """\
#! /usr/local/bin/python
FAQDIR = "/usr/people/guido/python/FAQ"
1997-05-26 02:43:29 -03:00
import sys, os
1997-05-25 21:07:18 -03:00
os.chdir(FAQDIR)
sys.path.insert(0, FAQDIR)
1997-05-26 02:43:29 -03:00
import faqwiz
1997-05-25 21:07:18 -03:00
"""