Read about our upcoming Code of Conduct on this issue

Commit 08727928 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Extracted version parsing from fetch_watch_tags

It will be useful in other scripts
parent bfd554f78f9a
......@@ -11,6 +11,8 @@
import requests
from subprocess import Popen, PIPE
from .version import level2_version
# Regular expression for a new version tag on the remote.
# The required whitespace after the last number excludes rc releases
# and similar on purpose
......@@ -62,13 +64,6 @@
"""
def level2_version(s):
split = s.strip().split('.')
if len(split) != 2:
raise TypeError("Invalid level 2 version string")
return int(split[0]), int(split[1])
def filter_new_versions(new_versions, series=None):
"""Return only the highest version, optionally for each specified serie
......
# Copyright 2020-2021 Georges Racinet <georges.racinet@octobus.net>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
#
# SPDX-License-Identifier: GPL-2.0-or-later
def level2_version(s):
"""Validate major.minor version strings.
Nothing else is accepted.
:raises: `TypeError` if invalid, so that it can be used as a type
in :class:`argparse.ArgumentParser`.
:returns: the version as a pair of integers.
Examples::
>>> level2_version('13.10')
(13, 10)
>>> for version_str in ('foo', '13.7.9'):
... try: level2_version(version_str)
... except TypeError as exc: print(exc.args[0])
Invalid level 2 version string: 'foo'
Invalid level 2 version string: '13.7.9'
"""
split = s.strip().split('.')
if len(split) != 2:
raise TypeError("Invalid level 2 version string: %r" % s)
return int(split[0]), int(split[1])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment