Fix compilation of coffeescript

This commit is contained in:
Kovid Goyal 2014-05-11 10:17:49 +05:30
parent ed7dec15a7
commit f58a115f5e

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, cPickle, re, shutil, marshal, zipfile, glob, time, subprocess, sys, hashlib, json import os, cPickle, re, shutil, marshal, zipfile, glob, time, sys, hashlib, json
from zlib import compress from zlib import compress
from itertools import chain from itertools import chain
@ -38,8 +38,6 @@ class Coffee(Command): # {{{
help='Display the generated javascript') help='Display the generated javascript')
def run(self, opts): def run(self, opts):
cc = self.j(self.SRC, 'calibre', 'utils', 'serve_coffee.py')
self.compiler = [sys.executable, cc, 'compile']
self.do_coffee_compile(opts) self.do_coffee_compile(opts)
if opts.watch: if opts.watch:
try: try:
@ -57,6 +55,7 @@ class Coffee(Command): # {{{
print highlight(raw, JavascriptLexer(), TerminalFormatter()) print highlight(raw, JavascriptLexer(), TerminalFormatter())
def do_coffee_compile(self, opts, timestamp=False, ignore_errors=False): def do_coffee_compile(self, opts, timestamp=False, ignore_errors=False):
from calibre.utils.serve_coffee import compile_coffeescript
src_files = {} src_files = {}
for src in self.COFFEE_DIRS: for src in self.COFFEE_DIRS:
for f in glob.glob(self.j(self.SRC, __appname__, src, for f in glob.glob(self.j(self.SRC, __appname__, src,
@ -85,12 +84,11 @@ class Coffee(Command): # {{{
print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if
timestamp else '', name)) timestamp else '', name))
src, sig = src_files[arcname] src, sig = src_files[arcname]
try: js, errors = compile_coffeescript(open(src, 'rb').read(), filename=src)
js = subprocess.check_output(self.compiler + if errors:
[src]).decode('utf-8')
except Exception as e:
print ('\n\tCompilation of %s failed'%name) print ('\n\tCompilation of %s failed'%name)
print (e) for line in errors:
print >>sys.stderr, line
if ignore_errors: if ignore_errors:
js = u'# Compilation from coffeescript failed' js = u'# Compilation from coffeescript failed'
else: else: