mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-16 03:54:39 -04:00
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
|
|
|
__license__ = 'GPL v3'
|
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|
__docformat__ = 'restructuredtext en'
|
|
|
|
import subprocess, tempfile, os, time
|
|
|
|
from setup import Command
|
|
|
|
class Server(Command):
|
|
|
|
description = 'Run the calibre server in development mode conveniently'
|
|
|
|
MONOCLE_PATH = '../monocle'
|
|
|
|
def rebuild_monocole(self):
|
|
subprocess.check_call(['sprocketize', '-C', self.MONOCLE_PATH,
|
|
'-I', 'src', 'src/monocle.js'],
|
|
stdout=open('resources/content_server/read/monocle.js', 'wb'))
|
|
|
|
def launch_server(self, log):
|
|
self.rebuild_monocole()
|
|
p = subprocess.Popen(['calibre-server', '--develop'],
|
|
stderr=subprocess.STDOUT, stdout=log)
|
|
time.sleep(0.2)
|
|
if p.poll() is not None:
|
|
print 'Starting server failed'
|
|
raise SystemExit(1)
|
|
return p
|
|
|
|
def run(self, opts):
|
|
tdir = tempfile.gettempdir()
|
|
logf = os.path.join(tdir, 'calibre-server.log')
|
|
log = open(logf, 'ab')
|
|
print 'Server log available at:', logf
|
|
|
|
while True:
|
|
print 'Starting server...'
|
|
p = self.launch_server(log)
|
|
try:
|
|
raw_input('Press Enter to kill/restart server. Ctrl+C to quit: ')
|
|
except:
|
|
if p.poll() is None:
|
|
p.kill()
|
|
break
|
|
else:
|
|
while p.poll() is None:
|
|
p.terminate()
|
|
time.sleep(0.1)
|
|
p.kill()
|
|
print
|
|
|