103
103
return result.addErrback(self.unknown_package_data_error, task)
104
104
if message["type"] == "change-package-locks":
105
105
return self.handle_change_package_locks(message)
106
if message["type"] == "change-package-holds":
107
return self.handle_change_package_holds(message)
107
109
def unknown_package_data_error(self, failure, task):
108
110
"""Handle L{UnknownPackageData} data errors.
128
130
raise PackageTaskError()
130
def smart_update_stamp_exists(self):
132
Return a boolean indicating if the smart-update stamp file exists.
134
return os.path.exists(self._config.smart_update_stamp_filename)
132
def update_stamp_exists(self):
134
Return a boolean indicating if the update-stamp stamp file exists.
136
return os.path.exists(self._config.update_stamp_filename)
138
def _clear_binaries(self):
139
"""Remove any binaries and its associated channel."""
140
binaries_path = self._config.binaries_path
142
for existing_deb_path in os.listdir(binaries_path):
143
# Clean up the binaries we wrote in former runs
144
os.remove(os.path.join(binaries_path, existing_deb_path))
145
self._facade.clear_channels()
136
147
def init_channels(self, binaries=()):
137
148
"""Initialize the Smart channels as needed.
169
180
self._facade.reset_marks()
172
for package in self._facade.get_packages():
173
if package.installed:
174
self._facade.mark_upgrade(package)
183
self._facade.mark_global_upgrade()
176
185
for ids, mark_func in [(install, self._facade.mark_install),
177
186
(remove, self._facade.mark_remove)]:
283
292
Create and delete package locks as requested by the given C{message}.
295
if not self._facade.supports_package_locks:
297
"type": "operation-result",
298
"operation-id": message.get("operation-id"),
300
"result-text": "This client doesn't support package locks.",
302
return self._broker.send_message(response, True)
286
304
for lock in message.get("create", ()):
287
305
self._facade.set_package_lock(*lock)
288
306
for lock in message.get("delete", ()):
299
317
"exchange urgently.")
300
318
return self._broker.send_message(response, True)
320
def _send_change_package_holds_response(self, response):
321
"""Log that a package holds result is sent and send the response."""
322
logging.info("Queuing message with change package holds results to "
323
"exchange urgently.")
324
return self._broker.send_message(response, True)
326
def handle_change_package_holds(self, message):
327
"""Handle a C{change-package-holds} message.
329
Create and delete package holds as requested by the given C{message}.
331
if not self._facade.supports_package_holds:
333
"type": "operation-result",
334
"operation-id": message.get("operation-id"),
336
"result-text": "This client doesn't support package holds.",
338
return self._send_change_package_holds_response(response)
340
not_installed = set()
341
holds_to_create = message.get("create", [])
342
versions_to_create = set()
343
for id in holds_to_create:
344
hash = self._store.get_id_hash(id)
345
hold_version = self._facade.get_package_by_hash(hash)
347
and self._facade.is_package_installed(hold_version)):
348
versions_to_create.add((hold_version.package, hold_version))
350
not_installed.add(str(id))
351
holds_to_remove = message.get("delete", [])
352
versions_to_remove = set()
353
for id in holds_to_remove:
354
hash = self._store.get_id_hash(id)
355
hold_version = self._facade.get_package_by_hash(hash)
357
and self._facade.is_package_installed(hold_version)):
358
versions_to_remove.add((hold_version.package, hold_version))
362
"type": "operation-result",
363
"operation-id": message.get("operation-id"),
365
"result-text": "Package holds not changed, since the" +
366
" following packages are not installed: %s" % (
367
", ".join(sorted(not_installed))),
369
return self._send_change_package_holds_response(response)
371
for package, hold_version in versions_to_create:
372
self._facade.set_package_hold(hold_version)
373
for package, hold_version in versions_to_remove:
374
self._facade.remove_package_hold(hold_version)
376
self._facade.reload_channels()
378
response = {"type": "operation-result",
379
"operation-id": message.get("operation-id"),
381
"result-text": "Package holds successfully changed.",
384
return self._send_change_package_holds_response(response)
303
387
def find_command():
304
388
return find_changer_command()