Skip to content
Permalink
Browse files
Merge pull request #1788 from getnikola/do-1767
fix #1767
  • Loading branch information
Kwpolska committed Jun 8, 2015
2 parents c7d4ebd + 94c5535 commit bbf0e4a147476d2af202621dad7c7f74caed6742
Showing with 38 additions and 0 deletions.
  1. +8 −0 CHANGES.txt
  2. +30 −0 nikola/plugins/command/version.py
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

* New ``nikola version --check`` option (Issue #1767)

New in v7.5.0
=============

@@ -26,9 +26,18 @@

from __future__ import print_function

import lxml
try:
import requests
except ImportError:
requests = None

from nikola.plugin_categories import Command
from nikola.utils import req_missing
from nikola import __version__

URL = 'https://pypi.python.org/pypi?:action=doap&name=Nikola'


class CommandVersion(Command):
"""Print the version."""
@@ -38,7 +47,28 @@ class CommandVersion(Command):
doc_usage = ""
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'):
if requests is None:
req_missing(['requests'], 'check for updates')
exit(1)
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))

0 comments on commit bbf0e4a

Please sign in to comment.