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: ";
120 for my $file (@files) {
121 my $fh = IO::File->new($file,'r') or
122 die "Unable to open $file for reading: $!";
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/;
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(),
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(),