Commit 79e97dc pungi-koji: new cmd option '--latest-link-status'

1 file Authored and Committed by qwan 5 months ago
pungi-koji: new cmd option '--latest-link-status'

Add a new option 'latest-link-status' to pungi-koji, if this is
specified, pungi will only create the latest symbol link to the compose
when compose's status matches the specified statuses. The status name is
case insensitive. If the option is not specified it will act as before.

Example:

pungi-koji --target-dir=_composes --config=data/dummy-pungi.conf \
--test --latest-link-status=finished --latest-link-status=finished_incomplete

Signed-off-by: Qixiang Wan <qwan@redhat.com>

    
 1 @@ -134,6 +134,13 @@
 2           help="don't create latest symbol link to this compose"
 3       )
 4       parser.add_option(
 5 +         "--latest-link-status",
 6 +         metavar="STATUS",
 7 +         action="append",
 8 +         default=[],
 9 +         help="only create latest symbol link to this compose when compose status matches specified status",
10 +     )
11 +     parser.add_option(
12           "--quiet",
13           action="store_true",
14           default=False,
15 @@ -181,6 +188,7 @@
16       opts.config = os.path.abspath(opts.config)
17   
18       create_latest_link = not opts.no_latest_link
19 +     latest_link_status = opts.latest_link_status or None
20   
21       import kobo.conf
22       import kobo.log
23 @@ -234,13 +242,13 @@
24       notifier.compose = compose
25       COMPOSE = compose
26       try:
27 -         run_compose(compose, create_latest_link)
28 +         run_compose(compose, create_latest_link=create_latest_link, latest_link_status=latest_link_status)
29       except Exception, ex:
30           compose.log_error("Compose run failed: %s" % ex)
31           raise
32   
33   
34 - def run_compose(compose, create_latest_link=True):
35 + def run_compose(compose, create_latest_link=True, latest_link_status=None):
36       import pungi.phases
37       import pungi.metadata
38   
39 @@ -414,8 +422,21 @@
40       test_phase.start()
41       test_phase.stop()
42   
43 +     compose.write_status("FINISHED")
44 +     latest_link = False
45       if create_latest_link:
46 -         # create a latest symlink
47 +         if latest_link_status is None:
48 +             # create latest symbol link by default if latest_link_status is not specified
49 +             latest_link = True
50 +         else:
51 +             latest_link_status = [s.upper() for s in latest_link_status]
52 +             if compose.get_status() in [s.upper() for s in latest_link_status]:
53 +                 latest_link = True
54 +             else:
55 +                 compose.log_warning("Compose status (%s) doesn't match with specified latest-link-status (%s), not create latest link."
56 +                                     % (compose.get_status(), str(latest_link_status)))
57 + 
58 +     if latest_link:
59           compose_dir = os.path.basename(compose.topdir)
60           if len(compose.conf["release_version"].split(".")) == 1:
61               symlink_name = "latest-%s-%s" % (compose.conf["release_short"], compose.conf["release_version"])
62 @@ -436,7 +457,6 @@
63               compose.log_error("Couldn't create latest symlink: %s" % ex)
64   
65       compose.log_info("Compose finished: %s" % compose.topdir)
66 -     compose.write_status("FINISHED")
67   
68   
69   if __name__ == "__main__":