~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/poppy/twistedsftp.py

  • Committer: William Grant
  • Date: 2011-05-09 01:57:28 UTC
  • mto: This revision was merged to the branch mainline in revision 13001.
  • Revision ID: william.grant@canonical.com-20110509015728-w5rgutho2yxybs80
Roll back r12987. It leaks LoopingCalls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    'SFTPServer',
10
10
    ]
11
11
 
12
 
import atexit
13
12
import errno
14
13
import logging
15
14
import os
19
18
    ISFTPFile,
20
19
    ISFTPServer,
21
20
    )
22
 
from twisted.internet import task
23
 
from twisted.internet.error import AlreadyCancelled
24
21
from zope.component import (
25
22
    adapter,
26
 
    getUtility,
27
23
    provideHandler,
28
24
    )
29
 
from zope.component.interfaces import ComponentLookupError
30
25
from zope.interface import implements
31
26
 
32
 
from canonical.launchpad.interfaces.gpghandler import IGPGHandler
33
27
from lp.poppy.filesystem import UploadFileSystem
34
28
from lp.poppy.hooks import Hooks
35
29
from lp.services.sshserver.events import SFTPClosed
55
49
        self.hook.new_client_hook(self._current_upload, 0, 0)
56
50
        self.hook.auth_verify_hook(self._current_upload, None, None)
57
51
 
58
 
        self._gpghandler_job = None
59
 
        # stop the GPGHandler job on normal termination.
60
 
        atexit.register(self._stopGPGHandlerJob)
61
 
        # start the GPGHandler job
62
 
        self._scheduleGPGHandlerJob()
63
 
 
64
 
    def _scheduleGPGHandlerJob(self, touch_interval=12 * 3600):
65
 
        # Create a job to touch the GPGHandler home directory every so often
66
 
        # so that it does not get cleaned up by any reaper scripts which look
67
 
        # at time last modified..
68
 
 
69
 
        self._stopGPGHandlerJob()
70
 
        try:
71
 
            self._gpghandler_job = task.LoopingCall(
72
 
                getUtility(IGPGHandler).touchConfigurationDirectory)
73
 
            return self._gpghandler_job.start(touch_interval)
74
 
        except ComponentLookupError:
75
 
            # No GPGHandler so no need to start the job.
76
 
            pass
77
 
 
78
 
    def _stopGPGHandlerJob(self):
79
 
        try:
80
 
            if self._gpghandler_job and self._gpghandler_job.running:
81
 
                self._gpghandler_job.stop()
82
 
        except AlreadyCancelled:
83
 
            # So we're already cancelled, meh.
84
 
            pass
85
 
 
86
52
    def gotVersion(self, other_version, ext_data):
87
53
        return {}
88
54