From 2d6291e5fc22a87c1855b9761f1baf9fc37d5f5f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 11 Jan 2012 09:18:58 +0530 Subject: [PATCH] Make sure that python setup.py resources works even if calibre has not been installed --- setup/resources.py | 30 +++--- src/TestHTTPServer.py | 132 ------------------------- src/calibre/utils/serve_coffee.py | 154 ++++++++++++++++++++++++++++-- 3 files changed, 160 insertions(+), 156 deletions(-) delete mode 100644 src/TestHTTPServer.py diff --git a/setup/resources.py b/setup/resources.py index 599cdccd29..0e91a9faa7 100644 --- a/setup/resources.py +++ b/setup/resources.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, cPickle, re, shutil, marshal, zipfile, glob, time +import os, cPickle, re, shutil, marshal, zipfile, glob, time, subprocess, sys from zlib import compress from setup import Command, basenames, __appname__ @@ -35,8 +35,8 @@ class Coffee(Command): # {{{ help='Display the generated javascript') def run(self, opts): - from calibre.utils.serve_coffee import compile_coffeescript - self.compiler = compile_coffeescript + cc = self.j(self.SRC, 'calibre', 'utils', 'serve_coffee.py') + self.compiler = [sys.executable, cc, 'compile'] self.do_coffee_compile(opts) if opts.watch: try: @@ -63,24 +63,24 @@ class Coffee(Command): # {{{ if self.newer(js, x): print ('\t%sCompiling %s'%(time.strftime('[%H:%M:%S] ') if timestamp else '', os.path.basename(x))) - with open(x, 'rb') as f: - cs, errs = self.compiler(f.read()) - for line in errs: - print (line) - if cs and not errs: + try: + cs = subprocess.check_output(self.compiler + + [x]).decode('utf-8') + except Exception as e: + print ('\n\tCompilation of %s failed'%os.path.basename(x)) + print (e) + if ignore_errors: + with open(js, 'wb') as f: + f.write('# Compilation from coffeescript failed') + else: + raise SystemExit(1) + else: with open(js, 'wb') as f: f.write(cs.encode('utf-8')) if opts.show_js: self.show_js(js) print ('#'*80) print ('#'*80) - else: - print ('\n\tCompilation of %s failed'%os.path.basename(x)) - if ignore_errors: - with open(js, 'wb') as f: - f.write('# Compilation from coffeescript failed') - else: - raise SystemExit(1) def clean(self): for toplevel, dest in self.COFFEE_DIRS.iteritems(): diff --git a/src/TestHTTPServer.py b/src/TestHTTPServer.py deleted file mode 100644 index 35077fe41c..0000000000 --- a/src/TestHTTPServer.py +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env python -# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import (unicode_literals, division, absolute_import, - print_function) - -__license__ = 'GPL v3' -__copyright__ = '2011, Kovid Goyal ' -__docformat__ = 'restructuredtext en' - -import os, io -from SimpleHTTPServer import SimpleHTTPRequestHandler - -class HTTPRequestHandler(SimpleHTTPRequestHandler): - ''' - Handle Range headers, as browsers insist on using range for