aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/command/plugin.py
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2015-07-08 07:35:06 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2015-07-08 07:35:06 -0300
commit055d72d76b44b0e627c8a17c48dbecd62e44197b (patch)
treee2c8d5475477c46115461fe9547c1ee797873635 /nikola/plugins/command/plugin.py
parent61f3aad02cd6492cb38e41b66f2ed8ec56e98981 (diff)
parentb0b24795b24ee6809397fbbadf42f31f310a219f (diff)
Merge tag 'upstream/7.6.0'
Upstream version 7.6.0
Diffstat (limited to 'nikola/plugins/command/plugin.py')
-rw-r--r--nikola/plugins/command/plugin.py43
1 files changed, 9 insertions, 34 deletions
diff --git a/nikola/plugins/command/plugin.py b/nikola/plugins/command/plugin.py
index 71901b8..56eb1d7 100644
--- a/nikola/plugins/command/plugin.py
+++ b/nikola/plugins/command/plugin.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Copyright © 2012-2014 Roberto Alsina and others.
+# Copyright © 2012-2015 Roberto Alsina and others.
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
@@ -30,41 +30,18 @@ import os
import shutil
import subprocess
import sys
+import requests
import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter
-try:
- import requests
-except ImportError:
- requests = None # NOQA
-
from nikola.plugin_categories import Command
from nikola import utils
LOGGER = utils.get_logger('plugin', utils.STDERR_HANDLER)
-# Stolen from textwrap in Python 3.3.2.
-def indent(text, prefix, predicate=None): # NOQA
- """Adds 'prefix' to the beginning of selected lines in 'text'.
-
- If 'predicate' is provided, 'prefix' will only be added to the lines
- where 'predicate(line)' is True. If 'predicate' is not provided,
- it will default to adding 'prefix' to all non-empty lines that do not
- consist solely of whitespace characters.
- """
- if predicate is None:
- def predicate(line):
- return line.strip()
-
- def prefixed_lines():
- for line in text.splitlines(True):
- yield (prefix + line if predicate(line) else line)
- return ''.join(prefixed_lines())
-
-
class CommandPlugin(Command):
"""Manage plugins."""
@@ -105,8 +82,8 @@ class CommandPlugin(Command):
'long': 'url',
'type': str,
'help': "URL for the plugin repository (default: "
- "http://plugins.getnikola.com/v7/plugins.json)",
- 'default': 'http://plugins.getnikola.com/v7/plugins.json'
+ "https://plugins.getnikola.com/v7/plugins.json)",
+ 'default': 'https://plugins.getnikola.com/v7/plugins.json'
},
{
'name': 'user',
@@ -258,7 +235,7 @@ class CommandPlugin(Command):
LOGGER.error('Could not install the dependencies.')
print('Contents of the requirements.txt file:\n')
with io.open(reqpath, 'r', encoding='utf-8') as fh:
- print(indent(fh.read(), 4 * ' '))
+ print(utils.indent(fh.read(), 4 * ' '))
print('You have to install those yourself or through a '
'package manager.')
else:
@@ -272,8 +249,8 @@ class CommandPlugin(Command):
with io.open(reqnpypath, 'r', encoding='utf-8') as fh:
for l in fh.readlines():
i, j = l.split('::')
- print(indent(i.strip(), 4 * ' '))
- print(indent(j.strip(), 8 * ' '))
+ print(utils.indent(i.strip(), 4 * ' '))
+ print(utils.indent(j.strip(), 8 * ' '))
print()
print('You have to install those yourself or through a package '
@@ -284,11 +261,11 @@ class CommandPlugin(Command):
print('Contents of the conf.py.sample file:\n')
with io.open(confpypath, 'r', encoding='utf-8') as fh:
if self.site.colorful:
- print(indent(pygments.highlight(
+ print(utils.indent(pygments.highlight(
fh.read(), PythonLexer(), TerminalFormatter()),
4 * ' '))
else:
- print(indent(fh.read(), 4 * ' '))
+ print(utils.indent(fh.read(), 4 * ' '))
return True
def do_uninstall(self, name):
@@ -311,8 +288,6 @@ class CommandPlugin(Command):
return False
def get_json(self, url):
- if requests is None:
- utils.req_missing(['requests'], 'install or list available plugins', python=True, optional=False)
if self.json is None:
self.json = requests.get(url).json()
return self.json