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)
| 33 | |
| 34 | |
| 35 | def _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 | |
| 58 | MAX_PLUGIN_IMPORT_FILES = getattr(settings, "DISPATCHARR_PLUGIN_IMPORT_MAX_FILES", 2000) |