Skip to content

Commit

Permalink
Merge pull request #2512 from getnikola/list-installed-themes
Browse files Browse the repository at this point in the history
Fix #2504 -- add nikola theme --list-installed
  • Loading branch information
Kwpolska committed Sep 25, 2016
2 parents 9018c37 + b6d5e40 commit 7b71ced
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -14,6 +14,7 @@ Bugfixes
Features
--------

* Add ``nikola theme --list-installed`` (Issue #2504)
* Add Chinese (Traditional) ``zh_TW`` locale by Po-Wen Chi
* Add ``KATEX_AUTO_RENDER`` setting to configure math delimiters
* Update KaTeX version to 0.6.0: support aligned math display
Expand Down
6 changes: 3 additions & 3 deletions nikola/plugins/command/plugin.py
Expand Up @@ -50,7 +50,7 @@ class CommandPlugin(Command):

json = None
name = "plugin"
doc_usage = "[[-u][--user] --install name] | [[-u] [-l |--upgrade|--list-installed] | [--uninstall name]]"
doc_usage = "[-u url] [--user] [-i name] [-r name] [--upgrade] [-l] [--list-installed]"
doc_purpose = "manage plugins"
output_dir = None
needs_config = False
Expand Down Expand Up @@ -177,8 +177,8 @@ def list_installed(self):
plugins.append([plugin.name, p])

plugins.sort()
print('Installed Plugins')
print('-----------------')
print('Installed Plugins:')
print('------------------')
for name, path in plugins:
print('{0} at {1}'.format(name, path))
print('\n\nAlso, you have disabled these plugins: {}'.format(self.site.config['DISABLED_PLUGINS']))
Expand Down
26 changes: 25 additions & 1 deletion nikola/plugins/command/theme.py
Expand Up @@ -36,6 +36,7 @@
import pygments
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter
from pkg_resources import resource_filename

from nikola.plugin_categories import Command
from nikola import utils
Expand All @@ -48,7 +49,7 @@ class CommandTheme(Command):

json = None
name = "theme"
doc_usage = "[-i theme_name] [-r theme_name] [-l] [-u url] [-g] [-n theme_name] [-c template_name]"
doc_usage = "[-u url] [-i theme_name] [-r theme_name] [-l] [--list-installed] [-g] [-n theme_name] [-c template_name]"
doc_purpose = "manage themes"
output_dir = 'themes'
cmd_options = [
Expand Down Expand Up @@ -76,6 +77,13 @@ class CommandTheme(Command):
'default': False,
'help': 'Show list of available themes.'
},
{
'name': 'list_installed',
'long': 'list-installed',
'type': bool,
'help': "List the installed themes with their location.",
'default': False
},
{
'name': 'url',
'short': 'u',
Expand Down Expand Up @@ -133,6 +141,7 @@ def _execute(self, options, args):
install = options.get('install')
uninstall = options.get('uninstall')
list_available = options.get('list')
list_installed = options.get('list_installed')
get_path = options.get('getpath')
copy_template = options.get('copy-template')
new = options.get('new')
Expand All @@ -142,6 +151,7 @@ def _execute(self, options, args):
install,
uninstall,
list_available,
list_installed,
get_path,
copy_template,
new)].count(True)
Expand All @@ -151,6 +161,8 @@ def _execute(self, options, args):

if list_available:
return self.list_available(url)
elif list_installed:
return self.list_installed()
elif install:
return self.do_install_deps(url, install)
elif uninstall:
Expand Down Expand Up @@ -263,6 +275,18 @@ def list_available(self, url):
print(theme)
return 0

def list_installed(self):
"""List all installed themes."""
print("Installed Themes:")
print("-----------------")
themes = []
themes_dirs = self.site.themes_dirs + [resource_filename('nikola', os.path.join('data', 'themes'))]
for tdir in themes_dirs:
themes += [(i, os.path.join(tdir, i)) for i in os.listdir(tdir)]
for tname, tpath in sorted(set(themes)):
if os.path.isdir(tpath):
print("{0} at {1}".format(tname, tpath))

def copy_template(self, template):
"""Copy the named template file from the parent to a local theme or to templates/."""
# Find template
Expand Down

0 comments on commit 7b71ced

Please sign in to comment.