/usr/share/pyshared/landscape/manager/packagemanager.py is in landscape-common 12.04.3-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 81 82 83 84 85 | import logging
import os
from twisted.internet.utils import getProcessOutput
from twisted.internet.defer import succeed
from landscape.package.store import PackageStore
from landscape.package.changer import PackageChanger
from landscape.package.releaseupgrader import ReleaseUpgrader
from landscape.manager.plugin import ManagerPlugin
class PackageManager(ManagerPlugin):
run_interval = 1800
_package_store = None
def register(self, registry):
super(PackageManager, self).register(registry)
self.config = registry.config
if not self._package_store:
filename = os.path.join(registry.config.data_path,
"package/database")
self._package_store = PackageStore(filename)
registry.register_message("change-packages",
self.handle_change_packages)
registry.register_message("change-package-locks",
self.handle_change_package_locks)
registry.register_message("release-upgrade",
self.handle_release_upgrade)
# When the package reporter notifies us that something has changed,
# we want to run again to see if we can now fulfill tasks that were
# skipped before.
registry.reactor.call_on("package-data-changed", self.run)
self.run()
def _handle(self, cls, message):
"""Queue C{message} as a task, and spawn the proper handler."""
self._package_store.add_task(cls.queue_name, message)
self.spawn_handler(cls)
def handle_change_packages(self, message):
return self._handle(PackageChanger, message)
def handle_change_package_locks(self, message):
return self._handle(PackageChanger, message)
def handle_release_upgrade(self, message):
return self._handle(ReleaseUpgrader, message)
def run(self):
result = self.registry.broker.get_accepted_message_types()
result.addCallback(self._got_message_types)
return result
def _got_message_types(self, message_types):
if "change-packages-result" in message_types:
self.spawn_handler(PackageChanger)
if "operation-result" in message_types:
self.spawn_handler(ReleaseUpgrader)
def spawn_handler(self, cls):
args = ["--quiet"]
if self.config.config:
args.extend(["-c", self.config.config])
if self._package_store.get_next_task(cls.queue_name):
# path is set to None so that getProcessOutput does not
# chdir to "." see bug #211373
result = getProcessOutput(cls.find_command(),
args=args, env=os.environ,
errortoo=1,
path=None)
result.addCallback(self._got_output, cls)
else:
result = succeed(None)
return result
def _got_output(self, output, cls):
if output:
logging.warning("Package %s output:\n%s" %
(cls.queue_name, output))
|