mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 02:27:51 +01:00
3efbc12706
This adds the `cln_parse_rpcversion` helper that is already used in various plugins to pyln-client, so it does not need to be copied around anymore. Changelog-None
24 lines
889 B
Python
24 lines
889 B
Python
import re
|
|
|
|
|
|
def cln_parse_rpcversion(string):
|
|
"""
|
|
Parse cln version string to determine RPC version.
|
|
|
|
cln switched from 'semver' alike `major.minor.sub[rcX][-mod]`
|
|
to ubuntu style with version 22.11 `yy.mm[.patch][-mod]`
|
|
make sure we can read all of them for (the next 80 years).
|
|
"""
|
|
rpcversion = string
|
|
if rpcversion.startswith('v'): # strip leading 'v'
|
|
rpcversion = rpcversion[1:]
|
|
if rpcversion.find('-') != -1: # strip mods
|
|
rpcversion = rpcversion[:rpcversion.find('-')]
|
|
if re.search('.*(rc[\\d]*)$', rpcversion): # strip release candidates
|
|
rpcversion = rpcversion[:rpcversion.find('rc')]
|
|
if rpcversion.count('.') == 1: # imply patch version 0 if not given
|
|
rpcversion = rpcversion + '.0'
|
|
|
|
# split and convert numeric string parts to actual integers
|
|
return list(map(int, rpcversion.split('.')))
|