MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / _compare_versions

Function _compare_versions

apps/plugins/api_views.py:35–55  ·  view source on GitHub ↗

Compare two semver-like version strings. Returns negative if a < b, 0 if equal, positive if a > b. If either version is a prerelease (any dot-segment contains non-digit characters), numeric ordering is meaningless. Falls back to exact string equality: 0 if identical, 1 otherwise.

(a, b)

Source from the content-addressed store, hash-verified

33
34
35def _compare_versions(a, b):
36 """Compare two semver-like version strings.
37 Returns negative if a < b, 0 if equal, positive if a > b.
38
39 If either version is a prerelease (any dot-segment contains non-digit
40 characters), numeric ordering is meaningless. Falls back to exact string
41 equality: 0 if identical, 1 otherwise.
42 """
43 if not a or not b:
44 return 0
45 na = a.lstrip("v")
46 nb = b.lstrip("v")
47 if any(not p.isdigit() for p in na.split(".")) or any(not p.isdigit() for p in nb.split(".")):
48 return 0 if na == nb else 1
49 pa = [int(x) for x in na.split(".")]
50 pb = [int(x) for x in nb.split(".")]
51 for i in range(max(len(pa), len(pb))):
52 diff = (pa[i] if i < len(pa) else 0) - (pb[i] if i < len(pb) else 0)
53 if diff != 0:
54 return diff
55 return 0
56
57
58MAX_PLUGIN_IMPORT_FILES = getattr(settings, "DISPATCHARR_PLUGIN_IMPORT_MAX_FILES", 2000)

Callers 1

postMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected