Use curl to download mathjax as well so that it works in Travis on OS X

This commit is contained in:
Kovid Goyal 2016-12-09 10:41:39 +05:30
parent e652bfac22
commit 91d3802377
3 changed files with 31 additions and 14 deletions

View File

@ -27,6 +27,7 @@ __version__ = __appname__ = modules = functions = basenames = scripts = None
_cache_dir_built = False
def newer(targets, sources):
if isinstance(targets, basestring):
targets = [targets]
@ -40,6 +41,14 @@ def newer(targets, sources):
newest_source, oldest_target = max(stimes), min(ttimes)
return newest_source > oldest_target
def download_securely(url):
# We use curl here as on some OSes (OS X) when bootstrapping calibre,
# python will be unable to validate certificates until after cacerts is
# installed
return subprocess.check_output(['curl', '-fsSL', url])
def build_cache_dir():
global _cache_dir_built
ans = os.path.join(os.path.dirname(SRC), '.build-cache')
@ -52,11 +61,13 @@ def build_cache_dir():
raise
return ans
def require_git_master():
if subprocess.check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip() != 'master':
print >>sys.stderr, 'You must be in the master git branch'
raise SystemExit(1)
def require_clean_git():
c = subprocess.check_call
p = subprocess.Popen
@ -70,6 +81,7 @@ def require_clean_git():
print >>sys.stderr, 'Your git index contains uncommitted changes'
raise SystemExit(1)
def initialize_constants():
global __version__, __appname__, modules, functions, basenames, scripts
@ -102,10 +114,12 @@ def initialize_constants():
modules[x] = list(map(e2m, entry_points[y]))
scripts[x] = list(map(e2s, entry_points[y]))
initialize_constants()
preferred_encoding = 'utf-8'
def prints(*args, **kwargs):
'''
Print unicode arguments safely by encoding them to preferred_encoding
@ -144,11 +158,14 @@ def prints(*args, **kwargs):
file.write(sep)
file.write(end)
warnings = []
def get_warnings():
return list(warnings)
class Command(object):
SRC = SRC
@ -252,6 +269,7 @@ class Command(object):
warnings.append((args, kwargs))
sys.stdout.flush()
def installer_name(ext, is64bit=False):
if is64bit and ext == 'msi':
return 'dist/%s-64bit-%s.msi'%(__appname__, __version__)
@ -266,6 +284,3 @@ def installer_name(ext, is64bit=False):
if is64bit:
ans = ans.replace('i686', 'x86_64')
return ans

View File

@ -8,14 +8,15 @@ __copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, shutil
from urllib import urlretrieve
from io import BytesIO
from zipfile import ZipFile, ZIP_STORED, ZipInfo
from hashlib import sha1
from tempfile import mkdtemp, SpooledTemporaryFile
is_ci = os.environ.get('CI', '').lower() == 'true'
from setup import Command
from setup import Command, download_securely
class MathJax(Command):
@ -29,8 +30,8 @@ class MathJax(Command):
def download_mathjax_release(self, tdir, url):
self.info('Downloading MathJax:', url)
filename = urlretrieve(url)[0]
with ZipFile(filename) as zf:
raw = download_securely(url)
with ZipFile(BytesIO(raw)) as zf:
zf.extractall(tdir)
return os.path.join(tdir, 'MathJax-master')

View File

@ -6,12 +6,13 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, cPickle, re, shutil, marshal, zipfile, glob, time, sys, hashlib, json, errno, subprocess
import os, cPickle, re, shutil, marshal, zipfile, glob, time, sys, hashlib, json, errno
from zlib import compress
from itertools import chain
is_ci = os.environ.get('CI', '').lower() == 'true'
from setup import Command, basenames, __appname__
from setup import Command, basenames, __appname__, download_securely
def get_opts_from_parser(parser):
def do_opt(opt):
@ -27,11 +28,6 @@ def get_opts_from_parser(parser):
for x in do_opt(o):
yield x
def download_securely(url):
# We use curl here as on some OSes (OS X) when bootstrapping calibre,
# python will be unable to validate certificates until after cacerts is
# installed
return subprocess.check_output(['curl', '-fsSL', url])
class Coffee(Command): # {{{
@ -128,6 +124,7 @@ class Coffee(Command): # {{{
os.remove(x)
# }}}
class Kakasi(Command): # {{{
description = 'Compile resources for unihandecode'
@ -229,6 +226,7 @@ class Kakasi(Command): # {{{
shutil.rmtree(kakasi)
# }}}
class CACerts(Command): # {{{
description = 'Get updated mozilla CA certificate bundle'
@ -256,6 +254,7 @@ class CACerts(Command): # {{{
get_https_resource_securely('https://calibre-ebook.com', cacerts=self.b(self.CA_PATH))
# }}}
class RecentUAs(Command):
description = 'Get updated list of recent browser user agents'
@ -291,6 +290,7 @@ class RecentUAs(Command):
with open(self.UA_PATH, 'wb') as f:
f.write('\n'.join(lines).encode('ascii'))
class RapydScript(Command): # {{{
description = 'Compile RapydScript to JavaScript'
@ -300,6 +300,7 @@ class RapydScript(Command): # {{{
compile_srv()
# }}}
class Resources(Command): # {{{
description = 'Compile various needed calibre resources'