Send the install uuid when downloading builtin recipes from the new server for better recipe usage stats

This commit is contained in:
Kovid Goyal 2015-01-06 21:59:19 +05:30
parent f5bc132d2a
commit cee98bbd0c
2 changed files with 5 additions and 3 deletions

View File

@ -154,7 +154,7 @@ else:
getattr(ssl, 'match_hostname', match_hostname)(self.sock.getpeercert(), self.host) getattr(ssl, 'match_hostname', match_hostname)(self.sock.getpeercert(), self.host)
def get_https_resource_securely( def get_https_resource_securely(
url, cacerts='calibre-ebook-root-CA.crt', timeout=60, max_redirects=5, ssl_version=None): url, cacerts='calibre-ebook-root-CA.crt', timeout=60, max_redirects=5, ssl_version=None, headers=None):
''' '''
Download the resource pointed to by url using https securely (verify server Download the resource pointed to by url using https securely (verify server
certificate). Ensures that redirects, if any, are also downloaded certificate). Ensures that redirects, if any, are also downloaded
@ -195,7 +195,7 @@ def get_https_resource_securely(
path = p.path or '/' path = p.path or '/'
if p.query: if p.query:
path += '?' + p.query path += '?' + p.query
c.request('GET', path) c.request('GET', path, headers=headers or {})
response = c.getresponse() response = c.getresponse()
if response.status in (httplib.MOVED_PERMANENTLY, httplib.FOUND, httplib.SEE_OTHER): if response.status in (httplib.MOVED_PERMANENTLY, httplib.FOUND, httplib.SEE_OTHER):
if max_redirects <= 0: if max_redirects <= 0:

View File

@ -208,9 +208,11 @@ def download_builtin_recipe(urn):
return get_https_resource_securely('https://status.calibre-ebook.com/recipe/'+urn) return get_https_resource_securely('https://status.calibre-ebook.com/recipe/'+urn)
def download_builtin_recipe2(urn): def download_builtin_recipe2(urn):
from calibre.utils.config_base import prefs
from calibre.utils.https import get_https_resource_securely from calibre.utils.https import get_https_resource_securely
import bz2 import bz2
return bz2.decompress(get_https_resource_securely('https://code.calibre-ebook.com/recipe-compressed/'+urn)) return bz2.decompress(get_https_resource_securely(
'https://code.calibre-ebook.com/recipe-compressed/'+urn, headers={'CALIBRE-INSTALL-UUID':prefs['installation_uuid']}))
def get_builtin_recipe(urn): def get_builtin_recipe(urn):
with zipfile.ZipFile(P('builtin_recipes.zip', allow_user_override=False), 'r') as zf: with zipfile.ZipFile(P('builtin_recipes.zip', allow_user_override=False), 'r') as zf: