Ticket #190: foolscap-190-fix.diff

File foolscap-190-fix.diff, 2.8 KB (added by davidsarah, 12 years ago)

Fix for logging/gatherer.py

Line 
1/usr/lib/pymodules/python2.6/foolscap/logging# diff --context=5 gatherer.py.old gatherer.py
2*** gatherer.py.old     2012-04-27 20:41:07.000000000 -0400
3--- gatherer.py 2012-04-28 19:05:38.000000000 -0400
4***************
5*** 350,375 ****
6              return
7          self.incident_fetch_outstanding = True
8          (name, trigger) = self.incidents_wanted.pop(0)
9          print >>self.stdout, "fetching incident", name
10          d = self.publisher.callRemote("get_incident", name)
11          d.addCallback(self._got_incident, name, trigger)
12          d.addErrback(tw_log.err,
13                       "IncidentObserver.get_incident or _got_incident")
14 
15      def _got_incident(self, incident, name, trigger):
16-         self.incident_fetch_outstanding = False
17          # We always save the incident to a .bz2 file.
18          abs_fn = self.basedir.child(name).path # this prevents evil
19          abs_fn += ".flog.bz2"
20          # we need to record the relative pathname of the savefile, for use by
21          # the classifiers (they write it into their output files)
22          rel_fn = os.path.join("incidents", self.tubid_s, name) + ".flog.bz2"
23          self.save_incident(abs_fn, incident)
24          self.update_latest(name)
25          self.gatherer.new_incident(abs_fn, rel_fn, self.tubid_s, incident)
26-         self.maybe_fetch_incident()
27 
28      def save_incident(self, filename, incident):
29          now = time.time()
30          (header, events) = incident
31          f = bz2.BZ2File(filename, "w")
32--- 350,378 ----
33              return
34          self.incident_fetch_outstanding = True
35          (name, trigger) = self.incidents_wanted.pop(0)
36          print >>self.stdout, "fetching incident", name
37          d = self.publisher.callRemote("get_incident", name)
38+         def _clear_outstanding(res):
39+             self.incident_fetch_outstanding = False
40+             return res
41+         d.addBoth(_clear_outstanding)
42          d.addCallback(self._got_incident, name, trigger)
43          d.addErrback(tw_log.err,
44                       "IncidentObserver.get_incident or _got_incident")
45+         d.addBoth(lambda ign: self.maybe_fetch_incident())
46 
47      def _got_incident(self, incident, name, trigger):
48          # We always save the incident to a .bz2 file.
49          abs_fn = self.basedir.child(name).path # this prevents evil
50          abs_fn += ".flog.bz2"
51          # we need to record the relative pathname of the savefile, for use by
52          # the classifiers (they write it into their output files)
53          rel_fn = os.path.join("incidents", self.tubid_s, name) + ".flog.bz2"
54          self.save_incident(abs_fn, incident)
55          self.update_latest(name)
56          self.gatherer.new_incident(abs_fn, rel_fn, self.tubid_s, incident)
57 
58      def save_incident(self, filename, incident):
59          now = time.time()
60          (header, events) = incident
61          f = bz2.BZ2File(filename, "w")