mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge from trunk
This commit is contained in:
commit
29a910a87b
@ -5,7 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import subprocess, tempfile, os, time, sys
|
import subprocess, tempfile, os, time, sys, telnetlib
|
||||||
from threading import RLock
|
from threading import RLock
|
||||||
|
|
||||||
from setup import Command
|
from setup import Command
|
||||||
@ -28,7 +28,12 @@ else:
|
|||||||
def process_default(self, event):
|
def process_default(self, event):
|
||||||
name = getattr(event,
|
name = getattr(event,
|
||||||
'name', None)
|
'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
|
||||||
print name, 'changed'
|
print name, 'changed'
|
||||||
self.command.kill_server()
|
self.command.kill_server()
|
||||||
@ -36,6 +41,9 @@ else:
|
|||||||
print self.command.prompt,
|
print self.command.prompt,
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
if reload:
|
||||||
|
self.command.reload_browser(delay=1)
|
||||||
|
|
||||||
|
|
||||||
class Server(Command):
|
class Server(Command):
|
||||||
|
|
||||||
@ -75,6 +83,19 @@ class Server(Command):
|
|||||||
self.notifier.start()
|
self.notifier.start()
|
||||||
self.wdd = wm.add_watch(os.path.abspath('src'), mask, rec=True)
|
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):
|
def run(self, opts):
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
tdir = tempfile.gettempdir()
|
tdir = tempfile.gettempdir()
|
||||||
@ -88,8 +109,8 @@ class Server(Command):
|
|||||||
first = True
|
first = True
|
||||||
while True:
|
while True:
|
||||||
self.launch_server()
|
self.launch_server()
|
||||||
if first:
|
if not first:
|
||||||
pass
|
self.reload_browser()
|
||||||
first = False
|
first = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -58,7 +58,13 @@ def comments_to_html(comments):
|
|||||||
return '\n'.join(parts)
|
return '\n'.join(parts)
|
||||||
|
|
||||||
if sanitize_pat.search(comments) is not None:
|
if sanitize_pat.search(comments) is not None:
|
||||||
return sanitize_comments_html(comments)
|
try:
|
||||||
|
return sanitize_comments_html(comments)
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return u'<p></p>'
|
||||||
|
|
||||||
|
|
||||||
# Explode lost CRs to \n\n
|
# Explode lost CRs to \n\n
|
||||||
comments = lost_cr_exception_pat.sub(lambda m: m.group().replace('.',
|
comments = lost_cr_exception_pat.sub(lambda m: m.group().replace('.',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user