source: server/trunk/web/lib/Sophie/Scan.pm @ 415

Last change on this file since 415 was 415, checked in by nanardon, 13 years ago
  • use numeric needupdate flag, then detect if another has been request
File size: 2.0 KB
Line 
1package Sophie::Scan;
2
3use strict;
4use warnings;
5use Sophie::Base;
6
7sub new {
8    my ($class) = @_;
9
10    my $base = Sophie::Base->connect or return;
11
12    bless({ _base => $base }, $class);
13}
14
15sub base { $_[0]->{_base} }
16
17sub commit {
18    my ($self) = @_;
19    #$self->base->storage->dbh->commit;
20    1;
21}
22
23sub 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
37sub 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
45sub 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
54sub 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
73sub 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
80sub 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
911;
Note: See TracBrowser for help on using the repository browser.