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 80d64a12da21a67aba0d8a16bd5aaf2f54239fb3
Showing with 34 additions and 7 deletions.
  1. +2 −0 CHANGES.txt
  2. +16 −4 nikola/plugins/command/install_theme.py
  3. +16 −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)
@@ -95,8 +95,12 @@ 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")
url = url.replace('http', 'https', 1)
data = requests.get(url).json()
if listing:
print("Themes:")
print("-------")
@@ -124,9 +128,17 @@ 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")
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)
@@ -209,9 +209,17 @@ 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")
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 +304,10 @@ 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")
url = url.replace('http', 'https', 1)
self.json = requests.get(url).json()
return self.json

0 comments on commit 80d64a1

Please sign in to comment.