Skip to content
Permalink
Browse files

Replace with

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 7, 2016
1 parent 68d0a1e commit 5c78d07d74f264ce68d530bcd0e487c8976f2c80
Showing with 15 additions and 94 deletions.
  1. +1 −1 docs/extending.txt
  2. +2 −2 docs/man/nikola.rst
  3. +6 −5 docs/manual.txt
  4. +6 −86 nikola/plugins/command/install_theme.py
@@ -63,13 +63,13 @@ When you run ``nikola --help`` you will see something like this:
nikola import_feed import a RSS/Atom dump
nikola import_wordpress import a WordPress dump
nikola init create a Nikola site in the specified folder
nikola install_theme install theme into current site
nikola list list tasks from dodo file
nikola mincss apply mincss to the generated site
nikola new_post create a new blog post or site page
nikola run run tasks
nikola serve start the test webserver
nikola strace use strace to list file_deps and targets
nikola theme manage themes
nikola version print the Nikola version number

nikola help show help / reference
@@ -100,8 +100,8 @@ The most basic commands needed to get by are:
start development web server with automated rebuilds and reloads
``nikola plugin [options]``
manage plugins from the Plugins Index (https://plugins.getnikola.com/)
``nikola install_theme [name]``
install themes from the Themes Index (https://themes.getnikola.com/)
``nikola theme [options]``
manage themes from the Themes Index (https://themes.getnikola.com/)

Use ``nikola help`` to get a list of all commands.

@@ -1076,23 +1076,24 @@ Getting More Themes

There are a few themes for Nikola. They are available at
the `Themes Index <https://themes.getnikola.com/>`_.
Nikola has a built-in theme download/install mechanism to install those themes — the ``install_theme`` command:
Nikola has a built-in theme download/install mechanism to install those themes
— the ``theme`` command:


.. code:: console

$ nikola install_theme -l
$ nikola theme -l
Themes:
-------
blogtxt
bootstrap3-gradients

$ nikola install_theme blogtxt
[2013-10-12T16:46:13Z] NOTICE: install_theme: Downloading:
$ nikola theme -i blogtxt
[2013-10-12T16:46:13Z] NOTICE: theme: Downloading:
https://themes.getnikola.com/v6/blogtxt.zip
[2013-10-12T16:46:15Z] NOTICE: install_theme: Extracting: blogtxt into themes
[2013-10-12T16:46:15Z] NOTICE: theme: Extracting: blogtxt into themes

And there you are, you now have themes/blogtxt installed. It's very
rudimentary, but it should work in most cases.
@@ -27,18 +27,9 @@
"""Install a theme."""

from __future__ import print_function
import os
import io
import time
import requests

import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter

from nikola.plugin_categories import Command
from nikola import utils

from nikola.plugin_categories import Command
LOGGER = utils.get_logger('install_theme', utils.STDERR_HANDLER)


@@ -79,6 +70,7 @@ class CommandInstallTheme(Command):

def _execute(self, options, args):
"""Install theme into current site."""
p = self.site.plugin_manager.getPluginByName('theme', 'Command').plugin_object
listing = options['list']
url = options['url']
if args:
@@ -87,85 +79,13 @@ def _execute(self, options, args):
name = None

if options['getpath'] and name:
path = utils.get_theme_path(name)
if path:
print(path)
else:
print('not installed')
return 0
return p.get_path(name)

if name is None and not listing:
LOGGER.error("This command needs either a theme name or the -l option.")
return False
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('https', 'http', 1)
data = requests.get(url).json()
if listing:
print("Themes:")
print("-------")
for theme in sorted(data.keys()):
print(theme)
return True
else:
# `name` may be modified by the while loop.
origname = name
installstatus = self.do_install(name, data)
# See if the theme's parent is available. If not, install it
while True:
parent_name = utils.get_parent_theme_name(name)
if parent_name is None:
break
try:
utils.get_theme_path(parent_name)
break
except: # Not available
self.do_install(parent_name, data)
name = parent_name
if installstatus:
LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(origname))

def do_install(self, name, data):
"""Download and install a theme."""
if name in data:
utils.makedirs(self.output_dir)
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('https', 'http', 1)
zip_data = requests.get(url).content

zip_file = io.BytesIO()
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)
if listing:
p.list_available(url)
else:
dest_path = os.path.join(self.output_dir, name)
try:
theme_path = utils.get_theme_path(name)
LOGGER.error("Theme '{0}' is already installed in {1}".format(name, theme_path))
except Exception:
LOGGER.error("Can't find theme {0}".format(name))

return False

confpypath = os.path.join(dest_path, 'conf.py.sample')
if os.path.exists(confpypath):
LOGGER.notice('This theme has a sample config file. Integrate it with yours in order to make this theme work!')
print('Contents of the conf.py.sample file:\n')
with io.open(confpypath, 'r', encoding='utf-8') as fh:
if self.site.colorful:
print(utils.indent(pygments.highlight(
fh.read(), PythonLexer(), TerminalFormatter()),
4 * ' '))
else:
print(utils.indent(fh.read(), 4 * ' '))
return True
p.do_install_loop(url, name)

0 comments on commit 5c78d07

Please sign in to comment.
You can’t perform that action at this time.