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 | -or => [ |
---|
28 | updated => [ |
---|
29 | undef, |
---|
30 | \[ " < now() - '24 hours'::interval"], |
---|
31 | ], |
---|
32 | { needupdate => { '>' => 0 }, }, |
---|
33 | ], |
---|
34 | })->get_column('d_path_key')->all |
---|
35 | } |
---|
36 | |
---|
37 | sub paths_to_keys { |
---|
38 | my ($self, @paths) = @_; |
---|
39 | |
---|
40 | return $self->base->resultset('Paths')->search({ |
---|
41 | path => [ @paths ], |
---|
42 | })->get_column('d_path_key')->all |
---|
43 | } |
---|
44 | |
---|
45 | sub list_paths { |
---|
46 | my ($self, $host) = @_; |
---|
47 | return $self->base->resultset('Paths')->search( |
---|
48 | { |
---|
49 | $host ? (host => $host) : (), |
---|
50 | } |
---|
51 | )->get_column('path')->all |
---|
52 | } |
---|
53 | |
---|
54 | sub update_meta_paths { |
---|
55 | my ($self) = @_; |
---|
56 | |
---|
57 | foreach ($self->base->resultset('MetaPaths')->search({ |
---|
58 | updated => [ undef, |
---|
59 | \[ " < now() - '24 hours'::interval"], |
---|
60 | ], |
---|
61 | })->all) { |
---|
62 | my $type = ucfirst(lc($_->type)); |
---|
63 | eval "require Sophie::Scan::MetaPath::$type"; |
---|
64 | if ($@) { |
---|
65 | warn "Cannot load MetaPath $type: $@"; |
---|
66 | next; |
---|
67 | } |
---|
68 | my $meta = "Sophie::Scan::MetaPath::$type"->new($self, $_); |
---|
69 | $meta->run(); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | sub call_plugins_parser { |
---|
74 | my ($self, $rpm, $pkgid, $new) = @_; |
---|
75 | foreach my $plugins (qw'sources desktopfile config docs') { |
---|
76 | $self->call_plugin_parser($plugins, $rpm, $pkgid, $new); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | sub call_plugin_parser { |
---|
81 | my ($self, $plugins, $rpm, $pkgid, $new) = @_; |
---|
82 | my $mod = ucfirst(lc($plugins)); |
---|
83 | eval "require Sophie::Scan::RpmParser::$mod;"; |
---|
84 | warn $@ if($@); |
---|
85 | eval { |
---|
86 | my $parser = "Sophie::Scan::RpmParser::$mod"->new($self); |
---|
87 | $parser->run($rpm, $pkgid, $new); |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | 1; |
---|