def valid_mediator_implementation(value, allow_empty_version=False): """Returns a tuple of (valid, error) indicating whether the provided string is a valid mediator implementation for mediated links. 'valid' is a boolean and 'error' is None or a string containing the error.""" error = "" iname = iver = None if isinstance(value, basestring): if "@" in value: iname, iver = value.rsplit("@", 1) else: iname = value if iver or (iver == "" and not allow_empty_version): try: version.Version(iver) except version.VersionError as e: error = str(e) if not error and iname and re.match("^[a-zA-Z0-9\-]+$", iname): return True, None if error: return False, _("'{value}' is not a valid " "mediator-implementation; only alphanumeric characters and " "a version dot-sequence following a single '@' are allowed: " "{error}").format(**locals()) return False, _("'{0}' is not a valid mediator-implementation; only " "alphanumeric characters and a version dot-sequence following a " "single '@' are allowed").format(value)
def filter_results(results, mver): found = 0 last_stem = None for result in results: if found and \ ((found - start_point) >= num_to_return): break if result[1] == qp.Query.RETURN_PACKAGES: pfmri = result[2] elif result[1] == qp.Query.RETURN_ACTIONS: pfmri = result[2][0] if mver is not None: if mver != version.Version(pfmri.split( "@", 1)[1], None): continue if return_latest and \ result[1] == qp.Query.RETURN_PACKAGES: # Latest version filtering can only be # done for packages as only they are # guaranteed to be in version order. stem = result[2].split("@", 1)[0] if last_stem == stem: continue else: last_stem = stem found += 1 if found > start_point: yield result
def parse_mediator_implementation(value): """Parses the provided mediator implementation string for a link and returns a tuple of (name, version) where 'name' is a string containing the name of the implementation and 'version' is None or a pkg.version object representing the version. If the implementation is not valid a tuple of (None, None) will be returned.""" if not isinstance(value, basestring): return None, None if "@" in value: try: impl_name, impl_ver = value.rsplit("@", 1) except (ValueError, AttributeError): # Can't parse implementation correctly, so # return a tuple of None. return None, None else: impl_name = value impl_ver = None if impl_ver: try: impl_ver = version.Version(impl_ver) except version.VersionError: # If part of implementation can't be parsed, then # return nothing at all. return None, None return impl_name, impl_ver
def _fmri_from_path(pkg, vers): """Helper method that takes the full path to the package directory and the name of the manifest file, and returns an FMRI constructed from the information in those components.""" v = version.Version(urllib.unquote(vers), None) f = fmri.PkgFmri(urllib.unquote(os.path.basename(pkg)), None) f.version = v return f
def __check_preserve_version(self, orig): """Any action that can have a 'preserve' attribute should also be able to have a 'preserve-version' attribute (that represents a simple package FMRI release version; no timestamp, etc., just 'X.n.n...'). In the absence of a 'preserve-version' attribute, '0' will be assumed. When performing downgrades, if the installed editable file has been modified (compared to the proposed packaged version), the behavior will be as follows: if the installed action's 'preserve-version' is greater than the proposed 'preserve-version', the installed file will be renamed with '.update' and the proposed file will be installed. if the installed action's 'preserve-version' is equal to or less than the proposed 'preserve-version', the installed file content will not be modified.""" orig_preserve_ver = version.Version("0") preserve_ver = version.Version("0") try: ver = orig.attrs["preserve-version"] orig_preserve_ver = version.Version(ver) except KeyError: pass try: ver = self.attrs["preserve-version"] preserve_ver = version.Version(ver) except KeyError: pass if orig_preserve_ver > preserve_ver: # .old is intentionally avoided here to prevent # accidental collisions with the normal install # process. return "renameold.update" return True
def valid_mediator_version(value): """Returns a tuple of (valid, error) indicating whether the provided string is a valid mediator version for a link mediation. 'valid' is a boolean and 'error' is None or a string containing the error.""" error = "" if isinstance(value, basestring): try: version.Version(value) return True, None except version.VersionError as e: error = str(e) if error: return False, _("'{value}' is not a valid mediator-version: " "{error}").format(**locals()) return False, _("'{0}' is not a valid mediator-version").format(value)
def testbogusversion6(self): """ insert a bad char at (almost) every position in a version""" v = "12.34.56-78:19760113T111111Z" # Check that v is valid version.Version(v) badchars = ["T", "Z", "@", "-", ".", ",", ":"] becareful = [".", ",", "-"] for b in badchars: for x in range(0, len(v)): vlist = list(v) if b in becareful and vlist[x] in becareful: continue if vlist[x] == b: continue vlist[x] = b vv = "".join(vlist) self.assertRaises(version.IllegalVersion, version.Version, vv, "5.11")
def vers_different(num): return version.Version("0.5.11,5.11-0.{0:d}:{1:0=8d}T172804Z".format( num, num))
def vers(num): return version.Version("0.5.11-0.111:20090428T172804Z")
def setUp(self): self.d1 = version.DotSequence("1.1.3") self.d2 = version.DotSequence("1.1.3") self.d3 = version.DotSequence("5.4") self.d4 = version.DotSequence("5.6") self.d5 = version.DotSequence("5.4.1") self.d6 = version.DotSequence("5.5.1") self.d7 = version.DotSequence("6.5.1") self.v1 = version.Version("5.5.1-10:20051122T000000Z", "5.5.1") self.v2 = version.Version("5.5.1-10:20070318T123456Z", "5.5.1") self.v3 = version.Version("5.5.1-10", "5.5") self.v4 = version.Version("5.5.1-6", "5.4") self.v5 = version.Version("5.6,1", "5.4") self.v6 = version.Version("5.7", "5.4") self.v7 = version.Version("5.10", "5.5.1") self.v8 = version.Version("5.10.1", "5.5.1") self.v9 = version.Version("5.11", "5.5.1") self.v9same = version.Version("5.11", "5.5.1") self.v10 = version.Version("0.1,5.11-1", None) self.v11 = version.Version("0.1,5.11-1:20070710T120000Z", None) self.v12 = version.Version("5.11-0.72:20070921T211008Z", "0.5.11") self.v13 = version.Version("5.11-0.72:20070922T160226Z", "0.5.11") self.v14 = version.Version("0.1,5.11", None) self.v15 = version.Version("0.1,5.11:20071014T234545Z", None) self.v16 = version.Version("0.2,5.11", None) self.v17 = version.Version("0.2,5.11-1:20071029T131519Z", None) self.v18 = version.Version("5", "5")