• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / mozregression / 11572196313

29 Oct 2024 10:42AM CUT coverage: 35.046%. First build
11572196313

Pull #1450

github

web-flow
Merge 8994ec23b into f558f7daa
Pull Request #1450: Bug 1763188 - Add Snap support using TC builds

65 of 209 new or added lines in 8 files covered. (31.1%)

1057 of 3016 relevant lines covered (35.05%)

1.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/mozregression/build_info.py
1
"""
2
The BuildInfo classes, that are used to store information a build.
3
"""
4

5
from __future__ import absolute_import
3✔
6

7
import datetime
3✔
8
import re
3✔
9
from urllib.parse import urlparse
3✔
10

11
FIELDS = []
3✔
12

13

14
def export(func):
3✔
15
    FIELDS.append(func.__name__)
3✔
16
    return func
3✔
17

18

19
class BuildInfo(object):
3✔
20
    """
21
    Store information about a build to be able to download and run it.
22

23
    a BuildInfo is built by calling
24
    :meth:`mozregression.fetch_build_info.FetchBuildInfo.find_build_info`.
25
    """
26

27
    def __init__(
3✔
28
        self,
29
        fetch_config,
30
        build_type,
31
        build_url,
32
        build_date,
33
        changeset,
34
        repo_url,
35
        repo_name,
36
        task_id=None,
37
    ):
38
        self._fetch_config = fetch_config
×
NEW
39
        self._force_update = False  # will be set True by SnapHandler
×
40
        self._build_type = build_type
×
41
        self._build_url = build_url
×
42
        self._build_date = build_date
×
43
        self._changeset = changeset
×
44
        self._repo_url = repo_url
×
45
        self._repo_name = repo_name
×
46
        self._build_file = None
×
47
        self._task_id = task_id
×
48

49
    @property
3✔
50
    @export
3✔
51
    def build_type(self):
3✔
52
        """
53
        Either 'nightly' or 'integration'
54
        """
55
        return self._build_type
×
56

57
    @property
3✔
58
    @export
3✔
59
    def app_name(self):
3✔
60
        """
61
        The application name, such as "firefox"
62
        """
63
        return self._fetch_config.app_name
×
64

65
    @property
3✔
66
    @export
3✔
67
    def build_url(self):
3✔
68
        """
69
        The url to download the build
70
        """
71
        return self._build_url
×
72

73
    @property
3✔
74
    @export
3✔
75
    def build_date(self):
3✔
76
        """
77
        The date of the build
78
        """
79
        return self._build_date
×
80

81
    @property
3✔
82
    @export
3✔
83
    def changeset(self):
3✔
84
        """
85
        The changeset of the build. For old nightlies, this can be None.
86
        """
87
        return self._changeset
×
88

89
    @property
3✔
90
    @export
3✔
91
    def repo_url(self):
3✔
92
        """
93
        The url of the repository. For old nightlies, this can be None.
94
        """
95
        return self._repo_url
×
96

97
    @property
3✔
98
    @export
3✔
99
    def repo_name(self):
3✔
100
        """
101
        the repository name, e.g. 'mozilla-central'
102
        """
103
        return self._repo_name
×
104

105
    @property
3✔
106
    @export
3✔
107
    def build_file(self):
3✔
108
        """
109
        The build file, once downloaded. This property is None when the
110
        BuildInfo is instanciated and should be set later.
111
        """
112
        return self._build_file
×
113

114
    @property
3✔
115
    @export
3✔
116
    def task_id(self):
3✔
117
        """
118
        The task ID, for Taskcluster builds.
119
        """
120
        return self._task_id
×
121

122
    @build_file.setter
3✔
123
    def build_file(self, build_file):
3✔
124
        self._build_file = build_file
×
125

126
    @property
3✔
127
    def short_changeset(self):
3✔
128
        """
129
        Returns the first 8 characters of the build changeset.
130
        """
131
        return self.changeset[:8]
×
132

133
    def update_from_app_info(self, app_info):
3✔
134
        """
135
        Takes an app_info (as returned by mozversion) and update the build info
136
        content if required.
137

138
        This helps to build the pushlog url for old nightlies.
139
        """
NEW
140
        if self._changeset is None or self._force_update is True:
×
141
            self._changeset = app_info.get("application_changeset")
×
NEW
142
        if self._repo_url is None or self._force_update is True:
×
143
            self._repo_url = app_info.get("application_repository")
×
144

145
    def persist_filename_for(self, data, regex=True):
3✔
146
        """
147
        Returns the persistent filename for the given data.
148

149
        `data` should be a date or datetime object if the build type is
150
        'nightly', else a changeset.
151

152
        if `regex` is True, instead of returning the persistent filename
153
        it is returned a string (regex pattern) that can match a filename.
154
        The pattern only allows the build name to be different, by using
155
        the fetch_config.build_regex() value. For example, it can return:
156

157
        '2015-01-11--mozilla-central--firefox.*linux-x86_64\\.tar.bz2$'
158
        """
159
        if self.build_type == "nightly":
×
160
            if isinstance(data, datetime.datetime):
×
161
                prefix = data.strftime("%Y-%m-%d-%H-%M-%S")
×
162
            else:
163
                prefix = str(data)
×
164
            persist_part = ""
×
165
        else:
166
            prefix = str(data[:12])
×
167
            persist_part = self._fetch_config.integration_persist_part()
×
168
        if persist_part:
×
169
            persist_part = "-" + persist_part
×
170
        extra = self._fetch_config.extra_persist_part()
×
171
        if extra:
×
172
            extra = extra + "--"
×
173
        full_prefix = "{}{}--{}--{}".format(prefix, persist_part, self.repo_name, extra)
×
174
        if regex:
×
175
            full_prefix = re.escape(full_prefix)
×
176
            appname = self._fetch_config.build_regex()
×
177
        else:
178
            appname = urlparse(self.build_url).path.replace("%2F", "/").split("/")[-1]
×
179
        return "{}{}".format(full_prefix, appname)
×
180

181
    @property
3✔
182
    def persist_filename(self):
3✔
183
        """
184
        Compute and return the persist filename to use to store this build.
185
        """
186
        if self.build_type == "nightly":
×
187
            data = self.build_date
×
188
        else:
189
            data = self.changeset
×
190
        return self.persist_filename_for(data, regex=False)
×
191

192
    def to_dict(self):
3✔
193
        """
194
        Export some public properties as a dict.
195
        """
196
        return dict((field, getattr(self, field)) for field in FIELDS)
×
197

198

199
class NightlyBuildInfo(BuildInfo):
3✔
200
    def __init__(self, fetch_config, build_url, build_date, changeset, repo_url):
3✔
201
        BuildInfo.__init__(
×
202
            self,
203
            fetch_config,
204
            "nightly",
205
            build_url,
206
            build_date,
207
            changeset,
208
            repo_url,
209
            fetch_config.get_nightly_repo(build_date),
210
        )
211

212

213
class IntegrationBuildInfo(BuildInfo):
3✔
214
    def __init__(self, fetch_config, build_url, build_date, changeset, repo_url, task_id=None):
3✔
215
        BuildInfo.__init__(
×
216
            self,
217
            fetch_config,
218
            "integration",
219
            build_url,
220
            build_date,
221
            changeset,
222
            repo_url,
223
            fetch_config.integration_branch,
224
            task_id=task_id,
225
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc