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
|
#!/usr/bin/python
#
# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
import sys
import transaction
from optparse import OptionParser
from twisted.internet import reactor
from storm.django.stores import configure_stores
from zope.component import (
getUtility,
queryAdapter,
)
from lpresults import hardware
from lpresults.scripts.application import Application
from lpresults.scripts.interfaces.activity import IActivitySet
from lpresults.scripts.mixins.activity import ActivityMixin
from lpresults.scripts.mixins.config import ConfigMixin
from lpresults.scripts.mixins.lock import LockMixin
from lpresults.repository.prober import ProberManager
from lpresults.repository.zope.interfaces import (
IResult,
IZRepository,
)
from lpresults.tracker import settings
class HardwareProber(ActivityMixin, ConfigMixin, LockMixin, Application):
# Config defaults
default_zcml_package = hardware.__name__
def addOptions(self, parser):
"""See Application."""
super(HardwareProber, self).addOptions(parser)
parser.add_option("-f", "--force",
action="store_true",
help="Force probing regardless of date modified.")
def parseOptions(self, options, args):
"""See Application."""
super(HardwareProber, self).parseOptions(options, args)
self.date_modified = None
if not options.force:
activity = getUtility(IActivitySet).getLastActivity(self.name)
if activity:
# Be conservative and use date_started
# instead of date_completed
self.date_modified = activity.date_started
def process(self):
"""See Application."""
manager = ProberManager()
zrepository = getUtility(IZRepository)
for name in zrepository.getDefaultURLs().iterkeys():
source = zrepository.get(name)
result = queryAdapter(source, IResult, name=name)
if result:
context = source.getContext(result)
deferred = manager.run(
source.url, date_modified=self.date_modified)
deferred.addCallback(context.parseData)
reactor.run()
transaction.commit()
if __name__ == "__main__":
application = HardwareProber()
application.run()
|