|
5 | 5 | '''
|
6 | 6 |
|
7 | 7 | import argparse
|
| 8 | +import collections |
| 9 | +import os |
| 10 | +import sys |
8 | 11 |
|
9 | 12 | from cosalib.builds import Builds
|
| 13 | +from cosalib.cmdlib import get_timestamp |
| 14 | + |
| 15 | +Build = collections.namedtuple('Build', ['id', 'timestamp', 'basearches']) |
10 | 16 |
|
11 | 17 | parser = argparse.ArgumentParser()
|
12 | 18 | parser.add_argument("--workdir", default='.', help="Path to workdir")
|
13 | 19 | args = parser.parse_args()
|
14 | 20 |
|
15 | 21 | builds = Builds(args.workdir)
|
| 22 | + |
| 23 | +scanned_builds = [] |
| 24 | +builds_dir = os.path.join(args.workdir, "builds") |
| 25 | + |
| 26 | +# first, pick up all the builds from the dir itself |
| 27 | +with os.scandir(builds_dir) as it: |
| 28 | + for entry in it: |
| 29 | + # ignore non-dirs |
| 30 | + if not entry.is_dir(follow_symlinks=False): |
| 31 | + # those are really the only two non-dir things we expect there |
| 32 | + if entry.name not in ['builds.json', 'latest']: |
| 33 | + print(f"Ignoring non-directory {entry.path}") |
| 34 | + continue |
| 35 | + |
| 36 | + # scan all per-arch builds, pick up the most recent build of those as |
| 37 | + # the overall "build" timestamp for pruning purposes |
| 38 | + with os.scandir(entry.path) as basearch_it: |
| 39 | + multiarch_build = None |
| 40 | + for basearch_entry in basearch_it: |
| 41 | + # ignore non-dirs |
| 42 | + if not basearch_entry.is_dir(follow_symlinks=False): |
| 43 | + print(f"Ignoring non-directory {basearch_entry.path}") |
| 44 | + continue |
| 45 | + ts = get_timestamp(basearch_entry) |
| 46 | + if not ts: |
| 47 | + continue |
| 48 | + if not multiarch_build: |
| 49 | + multiarch_build = Build(id=entry.name, timestamp=ts, |
| 50 | + basearches=[basearch_entry.name]) |
| 51 | + else: |
| 52 | + multiarch_build.basearches += [basearch_entry.name] |
| 53 | + multiarch_build.timestamp = max( |
| 54 | + multiarch_build.timestamp, ts) |
| 55 | + if multiarch_build: |
| 56 | + scanned_builds.append(multiarch_build) |
| 57 | + |
| 58 | +# just get the trivial case out of the way |
| 59 | +if len(scanned_builds) == 0: |
| 60 | + print("No builds found!") |
| 61 | + sys.exit(0) |
| 62 | + |
| 63 | +# sort by timestamp, newest first |
| 64 | +scanned_builds = sorted(scanned_builds, |
| 65 | + key=lambda x: x.timestamp, |
| 66 | + reverse=True) |
| 67 | + |
| 68 | +builds.raw()['builds'] = [] |
| 69 | +for build in reversed(scanned_builds): |
| 70 | + for basearch in build.basearches: |
| 71 | + builds.insert_build(build.id, basearch) |
| 72 | + |
16 | 73 | builds.bump_timestamp()
|
17 | 74 | print("Build timestamp was updated")
|
0 commit comments