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>.
11 use Getopt::Long qw(:config no_ignore_case);
16 debbugs-loadsql-debinfo -- load debbugs sql versions database
20 debbugs-loadsql-debinfo [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
35 Only load changed bugs
39 Postgreql service to use; defaults to debbugs
41 =item B<--sysconfdir,-c>
43 System configuration directory to use; if not set, defaults to the
44 postgresql default. [Operates by setting PGSYSCONFDIR]
52 Display brief useage information.
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);
75 my %options = (debug => 0,
89 'debug|d+','help|h|?','man|m');
91 pod2usage() if $options{help};
92 pod2usage({verbose=>2}) if $options{man};
94 $DEBUG = $options{debug};
97 $options{verbose} = $options{verbose} - $options{quiet};
99 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
101 if (exists $options{sysconfdir}) {
102 if (not defined $options{sysconfdir} or not length $options{sysconfdir}) {
103 delete $ENV{PGSYSCONFDIR};
105 $ENV{PGSYSCONFDIR} = $options{sysconfdir};
109 my $verbose = $options{debug};
111 my $initialdir = "db-h";
113 # connect to the database; figure out how to handle errors properly
115 my $s = Debbugs::DB->connect('dbi:Pg:service='.$options{service}) or
116 die "Unable to connect to database: ";
121 for my $file (@files) {
122 my $fh = IO::File->new($file,'r') or
123 die "Unable to open $file for reading: $!";
126 next unless length $_;
127 my ($binname, $binver, $binarch, $srcname, $srcver) = split;
128 # if $srcver is not defined, this is probably a broken
129 # .debinfo file [they were causing #686106, see commit
130 # 49c85ab8 in dak.] Basically, $binarch didn't get put into
131 # the file, so we'll fudge it from the filename.
132 if (not defined $srcver) {
133 ($srcname,$srcver) = ($binarch,$srcname);
134 ($binarch) = $file =~ /_([^\.]+)\.debinfo/;
136 my $sp = $s->resultset('SrcPkg')->find_or_create({pkg => $srcname});
137 my $sv = $s->resultset('SrcVer')->find_or_create({src_pkg_id=>$sp->id(),
140 if (defined $arch{$binarch}) {
141 $arch = $arch{$binarch};
143 $arch = $s->resultset('Arch')->find_or_create({arch => $binarch});
144 $arch{$binarch} = $arch;
146 my $bp = $s->resultset('BinPkg')->find_or_create({pkg => $binname});
147 $s->resultset('BinVer')->find_or_create({bin_pkg_id => $bp->id(),
148 src_ver_id => $sv->id(),
149 arch_id => $arch->id(),