Skip to content

Commit

Permalink
Merge pull request #1788 from getnikola/do-1767
Browse files Browse the repository at this point in the history
fix #1767
  • Loading branch information
Kwpolska committed Jun 8, 2015
2 parents c7d4ebd + 94c5535 commit bbf0e4a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

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

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

Expand Down
30 changes: 30 additions & 0 deletions nikola/plugins/command/version.py
Expand Up @@ -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."""
Expand All @@ -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.