]> git.donarmstrong.com Git - debbugs.git/blob - bin/debbugs-loadsql-debinfo
add initial version of debbugs-loadsql-debinfo and debbugs-loadsql-versions
[debbugs.git] / bin / debbugs-loadsql-debinfo
1 #! /usr/bin/perl
2 # debbugs-loadsql-debinfo is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2012 by Don Armstrong <don@donarmstrong.com>.
6
7
8 use warnings;
9 use strict;
10
11 use Getopt::Long qw(:config no_ignore_case);
12 use Pod::Usage;
13
14 =head1 NAME
15
16 debbugs-loadsql-debinfo -- load debbugs sql versions database
17
18 =head1 SYNOPSIS
19
20 debbugs-loadsql-debinfo [options]
21
22  Options:
23   --service, -s service name
24   --sysconfdir, -c postgresql service config dir
25   --debug, -d debugging level (Default 0)
26   --help, -h display this help
27   --man, -m display manual
28
29 =head1 OPTIONS
30
31 =over
32
33 =item B<--quick, -q>
34
35 Only load changed bugs
36
37 =item B<--service,-s>
38
39 Postgreql service to use; defaults to debbugs
40
41 =item B<--sysconfdir,-c>
42
43 System configuration directory to use; if not set, defaults to the
44 postgresql default. [Operates by setting PGSYSCONFDIR]
45
46 =item B<--debug, -d
47
48 Debug verbosity.
49
50 =item B<--help, -h>
51
52 Display brief useage information.
53
54 =item B<--man, -m>
55
56 Display this manual.
57
58 =back
59
60
61 =cut
62
63
64 use vars qw($DEBUG);
65
66 use Debbugs::Common qw(checkpid lockpid get_hashname getparsedaddrs getbugcomponent make_list);
67 use Debbugs::Config qw(:config);
68 use Debbugs::Status qw(read_bug split_status_fields);
69 use Debbugs::Log;
70 use Debbugs::DB;
71 use DateTime;
72 use File::stat;
73
74
75 my %options = (debug           => 0,
76                help            => 0,
77                man             => 0,
78                verbose         => 0,
79                quiet           => 0,
80                quick           => 0,
81                service         => 'debbugs',
82               );
83
84
85 GetOptions(\%options,
86            'quick|q',
87            'service|s',
88            'sysconfdir|c',
89            'debug|d+','help|h|?','man|m');
90
91 pod2usage() if $options{help};
92 pod2usage({verbose=>2}) if $options{man};
93
94 $DEBUG = $options{debug};
95
96 my @USAGE_ERRORS;
97 $options{verbose} = $options{verbose} - $options{quiet};
98
99 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
100
101 if (exists $options{sysconfdir}) {
102     if (not defined $options{sysconfdir} or not length $options{sysconfdir}) {
103         delete $ENV{PGSYSCONFDIR};
104     } else {
105         $ENV{PGSYSCONFDIR} = $options{sysconfdir};
106     }
107 }
108
109 my $verbose = $options{debug};
110
111 my $initialdir = "db-h";
112
113 # connect to the database; figure out how to handle errors properly
114 # here.
115 my $s = Debbugs::DB->connect('dbi:Pg:service='.$options{service}) or
116     die "Unable to connect to database: ";
117
118 my @files = @ARGV;
119
120 for my $file (@files) {
121     my $fh = IO::File->new($file,'r') or
122         die "Unable to open $file for reading: $!";
123     while (<$fh>) {
124         chomp;
125         next unless length $_;
126         my ($binname, $binver, $binarch, $srcname, $srcver) = split;
127         # if $srcver is not defined, this is probably a broken
128         # .debinfo file [they were causing #686106, see commit
129         # 49c85ab8 in dak.] Basically, $binarch didn't get put into
130         # the file, so we'll fudge it from the filename.
131         if (not defined $srcver) {
132             ($srcname,$srcver) = ($binarch,$srcname);
133             ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
134         }
135         my $sp = $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
136         my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg_id=>$sp->id(),
137                                                           ver => $srcver});
138         my $arch = $s->resultset('Arch')->find_or_create({arch => $binarch});
139         my $bp = $s->resultset('BinPkg')->find_or_create({pkg => $binname});
140         $s->resultset('BinVer')->find_or_create({bin_pkg_id => $bp->id(),
141                                                  src_ver_id => $sv->id(),
142                                                  arch_id    => $arch->id(),
143                                                  ver        => $binver,
144                                                 });
145     }
146 }
147
148
149 __END__