From: <bel...@us...> - 2003-02-27 00:44:44
|
Update of /cvsroot/btplusplus/BT++/src/WebServer In directory sc8-pr-cvs1:/tmp/cvs-serv25717/src/WebServer Modified Files: BTWebServer.py HTTPConfigFile.py Added Files: README.htmltmpl htmltmpl.py Log Message: HTML Templates for Torrent view and Log, ETA for Loaders --- NEW FILE: README.htmltmpl --- htmltmpl ======== A Python based templating engine for separation of code and HTML. To run the regression tests (recommended): python test.py To install the module: (become root) python setup.py install Documentation can be found in the 'doc' directory or at the homepage of this module: http://htmltmpl.sourceforge.net/ AUTHOR: Tomas Styblo, tr...@cp... LICENSE: GNU GPL (included in file "LICENSE") --- NEW FILE: htmltmpl.py --- """ A templating engine for separation of code and HTML. The documentation of this templating engine is separated to two parts: 1. Description of the templating language. 2. Documentation of classes and API of this module that provides a Python implementation of the templating language. All the documentation can be found in 'doc' directory of the distribution tarball or at the homepage of the engine. Latest versions of this module are also available at that website. You can use and redistribute this module under conditions of the GNU General Public License that can be found either at [ http://www.gnu.org/ ] or in file "LICENSE" contained in the distribution tarball of this module. [...1441 lines suppressed...] """ def __init__(self, error): """ Constructor. @hidden """ Exception.__init__(self, "Htmltmpl error: " + error) class PrecompiledError(Exception): """ This exception is _PRIVATE_ and non fatal. @hidden """ def __init__(self, template): """ Constructor. @hidden """ Exception.__init__(self, template) Index: BTWebServer.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/WebServer/BTWebServer.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BTWebServer.py 26 Feb 2003 01:12:05 -0000 1.2 --- BTWebServer.py 27 Feb 2003 00:44:40 -0000 1.3 *************** *** 3,7 **** from HTTPConfigFile import HTTPConfig from threading import Event ! from os import listdir, path, chdir, mkdir from TabTrans.LoaderManager import LoaderManager from urlparse import urlparse --- 3,7 ---- from HTTPConfigFile import HTTPConfig from threading import Event ! from os import listdir, path, chdir, mkdir, remove from TabTrans.LoaderManager import LoaderManager from urlparse import urlparse *************** *** 10,13 **** --- 10,14 ---- from time import sleep, localtime, strftime from BTConstants import * + from htmltmpl import TemplateManager, TemplateProcessor import socket *************** *** 83,86 **** --- 84,97 ---- BTWait = Event() + try: + remove("WebTemplates/torrent.tmplc") + except: + pass + templateTorrent = TemplateManager().prepare("WebTemplates/torrent.tmpl") + try: + remove("WebTemplates/log.tmplc") + except: + pass + templateLog = TemplateManager().prepare("WebTemplates/log.tmpl") ########################################################################################################### *************** *** 92,96 **** def WebLogit(a, loglevel = LOG_INFO): if loglevel >= int(HTTPConfig.Get('Display', 'LogLevel')): ! WebLog.append(strftime("[%a, %d %b %Y %H:%M:%S]_", localtime()) + str(loglevel) + '_' + a) if len(WebLog) > int(HTTPConfig.Get('Display', 'LogCount')): WebLog.pop() --- 103,123 ---- def WebLogit(a, loglevel = LOG_INFO): if loglevel >= int(HTTPConfig.Get('Display', 'LogLevel')): ! log = {} ! log['TimeCode'] = strftime("[%a, %d %b %Y %H:%M:%S]", localtime()) ! log['LogLevel'] = loglevel ! log['LogLevelTrivial'] = false ! log['LogLevelInfo'] = false ! log['LogLevelError'] = false ! log['LogLevelCritical'] = false ! if loglevel == LOG_TRIVIAL: ! log['LogLevelTrivial'] = true ! elif loglevel == LOG_INFO: ! log['LogLevelInfo'] = true ! elif loglevel == LOG_ERROR: ! log['LogLevelError'] = true ! else: ! log['LogLevelCritical'] = true ! log['Entry'] = a ! WebLog.append( log ) if len(WebLog) > int(HTTPConfig.Get('Display', 'LogCount')): WebLog.pop() *************** *** 158,182 **** if self.requested == 'torrents': if result['command']=='Pause': ! if result['seed']=='0': BTHandler.Loaders[int(result['nr'])-1].PauseDownload() ! else: ! BTHandler.Seeds[int(result['nr'])-1].PauseDownload() elif result['command']=='Resume': ! if result['seed']=='0': BTHandler.Loaders[int(result['nr'])-1].StartDownload() ! else: ! BTHandler.Seeds[int(result['nr'])-1].StartDownload() elif result['command']=='MoveUp': c = int(result['nr']) ! if result['seed']=='0': ! BTHandler.Move(c-1, c-2) ! else: ! BTHandler.MoveSeed(c-1, c-2) elif result['command']=='MoveDown': c = int(result['nr']) ! if result['seed']=='0': ! BTHandler.Move(c-1, c) ! else: ! BTHandler.MoveSeed(c-1, c) elif result['command']=='Add': url = result['torr'] --- 185,209 ---- if self.requested == 'torrents': if result['command']=='Pause': ! # if result['seed']=='0': BTHandler.Loaders[int(result['nr'])-1].PauseDownload() ! # else: ! # BTHandler.Seeds[int(result['nr'])-1].PauseDownload() elif result['command']=='Resume': ! # if result['seed']=='0': BTHandler.Loaders[int(result['nr'])-1].StartDownload() ! # else: ! # BTHandler.Seeds[int(result['nr'])-1].StartDownload() elif result['command']=='MoveUp': c = int(result['nr']) ! # if result['seed']=='0': ! BTHandler.Move(c-1, c-2) ! # else: ! # BTHandler.MoveSeed(c-1, c-2) elif result['command']=='MoveDown': c = int(result['nr']) ! # if result['seed']=='0': ! BTHandler.Move(c-1, c) ! # else: ! # BTHandler.MoveSeed(c-1, c) elif result['command']=='Add': url = result['torr'] *************** *** 254,314 **** def send_torrents(self): ! ret = "<html>\n<head>\n<title>WebTorrent++ Download Status</title>\n" ! ret = ret + "<META HTTP-EQUIV=\"Refresh\" CONTENT=\""+HTTPConfig.Get('Display', 'Refresh')+"\">\n" ! ret = ret + "</head>\n<body bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrBackground') ! if BTHandler.Loaders: ! ret = ret + "<table border=1 width=100% cellpadding=3>\n<tr bgcolor=#DDDDDD><th colspan=2>Incomplete</th><th align=left>File</th><th>Size</th><th>Transfered</th><th>Speed</th><th>Status</th><th width=15%>Progress</th><th>Remaining</th></tr>\n" ! c = 0 ! for loader in BTHandler.Loaders: ! c = c + 1 ! if loader.IsFinished(): ! ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrFinished') ! if c <= Config.Get('Download', 'MaxSimDown'): ! ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrAuto') ! else: ! ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrNonAuto') ! if loader.Info['Status']!='Paused': ! cc = 'Pause' ! else: ! cc = 'Resume' ! ret = ret + "<form method=\"POST\" action=\"torrents\"><td>" ! ret = ret + "<button type=submit name=command value=%s>%s</button></td><td>" % (cc,cc) ! if c == 1: ! cc = 'DISABLED' ! else: ! cc = '' ! ret = ret + "<table><tr><td><button type=submit name=command %s value=MoveUp style=\"font-size:xx-small; font-weight:bold\">↑</button></td></tr>" % (cc) ! if c == len(BTHandler.Loaders): ! cc = 'DISABLED' ! else: ! cc = '' ! ret = ret + "<tr><td><button type=submit name=command %s value=MoveDown style=\"font-size:xx-small; font-weight:bold\">↓</button></td></tr></table>" % (cc) ! ret = ret + "<input type=hidden name=seed value=0><input type=hidden name=nr value=%d>" % (c) ! ret = ret + "</td></form>" ! ret = ret + "<td align=left>" + loader.Config['File'] + "</td>" ! ret = ret + "<td align=center>" + ('%.2f MB' % (loader.Config['Size'] / 1024 / 1024)) + "</td><td align=center>" ! if loader.Info['FractionDone'] == -1: ! ret = ret + '?' ! else: ! ret = ret + ('%.2f MB' % (loader.Info['FractionDone'] * loader.Config['Size'] / 1024 / 1024)) ! ret = ret + "</td><td align=center>" + ('%.1f / %.1f' % (loader.Info['SpeedDown'], loader.Info['SpeedUp'])) + "</td>" ! ret = ret + "<td align=center>" + loader.Info['Status'] ! ret = ret + "</td><td><table width=100% bordercolor=#0000BB border=1><tr><td><table width=100% height=100%><tr>" ! if loader.Info['Status']=='Hashing': ! c1='#FF0000' ! c2='#0000FF' ! else: ! c1='#00FF00' ! c2='#FF0000' ! if loader.Info['FractionDone'] == -1: ! ret = ret + '<td bgcolor=#0000FF width=100%> </td>' ! else: ! ret = ret + ('<td bgcolor=%s width=%d%%> </td><td bgcolor=%s width=%d%%> </td>' % (c1, loader.Info['FractionDone']*100, c2, loader.Info['FractionRemain']*100)) ! ret = ret + "</tr></table></td></tr></table></td>" ! ret = ret + ('<td align=center>%.1f%% [%.2f MB]</td>' % (loader.Info['FractionRemain'] * 100, loader.Info['FractionRemain'] * loader.Config['Size'] / 1024 / 1024)) ! ret = ret + "</tr>\n" ! ret = ret + "</table>\n" ! else: ! ret = ret + "<p> No Torrents" ## if BTHandler.Seeds: ## ret = ret + "<p><table border=1 width=100% cellpadding=3>\n<tr bgcolor=#DDDDDD><th colspan=2>Seeds</th><th align=left>File</th><th>Size</th><th>Status</th><th>Speed</th></tr>\n" --- 281,409 ---- def send_torrents(self): ! tproc = TemplateProcessor() ! tproc.set("refresh", str(HTTPConfig.Get('Display', 'Refresh'))) ! LoaderInfos = [] ! c = 0 ! for loader in BTHandler.Loaders: ! LoaderInfo = {} ! c = c + 1 ! if loader.Info['Status']!='Paused': ! LoaderInfo['Command'] = 'Pause' ! else: ! LoaderInfo['Command'] = 'Resume' ! LoaderInfo['FileName'] = loader.Config['File'] ! LoaderInfo['Status'] = loader.Info['Status'] ! LoaderInfo['Hashing'] = (loader.Info['Status']=='Hashing') ! LoaderInfo['Finished'] = loader.IsFinished() ! LoaderInfo['Auto'] = (c <= Config.Get('Download', 'MaxSimDown')) ! LoaderInfo['Preparing'] = (loader.Info['FractionDone'] == -1) ! LoaderInfo['PercentDone'] = '%d' % (loader.Info['FractionDone']*100) ! LoaderInfo['PercentLeft'] = '%d' % (loader.Info['FractionRemain']*100) ! LoaderInfo['PercentDonePrec'] = '%.1f' % (loader.Info['FractionDone']*100) ! LoaderInfo['PercentLeftPrec'] = '%.1f' % (loader.Info['FractionRemain']*100) ! LoaderInfo['FileSize'] = '%.2f MB' % (loader.Config['Size'] / 1024 / 1024) ! if loader.Info['FractionDone'] == -1: ! LoaderInfo['FileSizeDone'] = '?' ! LoaderInfo['FileSizeLeft'] = LoaderInfo['FileSize'] ! else: ! LoaderInfo['FileSizeDone'] = ('%.2f MB' % (loader.Info['FractionDone'] * loader.Config['Size'] / 1024 / 1024)) ! LoaderInfo['FileSizeLeft'] = ('%.2f MB' % (loader.Info['FractionRemain'] * loader.Config['Size'] / 1024 / 1024)) ! LoaderInfo['SpeedDown'] = '%.1f' % loader.Info['SpeedDown'] ! LoaderInfo['SpeedUp'] = '%.1f' % loader.Info['SpeedUp'] ! LoaderInfo['ETA'] = loader.Info['ETA'] ! LoaderInfos.append(LoaderInfo) ! tproc.set("Loaders", LoaderInfos) ! self.wfile.write(tproc.process(templateTorrent)) ! ! ! ## ret = "<html>\n<head>\n<title>WebTorrent++ Download Status</title>\n" ! ## ret = ret + "<META HTTP-EQUIV=\"Refresh\" CONTENT=\""+HTTPConfig.Get('Display', 'Refresh')+"\">\n" ! ## ret = ret + "</head>\n<body bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrBackground') ! ## if BTHandler.Loaders: ! ## ret = ret + "<table border=1 width=100% cellpadding=3>\n<tr bgcolor=#DDDDDD><th colspan=2>Incomplete</th><th align=left>File</th><th>Size</th><th>Transfered</th><th>Speed</th><th>Status</th><th width=15%>Progress</th><th>Remaining</th></tr>\n" ! ## c = 0 ! ## for loader in BTHandler.Loaders: ! ## c = c + 1 ! ## if loader.IsFinished(): ! ## ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrFinished') ! ## if c <= Config.Get('Download', 'MaxSimDown'): ! ## ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrAuto') ! ## else: ! ## ret = ret + "<tr bgcolor=#%s>" % HTTPConfig.Get('WebColors','TorrNonAuto') ! ## ! ## # Buttons ! ## if loader.Info['Status']!='Paused': ! ## cc = 'Pause' ! ## else: ! ## cc = 'Resume' ! ## ret = ret + "<form method=\"POST\" action=\"torrents\"><td>" ! ## ret = ret + "<button type=submit name=command value=%s>%s</button></td><td>" % (cc,cc) ! ## if c == 1: ! ## cc = 'DISABLED' ! ## else: ! ## cc = '' ! ## ret = ret + "<table><tr><td><button type=submit name=command %s value=MoveUp style=\"font-size:xx-small; font-weight:bold\">↑</button></td></tr>" % (cc) ! ## if c == len(BTHandler.Loaders): ! ## cc = 'DISABLED' ! ## else: ! ## cc = '' ! ## ret = ret + "<tr><td><button type=submit name=command %s value=MoveDown style=\"font-size:xx-small; font-weight:bold\">↓</button></td></tr></table>" % (cc) ! ## ret = ret + "<input type=hidden name=seed value=0><input type=hidden name=nr value=%d>" % (c) ! ## ret = ret + "</td></form>" ! ## ! ## # Filename ! ## ret = ret + "<td align=left nowrap><table width=100%><tr><td>" + loader.Config['File'] + "</td></tr>" ! ## ret = ret + "<tr><td><table width=100% bordercolor=#0000BB border=1 cellspacing=0 cellpadding=0><tr><td><table width=100% height=100%><tr>" ! ## if loader.Info['Status']=='Hashing': ! ## c1='#CC6666' ! ## c2='#6666CC' ! ## else: ! ## c1='#66CC66' ! ## c2='#CC6666' ! ## if loader.Info['FractionDone'] == -1: ! ## ret = ret + '<td bgcolor=#6666CC width=100% style=\"font-size:2px\"> </td>' ! ## else: ! ## ret = ret + ('<td bgcolor=%s width=%d%% style=\"font-size:2px\"> </td><td bgcolor=%s width=%d%% style=\"font-size:2px\"> \0\0</td>' % (c1, loader.Info['FractionDone']*100, c2, loader.Info['FractionRemain']*100)) ! ## ret = ret + "</tr></table></td></tr></table></td></tr></table></td>" ! ## ! ## # Filesize ! ## ret = ret + "<td align=center>" + ('%.2f MB' % (loader.Config['Size'] / 1024 / 1024)) + "</td>" ! ## ! ## # Fraction Done ! ## ret = ret + "<td align=center>" ! ## if loader.Info['FractionDone'] == -1: ! ## ret = ret + '?' ! ## else: ! ## ret = ret + ('%.2f MB' % (loader.Info['FractionDone'] * loader.Config['Size'] / 1024 / 1024)) ! ## ret = ret + "</td>" ! ## ! ## # Speed ! ## ret = ret + "<td align=center>" + ('%.1f / %.1f' % (loader.Info['SpeedDown'], loader.Info['SpeedUp'])) + "</td>" ! ## ! ## # Status ! ## ret = ret + "<td align=center>" + loader.Info['Status'] +"</td>" ! ## ! ## # Progress ! #### ret = ret + "<td><table width=100% bordercolor=#0000BB border=1 cellspacing=0 cellpadding=0><tr><td><table width=100% height=100%><tr>" ! #### if loader.Info['Status']=='Hashing': ! #### c1='#FF0000' ! #### c2='#0000FF' ! #### else: ! #### c1='#00FF00' ! #### c2='#FF0000' ! #### if loader.Info['FractionDone'] == -1: ! #### ret = ret + '<td bgcolor=#0000FF width=100%> </td>' ! #### else: ! #### ret = ret + ('<td bgcolor=%s width=%d%%> </td><td bgcolor=%s width=%d%%> </td>' % (c1, loader.Info['FractionDone']*100, c2, loader.Info['FractionRemain']*100)) ! #### ret = ret + "</tr></table></td></tr></table></td>" ! ## ! ## # Rest ! ## ret = ret + ('<td><table width=100%%><tr><td align=center width=100%% nowrap>%.1f%% [%.2f MB]</td></tr>' % (loader.Info['FractionRemain'] * 100, loader.Info['FractionRemain'] * loader.Config['Size'] / 1024 / 1024)) ! ## ret = ret + '<tr><td align=center width=100%% nowrap>%s</td></tr></table></td>' % loader.Info['ETA'] ! ## ! ## ret = ret + "</tr>\n" ! ## ret = ret + "</table>\n" ! ## else: ! ## ret = ret + "<p> No Torrents" ## if BTHandler.Seeds: ## ret = ret + "<p><table border=1 width=100% cellpadding=3>\n<tr bgcolor=#DDDDDD><th colspan=2>Seeds</th><th align=left>File</th><th>Size</th><th>Status</th><th>Speed</th></tr>\n" *************** *** 352,357 **** ## ret = ret + s + "<br>" ## ret = ret + "</b></td></tr></table>" ! ret = ret + "</body>\n</html>\n" ! self.wfile.write(ret) def send_config(self): --- 447,452 ---- ## ret = ret + s + "<br>" ## ret = ret + "</b></td></tr></table>" ! ## ret = ret + "</body>\n</html>\n" ! ## self.wfile.write(ret) def send_config(self): *************** *** 409,415 **** def send_log(self): ! ret = "<html>\n<head>\n<title>WebTorrent++ Log</title>\n" ! ret = ret + "</head>\n<body bgcolor=#%s>\n" % HTTPConfig.Get('WebColors','LogBackground') ! ret = ret + "<h1>WebTorrent++ Log</h1>\n<table border=1 cellpadding=4>\n" t = WebLog[:] try: --- 504,508 ---- def send_log(self): ! tproc = TemplateProcessor() t = WebLog[:] try: *************** *** 417,425 **** except: pass ! for line in t: ! sp = str(line).split('_',2) ! ret = ret + "<tr bgcolor=#%s><td nowrap>%s</td><td width=100%%>%s</td></tr>\n" % (HTTPConfig.Get('WebColors','LogTable'+sp[1]), sp[0], sp[2]) ! ret = ret + "</table>\n</body>\n</html>" ! self.wfile.write(ret) --- 510,515 ---- except: pass ! tproc.set("Logs", t) ! self.wfile.write(tproc.process(templateLog)) Index: HTTPConfigFile.py =================================================================== RCS file: /cvsroot/btplusplus/BT++/src/WebServer/HTTPConfigFile.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HTTPConfigFile.py 26 Feb 2003 01:12:05 -0000 1.2 --- HTTPConfigFile.py 27 Feb 2003 00:44:40 -0000 1.3 *************** *** 22,36 **** 'MenuBackground': 'FFFFCC', 'MenuAddbar': 'FFCCCC', - 'TorrBackground': 'CCCC00', - 'TorrFinished': 'FFCCCC', - 'TorrAuto': 'CCFFCC', - 'TorrNonAuto': 'BFD8BC', 'ConfBackground': '6666AA', 'ConfTable': 'CCCCFF', - 'LogBackground': 'AA6666', - 'LogTable0': 'FFFF66', - 'LogTable1': '66DD66', - 'LogTable2': 'FF6666', - 'LogTable3': 'FF6666' } } --- 22,27 ---- |