diff options
Diffstat (limited to 'meta/lib/oeqa/utils/gitarchive.py')
| -rw-r--r-- | meta/lib/oeqa/utils/gitarchive.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/meta/lib/oeqa/utils/gitarchive.py b/meta/lib/oeqa/utils/gitarchive.py index fddd608593..ff614d06bb 100644 --- a/meta/lib/oeqa/utils/gitarchive.py +++ b/meta/lib/oeqa/utils/gitarchive.py | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | import os | 17 | import os |
| 18 | import re | 18 | import re |
| 19 | import sys | 19 | import sys |
| 20 | from operator import attrgetter | ||
| 21 | from collections import namedtuple | ||
| 20 | from oeqa.utils.git import GitRepo, GitError | 22 | from oeqa.utils.git import GitRepo, GitError |
| 21 | 23 | ||
| 22 | class ArchiveError(Exception): | 24 | class ArchiveError(Exception): |
| @@ -171,3 +173,72 @@ def gitarchive(data_dir, git_dir, no_create, bare, commit_msg_subject, commit_ms | |||
| 171 | log.info("Pushing data to remote") | 173 | log.info("Pushing data to remote") |
| 172 | data_repo.run_cmd(cmd) | 174 | data_repo.run_cmd(cmd) |
| 173 | 175 | ||
| 176 | # Container class for tester revisions | ||
| 177 | TestedRev = namedtuple('TestedRev', 'commit commit_number tags') | ||
| 178 | |||
| 179 | def get_test_runs(log, repo, tag_name, **kwargs): | ||
| 180 | """Get a sorted list of test runs, matching given pattern""" | ||
| 181 | # First, get field names from the tag name pattern | ||
| 182 | field_names = [m.group(1) for m in re.finditer(r'{(\w+)}', tag_name)] | ||
| 183 | undef_fields = [f for f in field_names if f not in kwargs.keys()] | ||
| 184 | |||
| 185 | # Fields for formatting tag name pattern | ||
| 186 | str_fields = dict([(f, '*') for f in field_names]) | ||
| 187 | str_fields.update(kwargs) | ||
| 188 | |||
| 189 | # Get a list of all matching tags | ||
| 190 | tag_pattern = tag_name.format(**str_fields) | ||
| 191 | tags = repo.run_cmd(['tag', '-l', tag_pattern]).splitlines() | ||
| 192 | log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) | ||
| 193 | |||
| 194 | # Parse undefined fields from tag names | ||
| 195 | str_fields = dict([(f, r'(?P<{}>[\w\-.()]+)'.format(f)) for f in field_names]) | ||
| 196 | str_fields['branch'] = r'(?P<branch>[\w\-.()/]+)' | ||
| 197 | str_fields['commit'] = '(?P<commit>[0-9a-f]{7,40})' | ||
| 198 | str_fields['commit_number'] = '(?P<commit_number>[0-9]{1,7})' | ||
| 199 | str_fields['tag_number'] = '(?P<tag_number>[0-9]{1,5})' | ||
| 200 | # escape parenthesis in fields in order to not messa up the regexp | ||
| 201 | fixed_fields = dict([(k, v.replace('(', r'\(').replace(')', r'\)')) for k, v in kwargs.items()]) | ||
| 202 | str_fields.update(fixed_fields) | ||
| 203 | tag_re = re.compile(tag_name.format(**str_fields)) | ||
| 204 | |||
| 205 | # Parse fields from tags | ||
| 206 | revs = [] | ||
| 207 | for tag in tags: | ||
| 208 | m = tag_re.match(tag) | ||
| 209 | groups = m.groupdict() | ||
| 210 | revs.append([groups[f] for f in undef_fields] + [tag]) | ||
| 211 | |||
| 212 | # Return field names and a sorted list of revs | ||
| 213 | return undef_fields, sorted(revs) | ||
| 214 | |||
| 215 | def get_test_revs(log, repo, tag_name, **kwargs): | ||
| 216 | """Get list of all tested revisions""" | ||
| 217 | fields, runs = get_test_runs(log, repo, tag_name, **kwargs) | ||
| 218 | |||
| 219 | revs = {} | ||
| 220 | commit_i = fields.index('commit') | ||
| 221 | commit_num_i = fields.index('commit_number') | ||
| 222 | for run in runs: | ||
| 223 | commit = run[commit_i] | ||
| 224 | commit_num = run[commit_num_i] | ||
| 225 | tag = run[-1] | ||
| 226 | if not commit in revs: | ||
| 227 | revs[commit] = TestedRev(commit, commit_num, [tag]) | ||
| 228 | else: | ||
| 229 | assert commit_num == revs[commit].commit_number, "Commit numbers do not match" | ||
| 230 | revs[commit].tags.append(tag) | ||
| 231 | |||
| 232 | # Return in sorted table | ||
| 233 | revs = sorted(revs.values(), key=attrgetter('commit_number')) | ||
| 234 | log.debug("Found %d tested revisions:\n %s", len(revs), | ||
| 235 | "\n ".join(['{} ({})'.format(rev.commit_number, rev.commit) for rev in revs])) | ||
| 236 | return revs | ||
| 237 | |||
| 238 | def rev_find(revs, attr, val): | ||
| 239 | """Search from a list of TestedRev""" | ||
| 240 | for i, rev in enumerate(revs): | ||
| 241 | if getattr(rev, attr) == val: | ||
| 242 | return i | ||
| 243 | raise ValueError("Unable to find '{}' value '{}'".format(attr, val)) | ||
| 244 | |||
