1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
#!/usr/bin/env python
"""Test script which generates the online documentation for HTMLgen.
"""
import string, re, os, time, glob
from HTMLcolors import *
from HTMLgen import *
import HTMLgen #only so I can pick off the __version__
__version__ = '$Id: HTMLtest.py,v 1.2 1998/04/26 17:55:50 friedric Exp $'
htmldir = './html'
datadir = './data'
doctitle = 'HTMLgen %s Online Documentation' % HTMLgen.__version__
try:
os.mkdir('html')
except os.error:
pass
def test():
# build_pages list is defined at the bottom of this file
# to pick up the following function objects.
t = time.clock()
for i in range(1, len(build_pages)-1):
build_pages[i][1](build_pages[i][0], # current filename
build_pages[i-1][0], # previous filename
build_pages[i+1][0], # next filename
'overview.html') # manual top
#leaving out a HOME button
import colorcube
colorcube.main(os.path.join(htmldir, 'colorcube.html'))
print 'Time to generate pages:', time.clock() - t, 'seconds'
def overview(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Overview'
doc.banner = ('../image/HTMLgen_banner.jpg')
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'overview-txt.html'))
doc.write(os.path.join(htmldir, filename))
def document(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Document Objects'
doc.banner = ('../image/document.gif', 472, 40)
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'document-txt.html'))
doc.write(os.path.join(htmldir, filename))
def lists(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Lists'
doc.banner = ('../image/lists.gif', 472, 40)
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'lists-txt.html'))
doc.append(HR())
nlist = ['Items',['First Item', 'Second Item',['SubitemA','SubitemB'], 'Third Item'], 'More']
doc.append('The following section just exercises most of the markup classes.')
ilist = [(Image('../image/purple_dot.gif'), Bold('Purple')),
(Image('../image/orange_dot.gif'), Bold('Orange')),
(Image('../image/red_dot.gif'), Bold('Red')),
(Image('../image/blue_dot.gif'), Bold('Blue')),
(Image('../image/green_dot.gif'), Bold('Green')),
(Image('../image/yellow_dot.gif'), Bold('Yellow')) ]
doc.append(Heading(3, 'List class'))
olist = OrderedList(type='I', columns=2, bgcolor="#DDDDDD")
olist.append('First item in the OrderedList (ImageBulletList)',
ImageBulletList(ilist),
'Second item in the OrderedList',
List(nlist))
doc.append(olist)
sample = """"Don't play dumb. You're not as good at it as I am.": Colonel Flagg - M*A*S*H"""
list = DefinitionList( [
('This should be initial upper caps', InitialCaps('Initial Upper Capital Letters')),
('This is normal Text with >< & escaped.', Text('<&>'+sample)),
('This is Blockquote markup.', Blockquote(sample)),
('This is red text.', Font(sample, color=RED)),
('This is Address markup.', Address(sample)),
('This is Emphasis markup.', Emphasis(sample)),
('This is Cite markup.', Cite(sample)),
('This is KBD markup.', KBD(sample)),
('This is Sample markup.', Sample(sample)),
('This is Code markup.', Code(sample)),
('This is Define markup.', Define(sample)),
('This is Var markup.', Var(sample)) ] )
doc.append(list)
doc.write(os.path.join(htmldir, filename))
def frames(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Frames'
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.banner = ('../image/frames.gif', 472, 40)
doc.append_file(os.path.join(datadir, 'frames-txt.html'))
doc.write(os.path.join(htmldir, 'top-'+filename))
f1 = Frame(name='top', src='top-'+filename)
f2 = Frame(name='bottom', src='./parrot.html')
fs = Frameset(f1, f2, rows='50%,50%')
fdoc = FramesetDocument()
fdoc.append(fs)
fdoc.write(os.path.join(htmldir, filename))
def chart(filename, aft=None, fore=None, top=None, home=None):
"""exercises the barchart module"""
import barchart
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Tables'
doc.banner = ('../image/tables.gif', 472, 40)
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'tables-txt.html'))
doc.append(HR())
dum = [ ('fddo4', 1318), ('cn1', 1472), ('cn2', 1411),
('fddo3', 1280), ('asc8', 1371), ('orb3', 1390),
('fddo1', 1418), ('asc4', 1292), ('dn2', 1381),
('fddo2', 1341), ('asc1', 1352), ('dn1', 1441) ]
dummydata = barchart.DataList()
dummydata.load_tuples(dum)
dummydata.sort()
b = barchart.BarChart(dummydata)
b.label_shade = AQUA
b.thresholds = (1300, 1400)
b.title = "System Throughput (jobs/week)"
doc.append(b)
doc.append(Pre(str(dummydata)))
doc.append(HR())
dum = [ ('fddo4', 1318, 456, 235, 290),
('fddo3', 1280, 560, 129, 295),
('fddo1', 1418, 1201, 490, 125),
('fddo2', 1341, 810, 466, 203) ]
dummydata = barchart.DataList()
dummydata.segment_names = ('User','System','I/O','Wait')
dummydata.load_tuples(dum)
dummydata.sort()
b = barchart.StackedBarChart(dummydata)
b.label_shade = AQUA
b.title = "System Load"
doc.append(b)
doc.append(Pre(str(dummydata)))
doc.write(os.path.join(htmldir, filename))
def forms(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc', banner=('../image/forms.gif', 472, 40))
doc.title = doctitle
doc.subtitle = 'Forms'
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'forms-txt.html'))
doc.append(HR())
folders = ('.','html')
F = Form('http://hoohoo.ncsa.uiuc.edu/cgi-bin/post-query')
for folder in folders:
files = os.listdir(folder)
J = Select(files, name=folder, size=4, multiple=1)
F.append(J)
F.append(Select(files[:10], name='Popup', size=1))
F.append(Textarea('You may send stuff in here.'))
F.append(P())
for item in ('pick me','no, pick me!', 'forget them, pick me!!'):
radio = Input(type='radio', name='rad', rlabel=item)
F.append(radio, BR())
F.append(P())
for item in ('Pepperoni','Sausage','Extra Cheese'):
check = Input(type='checkbox', name='CB', rlabel=item)
F.append(check, BR())
F.append(Input(type='password', name='pw', llabel='Password'), P())
F.append(Input(type='file', name='text'))
F.submit = Input(type='submit', value='Fire off to the server')
doc.append(F)
doc.write(os.path.join(htmldir, filename))
def imagemaps(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Imagemaps'
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.banner = ('../image/imapbanner.gif', 472, 40)
doc.append_file(os.path.join(datadir, 'imagemaps-txt.html'))
doc.append(HR())
doc.append(H(3, 'Moving the mouse pointer over the numbered areas should\
make Netscape show a URL name numbered accordingly.'))
a1 = Area(coords='0,0,50,50', href='a1.html')
a2 = Area(coords='0,50,50,100', href='a2.html')
a3 = Area(coords='0,100,50,150', href='a3.html')
a4 = Area(coords='0,150,50,200', href='a4.html')
a5 = Area(coords='0,200,50,250', href='a5.html')
csmap = Map(name='rect', areas=(a1,a2,a3,a4,a5))
csimage = Image('../image/csmap_rect.gif', usemap='#rect')
doc.append(csimage, csmap)
a1 = Area(shape='circle', coords='50,25,25', href='a1.html')
a2 = Area(shape='circle', coords='100,25,25', href='a2.html')
a3 = Area(shape='circle', coords='150,25,25', href='a3.html')
a4 = Area(shape='circle', coords='200,25,25', href='a4.html')
a5 = Area(shape='circle', coords='250,25,25', href='a5.html')
csmap = Map(name='circle', areas=(a1,a2,a3,a4,a5))
csimage = Image('../image/csmap_circle.gif', usemap='#circle', align='top')
doc.append(csimage, csmap)
doc.write(os.path.join(htmldir, filename))
def scripts(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.title = doctitle
doc.subtitle = 'Embedded Scripts'
doc.banner = ('../image/scripts.gif', 472, 40)
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.append_file(os.path.join(datadir, 'scripts-txt.html'))
doc.write(os.path.join(htmldir, filename))
def sample1(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.background = '../image/texturec.jpg'
doc.banner = ('../image/historic.gif', 472, 60)
doc.author = '1776 Thomas Jefferson'
doc.email = 'jefferson@montecello.virginia.gov'
doc.logo = ('../image/eagle21.gif', 64, 54)
# parse Declaration of Independence
re_hline = re.compile('^--+$')
re_title = re.compile('^Title:\(.*$\)')
font2 = Font(size='+2')
s = open(os.path.join(datadir, 'DoI.txt')).read()
paragraphs = re.split(s, '\n\([\t ]*\n\)+')
for para in paragraphs:
if not para: continue
if re_title.search(para) > -1:
doc.title = re_title.group(1)
elif re_hline.search(para) > -1:
doc.append(HR())
else:
p = Paragraph( para )
# using \` to match beginning of paragraph
# ^ won't work because it'll match all the newlines
n = p.markup('\`\(\w\)', font2, reg_type='regex')
doc.append(p)
doc.write(os.path.join(htmldir, filename))
def sample2(filename, aft=None, fore=None, top=None, home=None):
doc = SeriesDocument('HTMLgen.rc')
doc.goprev,doc.gonext,doc.gotop,doc.gohome = aft,fore,top,home
doc.author = '1969 Montgomery Python'
doc.email = 'cleese@bbc.co.uk'
doc.banner = ('../image/silywalk2.gif', 450, 110)
doc.bgcolor = PURPLE
doc.title = "It's..."
doc.subtitle = 'The Dead Parrot Sketch'
#Ok parse that file
f = open(mpath(os.path.join(datadir, 'parrot.txt')))
line = f.readline()
re_dialog = re.compile('\(^[OC].*:\)\(.*\)')
while line:
if re_dialog.search(line) > -1:
role, prose = re_dialog.group(1,2)
if role[0]=='C': role = 'Customer: '
if role[0]=='O': role = 'Owner: '
doc.append(BR(), Strong(role), ' ')
doc.append(prose)
else:
doc.append(' ', line)
line = f.readline()
f.close()
doc.append(P(), Image('../image/parrot4.gif', width=169, height=104))
doc.write(os.path.join(htmldir, filename))
################################
# define the pages which are to be generated by the test function
pages = [ ('overview.html', overview),
('document.html', document),
('lists.html', lists),
('frames.html', frames),
('tables.html', chart),
('forms.html', forms),
('imagemaps.html', imagemaps),
('scripts.html', scripts),
('independence.html', sample1),
('parrot.html', sample2) ]
build_pages = [(None, None)] + pages + [(None, None)]
#################################
if __name__ == '__main__': test()
|