Skip to content

Commit

Permalink
[fix] Check app min_version with yunohost package (fixbug #113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelebleu committed Dec 21, 2015
1 parent 144d27e commit 5cd3a86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/yunohost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,26 @@
## Packages versions

def get_version(package):
"""Get the version of package"""
from moulinette.utils import process
return process.check_output(
"dpkg-query -W -f='${{Version}}' {0}".format(package)
).strip()

def get_versions(*args, **kwargs):
"""Get the version of each YunoHost package"""
from collections import OrderedDict
return OrderedDict([
('moulinette', get_version('moulinette')),
('yunohost', get_version('yunohost')),
('yunohost-admin', get_version('yunohost-admin')),
])

def has_min_version(min_version, package='yunohost', strict=False):
"""Check if a package has minimum version"""
from distutils.version import LooseVersion, StrictVersion
cmp_cls = StrictVersion if strict else LooseVersion
version = cmp_cls(get_version(package))
if version >= cmp_cls(min_version):
return True
return False
7 changes: 5 additions & 2 deletions src/yunohost/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from moulinette.core import MoulinetteError
from moulinette.utils.log import getActionLogger

from . import has_min_version
from .service import service_log

logger = getActionLogger('yunohost.app')
Expand Down Expand Up @@ -344,7 +345,8 @@ def app_upgrade(auth, app=[], url=None, file=None):
continue

# Check min version
if 'min_version' in manifest and __version__ < manifest['min_version']:
if 'min_version' in manifest \
and not has_min_version(manifest['min_version']):
raise MoulinetteError(errno.EPERM,
m18n.n('app_recent_version_required', app_id))

Expand Down Expand Up @@ -448,7 +450,8 @@ def app_install(auth, app, label=None, args=None):
app_id = manifest['id']

# Check min version
if 'min_version' in manifest and __version__ < manifest['min_version']:
if 'min_version' in manifest \
and not has_min_version(manifest['min_version']):
raise MoulinetteError(errno.EPERM,
m18n.n('app_recent_version_required', app_id))

Expand Down

0 comments on commit 5cd3a86

Please sign in to comment.