aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/boost/version.py
blob: 2b5861cd4f0da95e49d0ea1aa8e2864bf424cc61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (c) 2020 Egor Tensin <egor@tensin.name>
# This file is part of the "cmake-common" project.
# For details, see https://github.com/egor-tensin/cmake-common
# Distributed under the MIT License.

from collections import namedtuple
from functools import total_ordering
import os.path
import re

_Version = namedtuple("_Version", ["major", "minor", "patch"])


@total_ordering
class Version:
    def __init__(self, major, minor, patch):
        self._impl = _Version(major, minor, patch)

    @property
    def major(self):
        return self._impl.major

    @property
    def minor(self):
        return self._impl.minor

    @property
    def patch(self):
        return self._impl.patch

    def __lt__(self, other):
        return self._impl < other._impl

    def __eq__(self, other):
        return self._impl == other._impl

    @staticmethod
    def from_string(s):
        result = re.match(r"^(\d+)\.(\d+)\.(\d+)$", s)
        if result is None:
            raise ValueError(f"invalid Boost version: {s}")
        major = int(result.group(1))
        minor = int(result.group(2))
        patch = int(result.group(3))
        return Version(major, minor, patch)

    def __str__(self):
        return f"{self.major}.{self.minor}.{self.patch}"

    @property
    def archive_ext(self):
        return ".tar.gz"

    def dir_path(self, parent_dir):
        return os.path.join(parent_dir, self.dir_name)

    @property
    def dir_name(self):
        return f"boost_{self.major}_{self.minor}_{self.patch}"

    @property
    def archive_name(self):
        return f"{self.dir_name}{self.archive_ext}"

    def get_download_url(self):
        return f"https://archives.boost.io/release/{self}/source/{self.archive_name}"