summarylogtreecommitdiffstats
path: root/0009-Add-buildlog-option-to-fetch-buildlog-not-relative-t.patch
blob: 6df24d036b46f06d7b965d7a1fadc81bc5507a16 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= <bjorn.bidar@jolla.com>
Date: Tue, 2 Jan 2024 12:28:20 +0200
Subject: [PATCH] Add buildlog option to fetch buildlog not-relative to pkg-dir
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Björn Bidar <bjorn.bidar@jolla.com>
---
 osc/commandline.py | 77 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 68 insertions(+), 9 deletions(-)

diff --git a/osc/commandline.py b/osc/commandline.py
index 2525e282bf82462b45701ccfb14ca4517418d5e0..1bdf533b415c21c3da872d5b0e63e15548a30870 100644
--- a/osc/commandline.py
+++ b/osc/commandline.py
@@ -6373,6 +6373,10 @@ Please submit there instead, or use --nodevelproject to force direct submission.
                   help='get log start or end from the offset')
     @cmdln.option('-s', '--strip-time', action='store_true',
                         help='strip leading build time from the log')
+    @cmdln.option('-O', '--all-packages', action='store_true',
+                  help='Show buildlog for all packages of project')
+    @cmdln.option('-S', '--status', action='store', metavar='STATUS',
+                  help='Only show build of packages with STATUS')
     def do_buildlog(self, subcmd, opts, *args):
         """
         Shows the build log of a package
@@ -6388,31 +6392,54 @@ Please submit there instead, or use --nodevelproject to force direct submission.
         results' output. If the buildlog url is used buildlog command has the
         same behavior as remotebuildlog.
 
+        buildlog PROJECT PACKAGE [REPOSITORY] [ARCH]
+        buildlog PROJECT [REPOSITORY] [ARCH]
+        buildlog PACKAGE [REPOSITORY] [ARCH]
         buildlog [REPOSITORY ARCH | BUILDLOGURL]
         """
         project = package = repository = arch = None
 
         apiurl = self.get_api_url()
+        repo_arg_offset = 0
 
         if len(args) == 1 and args[0].startswith('http'):
             apiurl, project, package, repository, arch = parse_buildlogurl(args[0])
         else:
-            project = store_read_project(Path.cwd())
-            package = store_read_package(Path.cwd())
-            if len(args) == 1:
+            cwd = Path.cwd()
+            if is_project_dir(cwd) or is_package_dir(cwd):
+                project = store_read_project(cwd)
+            if len(args) > 2:
+                project = args[0]
+                package = args[1]
+                repo_arg_offset = 2
+            if len(args) >= 1:
+                if opts.all_packages:
+                    project = args[0]
+                    repo_arg_offset = 1
+                else:
+                    if not package and is_project_dir(cwd):
+                        package = args[0]
+                        prj = Project(cwd)
+                        if package not in prj.pacs_avialable:
+                            raise oscerr.WrongArgs(f'Package {package} doesn\'t exist in {project}')
+                        repo_arg_offset = 1
+            if not package and is_package_dir(cwd):
+                    package = store_read_package(cwd)
+            if len(args) - repo_arg_offset == 1:
                 repository, arch = self._find_last_repo_arch(args[0], fatal=False)
                 if repository is None:
                     # no local build with this repo was done
                     print('failed to guess arch, using hostarch')
-                    repository = args[0]
+                    repository = args[repo_arg_offset]
                     arch = osc_build.hostarch
-            elif len(args) < 2:
+            elif len(args) - repo_arg_offset < 2:
                 self.print_repos()
-            elif len(args) > 2:
+            elif len(args) - repo_arg_offset > 2:
+                print(len(args), repo_arg_offset, project, package)
                 raise oscerr.WrongArgs('Too many arguments.')
             else:
-                repository = args[0]
-                arch = args[1]
+                repository = args[0 + repo_arg_offset]
+                arch = args[1 + repo_arg_offset]
 
         if opts.multibuild_package:
             package = package + ":" + opts.multibuild_package
@@ -6437,7 +6464,39 @@ Please submit there instead, or use --nodevelproject to force direct submission.
         elif opts.offset:
             offset = int(opts.offset)
         strip_time = opts.strip_time or conf.config['buildlog_strip_time']
-        print_buildlog(apiurl, project, package, repository, arch, offset, strip_time, opts.last, opts.lastsucceeded)
+
+        if opts.all_packages:
+            self.print_buildl_prj_pkgs(apiurl, project,
+                                 repository, arch, offset,
+                                 strip_time, opts.last, opts.lastsucceeded, opts.status)
+        else:
+            print_buildlog(apiurl, project, package, repository, arch, offset, strip_time, opts.last, opts.lastsucceeded)
+
+    def print_buildl_prj_pkgs(self,
+            apiurl: str,
+            prj: str,
+            repository: str,
+            arch: str,
+            offset=0,
+            strip_time=False,
+            last=False,
+            lastsucceeded=False,
+            status='succeeded'
+    ):
+        r = []
+        pkgs = []
+        for results in get_package_results(apiurl, prj,
+                                           None,
+                                           repository,
+                                           arch):
+            for res, is_multi in result_xml_to_dicts(results):
+                if res['code'] == status:
+                    pkgs.append(res['package'])
+        for pkg in pkgs:
+            with open(f'{prj}:{pkg}.log', 'w+b') as pkg_log_file:
+                print_buildlog(apiurl, prj, pkg,
+                               repository, arch,
+                               offset, strip_time, None, None, pkg_log_file)
 
     def print_repos(self, repos_only=False, exc_class=oscerr.WrongArgs, exc_msg='Missing arguments', project=None):
         wd = Path.cwd()