- Timestamp:
- Nov 12, 2007, 3:53:45 AM (17 years ago)
- Location:
- trunk/web/templates
- Files:
-
- 1 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/templates/Makefile
r205 r235 1 TEMPLATES= functions.tmpl skeleton.tmpl1 TEMPLATES=$(wildcard *.tmpl) 2 2 OUTPUTS=$(TEMPLATES:.tmpl=.py) 3 3 4 4 all: ${OUTPUTS} 5 5 6 ${OUTPUTS}:${TEMPLATES} 7 cheetah compile $^ 6 %.py: %.tmpl 7 cheetah compile $< 8 9 #${OUTPUTS}:${TEMPLATES} 10 # cheetah compile $^ 8 11 9 12 clean: -
trunk/web/templates/main.py
r228 r235 36 36 sys.path.append('/home/ecprice/.local/lib/python2.5/site-packages') 37 37 38 import templates 38 39 from Cheetah.Template import Template 39 40 from sipb_xen_database import Machine, CDROM, ctx, connect … … 41 42 from webcommon import InvalidInput, CodeError, g 42 43 import controls 44 45 class Checkpoint: 46 def __init__(self): 47 self.start_time = time.time() 48 self.checkpoints = [] 49 50 def checkpoint(self, s): 51 self.checkpoints.append((s, time.time())) 52 53 def __str__(self): 54 return ('Timing info:\n%s\n' % 55 '\n'.join(['%s: %s' % (d, t - self.start_time) for 56 (d, t) in self.checkpoints])) 57 58 checkpoint = Checkpoint() 59 43 60 44 61 def helppopup(subj): … … 99 116 d = dict(op=op, user=user, errorMessage=str(err), 100 117 stderr=emsg) 101 return Template(file='error.tmpl',searchList=[d])118 return templates.error(searchList=[d]) 102 119 103 120 def invalidInput(op, user, fields, err, emsg): … … 106 123 err_value=str(err.err_value), stderr=emsg, 107 124 errorMessage=str(err)) 108 return Template(file='invalid.tmpl',searchList=[d])125 return templates.invalid(searchList=[d]) 109 126 110 127 def hasVnc(status): … … 164 181 else: 165 182 d['new_machine'] = parsed_fields['name'] 166 return Template(file='list.tmpl',searchList=[d])183 return templates.list(searchList=[d]) 167 184 168 185 … … 170 187 machines = [m for m in Machine.select() 171 188 if validation.haveAccess(user, m)] 189 checkpoint.checkpoint('Got my machines') 172 190 on = {} 173 191 has_vnc = {} 174 192 on = g.uptimes 193 checkpoint.checkpoint('Got uptimes') 175 194 for m in machines: 176 195 m.uptime = g.uptimes.get(m) … … 183 202 max_memory = validation.maxMemory(user) 184 203 max_disk = validation.maxDisk(user) 204 checkpoint.checkpoint('Got max mem/disk') 185 205 defaults = Defaults(max_memory=max_memory, 186 206 max_disk=max_disk, 187 207 owner=user, 188 208 cdrom='gutsy-i386') 209 checkpoint.checkpoint('Got defaults') 189 210 d = dict(user=user, 190 211 cant_add_vm=validation.cantAddVm(user), … … 200 221 def listVms(user, fields): 201 222 """Handler for list requests.""" 223 checkpoint.checkpoint('Getting list dict') 202 224 d = getListDict(user) 203 return Template(file='list.tmpl', searchList=[d]) 225 checkpoint.checkpoint('Got list dict') 226 return templates.list(searchList=[d]) 204 227 205 228 def vnc(user, fields): … … 247 270 hostname=os.environ.get('SERVER_NAME', 'localhost'), 248 271 authtoken=token) 249 return Template(file='vnc.tmpl',searchList=[d])272 return templates.vnc(searchList=[d]) 250 273 251 274 def getNicInfo(data_dict, machine): … … 303 326 result = 'Success!' 304 327 if not back: 305 return Template(file='command.tmpl',searchList=[d])328 return templates.command(searchList=[d]) 306 329 if back == 'list': 307 330 g.clear() #Changed global state 308 331 d = getListDict(user) 309 332 d['result'] = result 310 return Template(file='list.tmpl',searchList=[d])333 return templates.list(searchList=[d]) 311 334 elif back == 'info': 312 335 machine = validation.testMachineId(user, fields.getfirst('machine_id')) 313 336 d = infoDict(user, machine) 314 337 d['result'] = result 315 return Template(file='info.tmpl', searchList=[d]) 316 else: 317 raise InvalidInput('back', back, 'Not a known back page.') 338 return templates.info(searchList=[d]) 339 else: 340 raise InvalidInput 341 ('back', back, 'Not a known back page.') 318 342 319 343 def modifyDict(user, fields): … … 384 408 setattr(info_dict['defaults'], field, fields.getfirst(field)) 385 409 info_dict['result'] = result 386 return Template(file='info.tmpl',searchList=[info_dict])410 return templates.info(searchList=[info_dict]) 387 411 388 412 … … 428 452 mapping=help_mapping) 429 453 430 return Template(file="help.tmpl",searchList=[d])454 return templates.help(searchList=[d]) 431 455 432 456 … … 436 460 def infoDict(user, machine): 437 461 status = controls.statusInfo(machine) 462 checkpoint.checkpoint('Getting status info') 438 463 has_vnc = hasVnc(status) 439 464 if status is None: … … 448 473 cpu_time_float = float(main_status.get('cpu_time', 0)) 449 474 cputime = datetime.timedelta(seconds=int(cpu_time_float)) 475 checkpoint.checkpoint('Status') 450 476 display_fields = """name uptime memory state cpu_weight on_reboot 451 477 on_poweroff on_crash on_xend_start on_xend_stop bootloader""".split() … … 498 524 pass 499 525 #fields.append((disp, None)) 500 max_mem = validation.maxMemory(user, machine) 526 527 checkpoint.checkpoint('Got fields') 528 529 530 max_mem = validation.maxMemory(user, machine, False) 531 checkpoint.checkpoint('Got mem') 501 532 max_disk = validation.maxDisk(user, machine) 502 533 defaults = Defaults() … … 504 535 setattr(defaults, name, getattr(machine, name)) 505 536 defaults.disk = "%0.2f" % (machine.disks[0].size/1024.) 537 checkpoint.checkpoint('Got defaults') 506 538 d = dict(user=user, 507 539 cdroms=CDROM.select(), … … 522 554 machine = validation.testMachineId(user, fields.getfirst('machine_id')) 523 555 d = infoDict(user, machine) 524 return Template(file='info.tmpl', searchList=[d]) 556 checkpoint.checkpoint('Got infodict') 557 return templates.info(searchList=[d]) 525 558 526 559 mapping = dict(list=listVms, … … 547 580 548 581 def main(operation, user, fields): 582 start_time = time.time() 549 583 fun = mapping.get(operation, badOperation) 550 584 … … 552 586 connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen') 553 587 try: 588 checkpoint.checkpoint('Before') 554 589 output = fun(u, fields) 590 checkpoint.checkpoint('After') 555 591 556 592 headers = dict(DEFAULT_HEADERS) … … 558 594 new_headers, output = output 559 595 headers.update(new_headers) 560 561 596 e = revertStandardError() 562 597 if e: 563 598 output.addError(e) 564 599 printHeaders(headers) 565 print output 600 output_string = str(output) 601 checkpoint.checkpoint('output as a string') 602 print output_string 603 print '<pre>%s</pre>' % checkpoint 566 604 except Exception, err: 567 605 if not fields.has_key('js'): … … 586 624 587 625 if __name__ == '__main__': 588 start_time = time.time()589 626 fields = cgi.FieldStorage() 590 627 u = getUser() … … 601 638 operation = 'list' 602 639 603 main(operation, u, fields) 604 640 #main(operation, u, fields) 641 import profile 642 profile.run('main(operation, u, fields)', 'log-'+operation) 643 -
trunk/web/templates/skeleton.tmpl
r228 r235 31 31 </head> 32 32 <body id="body"> 33 34 #if True 35 <div> 36 <p>We are in the process of modifying the service. Things likely will not work.</p> 37 </div> 38 #end if 33 39 34 40 <div id="err"> -
trunk/web/templates/validation.py
r234 r235 68 68 69 69 def haveAccess(user, machine): 70 """Return whether a user has admin strative access to a machine"""70 """Return whether a user has administrative access to a machine""" 71 71 if user == 'moo': 72 72 return True
Note: See TracChangeset
for help on using the changeset viewer.