Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2009, Zenoss Inc. 5 # 6 # This program is free software; you can redistribute it and/or modify it 7 # under the terms of the GNU General Public License version 2 as published by 8 # the Free Software Foundation. 9 # 10 # For complete information please visit: http://www.zenoss.com/oss/ 11 # 12 ########################################################################### 13 14 import time 15 16 from Products.Five.browser import BrowserView 17 from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile 18 from Products.Jobber.logfile import MESSAGE_MARKER, SEEK_END, EOF_MARKER 19 from Products.ZenUtils.Utils import is_browser_connection_open 2022 """ 23 Stream output from a job to the browser. 24 """7426 self.request.response.setHeader("Content-Type", "text/html") 27 self.request.response.write(""" 28 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" 29 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> 30 <html><body style="overflow-x:hidden;"><pre style=" 31 font-family:Monaco,monospace; 32 font-size:14px;">""") 33 self._stream() 34 self.request.response.write(""" </pre></body></html> """) 35 self.request.response.flush() 36 return self.request.response3739 log = self.context.getLog() 40 f = log.getFile() 41 offset = 0 42 f.seek(0, SEEK_END) 43 remaining = f.tell() 44 _wrote = False 45 # The while loop keeps the thread open, so check manually to see if 46 # the connection has been closed so we don't stream forever 47 while is_browser_connection_open(self.request): 48 for line in log.generate_lines(f, offset, remaining): 49 if line.startswith(EOF_MARKER): 50 return 51 self._write_line(line) 52 _wrote = True 53 if log.finished: 54 return 55 offset = f.tell() 56 f.seek(0, SEEK_END) 57 remaining = f.tell() - offset 58 del f 59 f = log.getFile() 60 if not _wrote: 61 time.sleep(0.1) 62 _wrote = False6365 if line.startswith(MESSAGE_MARKER): 66 line = """</pre><pre style=" 67 font-family:Monaco,monospace; 68 font-size:14px;color:blue">%s</pre> 69 <pre style=" 70 font-family:Monaco,monospace; 71 font-size:14px;">""" % line.lstrip(MESSAGE_MARKER) 72 self.request.response.write(line) 73 self.request.response.flush()76 """ 77 Show a log stream in an IFRAME. 78 """ 79 __call__ = ZopeTwoPageTemplateFile('joblogview.pt') 808982 return self.context.absolute_url_path() + '/logstream'8385 job = self.context.getJob() 86 type = job.getJobType() 87 description = job.getDescription() 88 return '%s "%s"' % (type, description)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu May 7 11:46:32 2009 | http://epydoc.sourceforge.net |