change the date
[tools/build.git] / listinstalled
1 #!/usr/bin/perl -w
2
3 ################################################################
4 #
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #
21 ################################################################
22
23 BEGIN {
24   unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
25 }
26
27 use Getopt::Long;
28 use Build;
29
30 use strict;
31
32 Getopt::Long::Configure("no_ignore_case");
33
34 my $opt_root;
35 my $opt_type;
36 my $opt_extraname;
37
38 GetOptions ("root=s" => \$opt_root, "type=s" => \$opt_type, "extraname" => \$opt_extraname) or exit(1);
39
40 $opt_type ||= 'rpm';
41
42 my $ql = Build::queryinstalled($opt_type, $opt_root);
43 die("cannot get list of installed packages for type $opt_type\n") unless $ql;
44
45 for my $q (@$ql) {
46   next unless defined($q->{'name'}) && defined($q->{'arch'});
47   next if $q->{'arch'} eq 'src' || $q->{'arch'} eq 'nosrc';
48   my $id = "$q->{'name'}.$q->{'arch'}-0/0/0: ";
49   my $evr = $q->{'version'};
50   $evr = "$q->{'epoch'}:$evr" if $q->{'epoch'};
51   $evr .= "-$q->{'release'}" if defined $q->{'release'};
52   my $buildtime = $q->{'buildtime'} || 0;
53   if ($opt_extraname) {
54     print "I:$id$q->{'name'} $q->{'name'}-$evr $buildtime-$q->{'arch'}\n";
55   } else {
56     print "I:$id$q->{'name'}-$evr $buildtime-$q->{'arch'}\n";
57   }
58 }
59