Skip to content
Permalink
Browse files
Fix getnikola/nikola-themes#49 -- https→http fallback
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 16, 2015
1 parent d9559f9 commit 63dcbc7092b7effd5860cbabc28b5c32929a3ef7
Showing with 40 additions and 8 deletions.
  1. +2 −0 CHANGES.txt
  2. +19 −5 nikola/plugins/command/install_theme.py
  3. +19 −3 nikola/plugins/command/plugin.py
@@ -33,6 +33,8 @@ Features
Bugfixes
--------

* Use ``http`` as fallback in plugin/theme installers if a SSL error occurs
(Issue getnikola/nikola-themes#49)
* Add missing ``xmlns:xhtml`` namespace to sitemaps (Issue #1890)
* Fixed superfluous rebuild problems with Python 3. Note that this will cause
rebuilds for most sites. (Issue #1887)
@@ -27,7 +27,7 @@
from __future__ import print_function
import os
import io
import json
import time
import requests

import pygments
@@ -95,8 +95,13 @@ def _execute(self, options, args):
if name is None and not listing:
LOGGER.error("This command needs either a theme name or the -l option.")
return False
data = requests.get(url).text
data = json.loads(data)
try:
data = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('http', 'https', 1)
data = requests.get(url).json()
if listing:
print("Themes:")
print("-------")
@@ -124,9 +129,18 @@ def _execute(self, options, args):
def do_install(self, name, data):
if name in data:
utils.makedirs(self.output_dir)
LOGGER.info("Downloading '{0}'".format(data[name]))
url = data[name]
LOGGER.info("Downloading '{0}'".format(url))
try:
zip_data = requests.get(url).content
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('http', 'https', 1)
zip_data = requests.get(url).content

zip_file = io.BytesIO()
zip_file.write(requests.get(data[name]).content)
zip_file.write(zip_data)
LOGGER.info("Extracting '{0}' into themes/".format(name))
utils.extract_all(zip_file)
dest_path = os.path.join(self.output_dir, name)
@@ -30,6 +30,7 @@
import shutil
import subprocess
import sys
import time
import requests

import pygments
@@ -209,9 +210,18 @@ def do_install(self, url, name, show_install_notes=True):
data = self.get_json(url)
if name in data:
utils.makedirs(self.output_dir)
LOGGER.info('Downloading: ' + data[name])
url = data[name]
LOGGER.info("Downloading '{0}'".format(url))
try:
zip_data = requests.get(url).content
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('http', 'https', 1)
zip_data = requests.get(url).content

zip_file = io.BytesIO()
zip_file.write(requests.get(data[name]).content)
zip_file.write(zip_data)
LOGGER.info('Extracting: {0} into {1}/'.format(name, self.output_dir))
utils.extract_all(zip_file, self.output_dir)
dest_path = os.path.join(self.output_dir, name)
@@ -296,5 +306,11 @@ def do_uninstall(self, name):

def get_json(self, url):
if self.json is None:
self.json = requests.get(url).json()
try:
self.json = requests.get(url).json()
except requests.exceptions.SSLError:
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
time.sleep(1)
url = url.replace('http', 'https', 1)
self.json = requests.get(url).json()
return self.json

0 comments on commit 63dcbc7

Please sign in to comment.