File: ios.py

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (91 lines) | stat: -rw-r--r-- 2,613 bytes parent folder | download | duplicates (12)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Defines the characteristics of an iOS version number."""

import re

import attr

from mozilla_version.parser import positive_int_or_none

from .version import ShipItVersion


@attr.s(frozen=True, eq=False, hash=True)
class MobileIosVersion(ShipItVersion):
    """
    Class representing an iOS version number.

    iOS version numbers are a bit different in that they don't have a patch number
    but they have a beta one.
    """

    beta_number = attr.ib(type=int, converter=positive_int_or_none, default=None)

    _VALID_ENOUGH_VERSION_PATTERN = re.compile(
        r"""
        ^(?P<major_number>\d+)
        \.(?P<minor_number>\d+)
        (b(?P<beta_number>\d+))?$""",
        re.VERBOSE,
    )

    _OPTIONAL_NUMBERS = ("beta_number",)
    _ALL_NUMBERS = ShipItVersion._MANDATORY_NUMBERS + _OPTIONAL_NUMBERS

    def __str__(self):
        """
        Format the version as a string.

        Because iOS is different, the format is "major.minor(.beta)".
        """
        version = f"{self.major_number}.{self.minor_number}"

        if self.beta_number is not None:
            version += f"b{self.beta_number}"

        return version

    def _create_bump_kwargs(self, field):
        """
        Create a version bump for the required field.

        Version bumping is a bit different for iOS as we don't have a patch number
        despite shipit expecting one. So when asked to bump the patch version, we bump
        the minor instead.
        """
        if field == "patch_number":
            field = "minor_number"

        kwargs = super()._create_bump_kwargs(field)

        # If we get a bump request for anything but the beta number, remove it
        if field != "beta_number":
            del kwargs["beta_number"]

        return kwargs

    @property
    def is_beta(self):
        """Returns true if the version is considered a beta one."""
        return self.beta_number is not None

    @property
    def is_release_candidate(self):
        """
        Returns true if the version is a release candidate.

        For iOS versions, this is always false.
        """
        return False

    def _compare(self, other):
        """Compare this release with another."""
        if isinstance(other, str):
            other = MobileIosVersion.parse(other)
        if not isinstance(other, MobileIosVersion):
            raise ValueError(f'Cannot compare "{other}", type not supported!')

        difference = super()._compare(other)
        if difference != 0:
            return difference

        return self._substract_other_number_from_this_number(other, "beta_number")