Repository navigation
Expand file tree
/
Copy pathload_source_data.pl
More file actions
executable file
·86 lines (77 loc) · 2.98 KB
/
Copy pathload_source_data.pl
File metadata and controls
executable file
·86 lines (77 loc) · 2.98 KB
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
#!/usr/bin/env perl
use strict;
use warnings;
use Babel::lib::Babel;
use Data::Dumper;
use Getopt::Long;
my $usage = "load_source_data.pl [--verbose] [--dbname NAME] [--dbuser USER] [--dbhost HOST] --download DOWNLOAD_FILE --source SOURCE_FILE\n";
my $dfile = '';
my $sfile = '';
my $verb = '';
my $dbname = $Conf::babel_db;
my $dbuser = $Conf::babel_dbuser;
my $dbhost = $Conf::babel_dbhost;
if ( (@ARGV > 0) && ($ARGV[0] =~ /-h/) ) { print STDERR $usage; exit; }
if ( ! GetOptions('dbname:s' => \$dbname,
'dbuser:s' => \$dbuser,
'dbhost:s' => \$dbhost,
"download=s" => \$dfile,
"source=s" => \$sfile,
"verbose!" => \$verb
) ) {
print STDERR $usage; exit;
}
unless ($sfile && (-s $sfile) && $dfile && (-s $dfile)) {
print STDERR $usage; exit;
}
print "Initializing Babel DB\n" if ($verb);
my ($dbh, $babel);
if ($dbname && $dbuser && $dbhost) {
$dbh = DBI->connect("DBI:Pg:dbname=$dbname;host=$dbhost", $dbuser, '');
$babel = Babel::lib::Babel->new($dbh);
}
else {
$babel = new Babel::lib::Babel;
$dbh = $babel->dbh();
}
my $data = $babel->source_info_from_file($sfile);
my $down = $babel->download_info_from_file($dfile);
my $srcs = $babel->sources();
my $repos = {};
foreach my $name ( keys %$srcs ) {
if (exists $data->{$name}) {
my $src = exists($data->{$name}{source}) ? $data->{$name}{source} : '';
my $vers = exists($data->{$name}{version}) ? $data->{$name}{version} : '';
my $desc = exists($data->{$name}{description}) ? $data->{$name}{description} : '';
my $titl = exists($data->{$name}{title}) ? $data->{$name}{title} : '';
my $url = exists($data->{$name}{url}) ? $data->{$name}{url} : '';
my $type = exists($data->{$name}{type}) ? $data->{$name}{type} : '';
my $link = exists($data->{$name}{link}) ? $data->{$name}{link} : '';
my $sql = qq(UPDATE sources SET source='$src', version='$vers', description='$desc', url='$url', type='$type', title='$titl', link='$link' WHERE name='$name');
if ($src && $url && $type) {
$repos->{$src} = 1;
if ($verb) { print "$sql\n"; }
my $res = $dbh->do($sql);
if (! $res) { print STDERR "Error updating sources: " . $dbh->error . "\n"; }
}
}
else {
print "ERROR: $name\n";
}
}
foreach my $name ( keys %$repos ) {
if (exists($down->{$name}) && (scalar(@{$down->{$name}}) > 0)) {
my (@paths, @files);
my $date = $down->{$name}[0]{download_date};
foreach my $d ( @{$down->{$name}} ) {
push @paths, $d->{download_path};
push @files, $d->{download_file};
}
my $path = "{" . join(",", map {qq("$_")} @paths) . "}";
my $file = "{" . join(",", map {qq("$_")} @files) . "}";
my $sql = qq(UPDATE sources SET download_path='$path', download_file='$file', download_date='$date' WHERE source='$name');
if ($verb) { print "$sql\n"; }
my $res = $dbh->do($sql);
if (! $res) { print STDERR "Error updating sources: " . $dbh->error . "\n"; }
}
}