diff options
Diffstat (limited to 'nikola/plugins/command_install_theme.py')
| -rw-r--r-- | nikola/plugins/command_install_theme.py | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/nikola/plugins/command_install_theme.py b/nikola/plugins/command_install_theme.py index 0dc000b..04a2cce 100644 --- a/nikola/plugins/command_install_theme.py +++ b/nikola/plugins/command_install_theme.py @@ -23,7 +23,6 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import print_function -from optparse import OptionParser import os import json from io import BytesIO @@ -41,31 +40,39 @@ class CommandInstallTheme(Command): """Start test server.""" name = "install_theme" + doc_usage = "[[-u] theme_name] | [[-u] -l]" + doc_purpose = "Install theme into current site." + cmd_options = [ + { + 'name': 'list', + 'short': 'l', + 'long': 'list', + 'type': bool, + 'default': False, + 'help': 'Show list of available themes.' + }, + { + 'name': 'url', + 'short': 'u', + 'long': 'url', + 'type': str, + 'help': "URL for the theme repository (default: " + "http://nikola.ralsina.com.ar/themes/index.json)", + 'default': 'http://nikola.ralsina.com.ar/themes/index.json' + }, + ] - def run(self, *args): + def _execute(self, options, args): """Install theme into current site.""" - if requests is None: - print('To use the install_theme command, you need to install the ' - '"requests" package.') - return - parser = OptionParser(usage="nikola %s [options]" % self.name) - parser.add_option("-l", "--list", dest="list", action="store_true", - help="Show list of available themes.") - parser.add_option("-n", "--name", dest="name", help="Theme name", - default=None) - parser.add_option("-u", "--url", dest="url", help="URL for the theme " - "repository" "(default: " - "http://nikola.ralsina.com.ar/themes/index.json)", - default='http://nikola.ralsina.com.ar/themes/' - 'index.json') - (options, args) = parser.parse_args(list(args)) - - listing = options.list - name = options.name - url = options.url + listing = options['list'] + url = options['url'] + if args: + name = args[0] + else: + name = None if name is None and not listing: - print("This command needs either the -n or the -l option.") + print("This command needs either a theme name or the -l option.") return False data = requests.get(url).text data = json.loads(data) @@ -84,11 +91,11 @@ class CommandInstallTheme(Command): os.makedirs("themes") except: raise OSError("mkdir 'theme' error!") - print('Downloading: %s' % data[name]) + print('Downloading: ' + data[name]) zip_file = BytesIO() zip_file.write(requests.get(data[name]).content) - print('Extracting: %s into themes' % name) + print('Extracting: {0} into themes'.format(name)) utils.extract_all(zip_file) else: - print("Can't find theme %s" % name) + print("Can't find theme " + name) return False |
