1 | package Sophie::Scan; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use Sophie::Base; |
---|
6 | |
---|
7 | sub new { |
---|
8 | my ($class) = @_; |
---|
9 | |
---|
10 | my $base = Sophie::Base->connect or return; |
---|
11 | |
---|
12 | bless({ _base => $base }, $class); |
---|
13 | } |
---|
14 | |
---|
15 | sub base { $_[0]->{_base} } |
---|
16 | |
---|
17 | sub commit { |
---|
18 | my ($self) = @_; |
---|
19 | #$self->base->storage->dbh->commit; |
---|
20 | 1; |
---|
21 | } |
---|
22 | |
---|
23 | sub list_unscanned_paths { |
---|
24 | my ($self) = @_; |
---|
25 | |
---|
26 | return $self->base->resultset('Paths')->search({ |
---|
27 | updated => [ undef, |
---|
28 | \[ " < now() - '24 hours'::interval"], |
---|
29 | ], |
---|
30 | })->get_column('d_path_key')->all |
---|
31 | } |
---|
32 | |
---|
33 | sub paths_to_keys { |
---|
34 | my ($self, @paths) = @_; |
---|
35 | |
---|
36 | return $self->base->resultset('Paths')->search({ |
---|
37 | path => [ @paths ], |
---|
38 | })->get_column('d_path_key')->all |
---|
39 | } |
---|
40 | |
---|
41 | sub list_paths { |
---|
42 | my ($self, $host) = @_; |
---|
43 | return $self->base->resultset('Paths')->search( |
---|
44 | { |
---|
45 | $host ? (host => $host) : (), |
---|
46 | } |
---|
47 | )->get_column('path')->all |
---|
48 | } |
---|
49 | |
---|
50 | sub update_meta_paths { |
---|
51 | my ($self) = @_; |
---|
52 | |
---|
53 | foreach ($self->base->resultset('MetaPaths')->search({ |
---|
54 | updated => [ undef, |
---|
55 | \[ " < now() - '24 hours'::interval"], |
---|
56 | ], |
---|
57 | })->all) { |
---|
58 | my $type = ucfirst(lc($_->type)); |
---|
59 | eval "require Sophie::Scan::MetaPath::$type"; |
---|
60 | if ($@) { |
---|
61 | warn "Cannot load MetaPath $type: $@"; |
---|
62 | next; |
---|
63 | } |
---|
64 | warn "$$ Updating Meta $_"; |
---|
65 | my $meta = "Sophie::Scan::MetaPath::$type"->new($self, $_); |
---|
66 | $meta->run(); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | sub call_plugins_parser { |
---|
71 | my ($self, $rpm, $pkgid, $new) = @_; |
---|
72 | foreach my $plugins (qw'sources') { |
---|
73 | $self->call_plugin_parser($plugins, $rpm, $pkgid, $new); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | sub call_plugin_parser { |
---|
78 | my ($self, $plugins, $rpm, $pkgid, $new) = @_; |
---|
79 | my $mod = ucfirst(lc($plugins)); |
---|
80 | eval "require Sophie::Scan::RpmParser::$mod;"; |
---|
81 | warn $@ if($@); |
---|
82 | eval { |
---|
83 | my $parser = "Sophie::Scan::RpmParser::$mod"->new($self); |
---|
84 | $parser->run($rpm, $pkgid, $new); |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | 1; |
---|