-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathqueryobs
executable file
·123 lines (107 loc) · 3.66 KB
/
queryobs
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
#!/usr/bin/perl -w
################################################################
#
# Copyright (c) 2021 SUSE Linux GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
# obs: repo support
BEGIN {
unshift @INC, ($::ENV{"BUILD_DIR"} || "/usr/lib/build");
}
use strict;
use Digest::MD5 ();
use File::Path ();
use Build ':rpm';
use Build::Options;
use PBuild::OBS;
my $cachedir = "/var/cache/build";
my $cmd = shift @ARGV;
die("please specify a query command\n") unless defined $cmd;
if ($cmd eq 'expandpath') {
my $options = {
'obs' => ':',
'reverse' => '',
};
my ($opts, @args) = Build::Options::parse_options($options, @ARGV);
my $obsurl = $opts->{'obs'};
die("please specify a obs url with the --obs option\n") unless $obsurl;
$obsurl =~ s/\/$//;
for my $url (@args) {
die("$url: not a valid obs: repo") unless $url =~ /^obs:\/{1,3}([^\/]+\/[^\/]+)\/?$/;
my $prp = $1;
$prp =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/sge;
my @prps = PBuild::OBS::expand_path($prp, "$obsurl/");
@prps = reverse(@prps) if $opts->{'reverse'};
for (@prps) {
s/([\000-\040<>;\"#\?&\+=%[\177-\377])/sprintf("%%%02X",ord($1))/sge;
print "obs:/$_\n";
}
}
exit;
}
if ($cmd eq 'config') {
my $options = {
'obs' => ':',
'reverse' => '',
'noexpand' => '',
};
my ($opts, @args) = Build::Options::parse_options($options, @ARGV);
my $obsurl = $opts->{'obs'};
die("please specify a obs url with the --obs option\n") unless $obsurl;
$obsurl =~ s/\/$//;
my @configs;
my $distcnt = 0;
for my $url (@args) {
$distcnt++;
my $doexpand = $distcnt == @args && !$opts->{'noexpand'} ? 1 : 0;
my ($obsconfigs) = PBuild::OBS::fetch_all_configs($url, { 'obs' => $obsurl }, $doexpand);
@$obsconfigs = reverse @$obsconfigs unless $opts->{'reverse'};
push @configs, @$obsconfigs;
}
my $config = Build::combine_configs(@configs);
$config =~ s/\n?$/\n/s if $config ne '';
print $config;
exit;
}
die("unknown query command '$cmd'\n") unless $cmd eq 'repo';
my $options = {
'obs' => ':',
'arch' => ':',
'cachedir' => ':',
};
my ($opts, @args) = Build::Options::parse_options($options, @ARGV);
my $obsurl = $opts->{'obs'};
die("please specify a obs url with the --obs option\n") unless $obsurl;
$obsurl =~ s/\/$//;
my $arch = $opts->{'arch'};
die("please specify a scheduler architecture with the --arch option\n") unless $arch;
$arch =~ s/:.*//;
$cachedir = $opts->{'cachedir'} if $opts->{'cachedir'};
for my $url (@args) {
die("$url: not a valid obs: repo") unless $url =~ /^obs:\/{1,3}([^\/]+\/[^\/]+)\/?$/;
my $prp = $1;
my $repoid = Digest::MD5::md5_hex("$obsurl/build/$prp/$arch");
my $dir = "$cachedir/$repoid";
File::Path::mkpath($dir);
my $bins = PBuild::OBS::fetch_repodata($url, $dir, $arch, { 'obs' => $opts->{'obs'} });
@$bins = sort {$a->{'name'} cmp $b->{'name'}} @$bins;
for (@$bins) {
delete $_->{'filename'}; # just in case
delete $_->{'packid'}; # just in case
Build::writedeps(\*STDOUT, $_);
}
}