Merge from trunk

This commit is contained in:
Sengian 2010-11-01 11:24:30 +01:00
commit 29a910a87b
2 changed files with 32 additions and 5 deletions

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import subprocess, tempfile, os, time, sys
import subprocess, tempfile, os, time, sys, telnetlib
from threading import RLock
from setup import Command
@ -28,7 +28,12 @@ else:
def process_default(self, event):
name = getattr(event,
'name', None)
if name and os.path.splitext(name)[1] == '.py':
if not name:
return
ext = os.path.splitext(name)[1]
reload = False
if ext == '.py':
reload = True
print
print name, 'changed'
self.command.kill_server()
@ -36,6 +41,9 @@ else:
print self.command.prompt,
sys.stdout.flush()
if reload:
self.command.reload_browser(delay=1)
class Server(Command):
@ -75,6 +83,19 @@ class Server(Command):
self.notifier.start()
self.wdd = wm.add_watch(os.path.abspath('src'), mask, rec=True)
def reload_browser(self, delay=0.1):
time.sleep(delay)
try:
t = telnetlib.Telnet('localhost', 4242)
t.read_until("repl>")
t.write('BrowserReload();')
print t.read_until("repl>")
t.close()
except:
print 'Failed to reload browser'
import traceback
traceback.print_exc()
def run(self, opts):
self.lock = RLock()
tdir = tempfile.gettempdir()
@ -88,8 +109,8 @@ class Server(Command):
first = True
while True:
self.launch_server()
if first:
pass
if not first:
self.reload_browser()
first = False
try:

View File

@ -58,7 +58,13 @@ def comments_to_html(comments):
return '\n'.join(parts)
if sanitize_pat.search(comments) is not None:
try:
return sanitize_comments_html(comments)
except:
import traceback
traceback.print_exc()
return u'<p></p>'
# Explode lost CRs to \n\n
comments = lost_cr_exception_pat.sub(lambda m: m.group().replace('.',