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

Last change on this file since 344 was 344, checked in by nanardon, 13 years ago
  • add tools to rescan rpm
  • index desktop files (only if in /usr/share/applications)
File size: 1.9 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            updated => [ undef,
28            \[ " < now() - '24 hours'::interval"],
29            ],
30    })->get_column('d_path_key')->all
31}
32
33sub 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
41sub 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
50sub 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
70sub 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
77sub 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
881;
Note: See TracBrowser for help on using the repository browser.