aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/command/version.py
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/command/version.py')
-rw-r--r--nikola/plugins/command/version.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/nikola/plugins/command/version.py b/nikola/plugins/command/version.py
index 9b42423..b6520d7 100644
--- a/nikola/plugins/command/version.py
+++ b/nikola/plugins/command/version.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
@@ -26,19 +26,42 @@
from __future__ import print_function
+import lxml
+import requests
+
from nikola.plugin_categories import Command
from nikola import __version__
+URL = 'https://pypi.python.org/pypi?:action=doap&name=Nikola'
+
class CommandVersion(Command):
"""Print the version."""
name = "version"
- doc_usage = ""
+ doc_usage = "[--check]"
needs_config = False
doc_purpose = "print the Nikola version number"
+ cmd_options = [
+ {
+ 'name': 'check',
+ 'long': 'check',
+ 'short': '',
+ 'default': False,
+ 'type': bool,
+ 'help': "Check for new versions.",
+ }
+ ]
def _execute(self, options={}, args=None):
"""Print the version number."""
print("Nikola v" + __version__)
+ if options.get('check'):
+ data = requests.get(URL).text
+ doc = lxml.etree.fromstring(data.encode('utf8'))
+ revision = doc.findall('*//{http://usefulinc.com/ns/doap#}revision')[0].text
+ if revision == __version__:
+ print("Nikola is up-to-date")
+ else:
+ print("The latest version of Nikola is v{0} -- please upgrade using `pip install --upgrade Nikola=={0}` or your system package manager".format(revision))