def normalizedVersion(ver): try: modv = '.'.join(ver.split('.')[:4]).split('-', 1)[ 0] # Clean the version i.e. Turn 1.2.3.4-asdf8-ads7f into 1.2.3.4 return verlib.NormalizedVersion( verlib.suggest_normalized_version(modv)) except: if ver: ERROR() return verlib.NormalizedVersion( verlib.suggest_normalized_version('0.0.0'))
def nextversion(current_version): """Returns incremented module version number. :param current_version: version string to increment :returns: Next version string (PEP 386 compatible) if possible. If impossible (since `current_version` is too far from PEP 386), `None` is returned. """ norm_ver = verlib.suggest_normalized_version(current_version) if norm_ver is None: return None norm_ver = verlib.NormalizedVersion(norm_ver) # increment last version figure parts = norm_ver.parts # see comments of `verlib.py` to get the idea of `parts` assert (len(parts) == 3) if len(parts[2]) > 1: # postdev if parts[2][-1] == 'f': # when `post` exists but `dev` doesn't parts = _mk_incremented_parts(parts, part_idx=2, in_part_idx=-2, incval=1) else: # when both `post` and `dev` exist parts = _mk_incremented_parts(parts, part_idx=2, in_part_idx=-1, incval=1) elif len(parts[1]) > 1: # prerel parts = _mk_incremented_parts(parts, part_idx=1, in_part_idx=-1, incval=1) else: # version & extraversion parts = _mk_incremented_parts(parts, part_idx=0, in_part_idx=-1, incval=1) norm_ver.parts = parts return str(norm_ver)
def Version(ver_string): return verlib.NormalizedVersion( verlib.suggest_normalized_version(ver_string))
# pylint: disable=invalid-name """ This module contains the high-level functions to access the library. Care is taken to make this as pythonic as possible and hide as many of the gory implementations as possible. """ from __future__ import unicode_literals from collections import namedtuple import verlib # !!! DO NOT REMOVE !!! The following import triggers the processing of SNMP # Types and thus populates the Registry. If this is not included, Non x.690 # SNMP types will not be properly detected! import puresnmp.types from puresnmp.api.pythonic import (bulkget, bulkwalk, get, getnext, multiget, multigetnext, multiset, multiwalk, set, table, walk) from .version import VERSION # Simple version information as text __version__ = VERSION # The following line makes the version information available, and also serves # as a sanity check that the version number is PEP-440 compliant. verlib would # raise an exception if it isn't! version_info = verlib.NormalizedVersion(__version__)