From e03e884ffc0484f86feef2f2a405934ed3c0e4c1 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 9 Feb 2018 13:46:45 -0500 Subject: [PATCH] minWebodmVersion check in plugins --- VERSION | 1 - app/boot.py | 9 +++++---- app/plugins/functions.py | 34 ++++++++++++++++++++++++++++++++++ app/templates/app/base.html | 1 - webodm/settings.py | 6 ++++-- 5 files changed, 43 insertions(+), 8 deletions(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 267577d4..00000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.4.1 diff --git a/app/boot.py b/app/boot.py index f22462ef..8d30e825 100644 --- a/app/boot.py +++ b/app/boot.py @@ -28,6 +28,8 @@ def boot(): booted.value = True logger = logging.getLogger('app.logger') + logger.info("Booting WebODM {}".format(settings.VERSION)) + if settings.DEBUG: logger.warning("Debug mode is ON (for development this is OK)") @@ -59,14 +61,13 @@ def boot(): # Add default presets Preset.objects.get_or_create(name='DSM + DTM', system=True, options=[{'name': 'dsm', 'value': True}, {'name': 'dtm', 'value': True}]) + Preset.objects.get_or_create(name='Fast Orthophoto', system=True, + options=[{'name': 'fast-orthophoto', 'value': True}]) Preset.objects.get_or_create(name='High Quality', system=True, options=[{'name': 'dsm', 'value': True}, - {'name': 'skip-resize', 'value': True}, {'name': 'mesh-octree-depth', 'value': "12"}, - {'name': 'use-25dmesh', 'value': True}, - {'name': 'min-num-features', 'value': 8000}, {'name': 'dem-resolution', 'value': "0.04"}, - {'name': 'orthophoto-resolution', 'value': "60"}, + {'name': 'orthophoto-resolution', 'value': "40"}, ]) Preset.objects.get_or_create(name='Default', system=True, options=[{'name': 'dsm', 'value': True}]) diff --git a/app/plugins/functions.py b/app/plugins/functions.py index 790da7be..47097c28 100644 --- a/app/plugins/functions.py +++ b/app/plugins/functions.py @@ -3,7 +3,11 @@ import logging import importlib import django +import json from django.conf.urls import url +from functools import reduce + +from webodm import settings logger = logging.getLogger('app.logger') @@ -49,6 +53,16 @@ def get_active_plugins(): if os.path.isfile(disabled_path): continue + # Read manifest + with open(manifest_path) as manifest_file: + manifest = json.load(manifest_file) + if 'webodmMinVersion' in manifest: + min_version = manifest['webodmMinVersion'] + + if versionToInt(min_version) > versionToInt(settings.VERSION): + logger.warning("In {} webodmMinVersion is set to {} but WebODM version is {}. Plugin will not be loaded. Update WebODM.".format(manifest_path, min_version, settings.VERSION)) + continue + # Instantiate the plugin try: module = importlib.import_module("plugins.{}".format(dir)) @@ -63,3 +77,23 @@ def get_active_plugins(): def get_plugins_path(): current_path = os.path.dirname(os.path.realpath(__file__)) return os.path.abspath(os.path.join(current_path, "..", "..", "plugins")) + + +def versionToInt(version): + """ + Converts a WebODM version string (major.minor.build) to a integer value + for comparison + >>> versionToInt("1.2.3") + 100203 + >>> versionToInt("1") + 100000 + >>> versionToInt("1.2.3.4") + 100203 + >>> versionToInt("wrong") + -1 + """ + + try: + return sum([reduce(lambda mult, ver: mult * ver, i) for i in zip([100000, 100, 1], map(int, version.split(".")))]) + except: + return -1 \ No newline at end of file diff --git a/app/templates/app/base.html b/app/templates/app/base.html index 4c04533e..f644c74a 100644 --- a/app/templates/app/base.html +++ b/app/templates/app/base.html @@ -90,7 +90,6 @@