Module: check_mk
Branch: master
Commit: 6ebe49cf52113d9af57eef7e72cf0a64e9eb558e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6ebe49cf52113d…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Fri Dec 14 11:19:58 2018 +0100
Centralize parse_check_mk_version().
Change-Id: If66ca16f1ce2f7dcde3a39cce3b5f0c52b0644d2
---
cmk_base/data_sources/tcp.py | 5 +++--
cmk_base/packaging.py | 10 +++++-----
cmk_base/utils.py | 46 --------------------------------------------
3 files changed, 8 insertions(+), 53 deletions(-)
diff --git a/cmk_base/data_sources/tcp.py b/cmk_base/data_sources/tcp.py
index 97c65c5..ad9b683 100644
--- a/cmk_base/data_sources/tcp.py
+++ b/cmk_base/data_sources/tcp.py
@@ -28,6 +28,7 @@ import socket
import cmk.debug
from cmk.exceptions import MKTerminate, MKGeneralException
+import cmk.werks
import cmk_base.utils as utils
import cmk_base.config as config
@@ -274,8 +275,8 @@ class TCPDataSource(CheckMKAgentDataSource):
if utils.is_daily_build_version(agent_version):
return False
- if utils.parse_check_mk_version(agent_version) \
- < utils.parse_check_mk_version(spec['release']):
+ if cmk.werks.parse_check_mk_version(agent_version) \
+ < cmk.werks.parse_check_mk_version(spec['release']):
return False
return True
diff --git a/cmk_base/packaging.py b/cmk_base/packaging.py
index ae55be4..6542c71 100644
--- a/cmk_base/packaging.py
+++ b/cmk_base/packaging.py
@@ -34,11 +34,11 @@ import subprocess
import json
from cStringIO import StringIO
-import cmk.tty as tty
-import cmk.paths
import cmk.ec.export
-
import cmk.log
+import cmk.paths
+import cmk.tty as tty
+import cmk.werks
import cmk_base.utils
logger = cmk.log.get_logger(__name__)
@@ -634,8 +634,8 @@ def verify_check_mk_version(package):
compatible = True
try:
- compatible = cmk_base.utils.parse_check_mk_version(min_version) \
- <= cmk_base.utils.parse_check_mk_version(cmk_version)
+ compatible = cmk.werks.parse_check_mk_version(min_version) \
+ <= cmk.werks.parse_check_mk_version(cmk_version)
except:
# Be compatible: When a version can not be parsed, then skip this check
if cmk.debug.enabled():
diff --git a/cmk_base/utils.py b/cmk_base/utils.py
index b5139a2..fc3be54 100644
--- a/cmk_base/utils.py
+++ b/cmk_base/utils.py
@@ -61,52 +61,6 @@ def branch_of_daily_build(v):
return v.split('-')[0]
-# Parses versions of Check_MK and converts them into comparable integers.
-# This does not handle daily build numbers, only official release numbers.
-# 1.2.4p1 -> 01020450001
-# 1.2.4 -> 01020450000
-# 1.2.4b1 -> 01020420100
-# 1.2.3i1p1 -> 01020310101
-# 1.2.3i1 -> 01020310100
-# TODO: Copied to werks.py - find location for common code.
-def parse_check_mk_version(v):
- def extract_number(s):
- number = ''
- for i, c in enumerate(s):
- try:
- int(c)
- number += c
- except ValueError:
- s = s[i:]
- return number and int(number) or 0, s
- return number and int(number) or 0, ''
-
- parts = v.split('.')
- while len(parts) < 3:
- parts.append("0")
-
- major, minor, rest = parts
- sub, rest = extract_number(rest)
-
- if not rest:
- val = 50000
- elif rest[0] == 'p':
- num, rest = extract_number(rest[1:])
- val = 50000 + num
- elif rest[0] == 'i':
- num, rest = extract_number(rest[1:])
- val = 10000 + num * 100
-
- if rest and rest[0] == 'p':
- num, rest = extract_number(rest[1:])
- val += num
- elif rest[0] == 'b':
- num, rest = extract_number(rest[1:])
- val = 20000 + num * 100
-
- return int('%02d%02d%02d%05d' % (int(major), int(minor), sub, val))
-
-
def total_size(o, handlers=None):
""" Returns the approximate memory footprint an object and all of its
contents.