1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""A Twisted job to touch the GPGHandler config files."""
8
'GPGHandlerConfigResetJob',
11
from twisted.application.service import Service
12
from twisted.internet import task
13
from twisted.internet.error import AlreadyCancelled
15
from zope.component import getUtility
16
from zope.component.interfaces import ComponentLookupError
18
from canonical.launchpad.interfaces.gpghandler import IGPGHandler
21
class GPGHandlerConfigResetJob(Service):
22
"""Manages twisted job to touch the files in the gpgconfig directory."""
24
def startService(self):
25
self._gpghandler_job = None
26
# start the GPGHandler job
27
self._scheduleGPGHandlerJob()
28
Service.startService(self)
30
def stopService(self):
31
self._stopGPGHandlerJob()
32
Service.stopService(self)
34
def _scheduleGPGHandlerJob(self, touch_interval=12 * 3600):
35
# Create a job to touch the GPGHandler home directory every so often
36
# so that it does not get cleaned up by any reaper scripts which look
37
# at time last modified.
39
self._stopGPGHandlerJob()
40
self._gpghandler_job = task.LoopingCall(
41
getUtility(IGPGHandler).touchConfigurationDirectory)
42
return self._gpghandler_job.start(touch_interval)
44
def _stopGPGHandlerJob(self):
46
if self._gpghandler_job and self._gpghandler_job.running:
47
self._gpghandler_job.stop()
48
except AlreadyCancelled:
49
# So we're already cancelled, meh.