10
10
from landscape.lib.sequenceranges import sequence_to_ranges
11
11
from landscape.lib.twisted_util import gather_results
12
12
from landscape.lib.fetch import fetch_async
13
from landscape.lib.fs import touch_file
14
15
from landscape.package.taskhandler import (
15
16
PackageTaskHandlerConfiguration, PackageTaskHandler, run_task_handler)
200
200
self.smart_update_filename, code, err))
201
201
logging.debug("'%s' exited with status %d (out='%s', err='%s'" % (
202
202
self.smart_update_filename, code, out, err))
203
touch_file(self._config.smart_update_stamp_filename)
203
204
return (out, err, code)
205
206
result.addCallback(callback)
385
386
return result.addCallbacks(set_message_id, send_message_failed)
387
388
def detect_changes(self):
389
"""Detect all changes concerning packages.
391
If some changes were detected with respect to our last run, then an
392
event of type 'package-data-changed' will be fired in the broker
396
def changes_detected(results):
397
# Release all smart locks, in case the changer runs after us.
398
self._facade.deinit()
400
# Something has changed, notify the broker.
401
return self._broker.fire_event("package-data-changed")
403
result = gather_results([self.detect_packages_changes(),
404
self.detect_package_locks_changes()])
405
return result.addCallback(changes_detected)
407
def detect_packages_changes(self):
388
408
"""Detect changes in the universe of known packages.
390
410
This method will verify if there are packages that:
404
424
In all cases, the server is notified of the new situation
405
425
with a "packages" message.
427
@return: A deferred resulting in C{True} if package changes were
428
detected with respect to the previous run, or C{False} otherwise.
407
430
self._facade.ensure_channels_reloaded()
489
512
list(sequence_to_ranges(sorted(not_locked)))
492
result = succeed(None)
494
message["type"] = "packages"
496
result = self._broker.send_message(message, True)
498
logging.info("Queuing message with changes in known packages: "
499
"%d installed, %d available, %d available upgrades, "
500
"%d locked, %d not installed, %d not available, "
501
"%d not available upgrades, %d not locked."
502
% (len(new_installed), len(new_available),
503
len(new_upgrades), len(new_locked),
504
len(not_installed), len(not_available),
505
len(not_upgrades), len(not_locked)))
515
return succeed(False)
517
message["type"] = "packages"
518
result = self._broker.send_message(message, True)
520
logging.info("Queuing message with changes in known packages: "
521
"%d installed, %d available, %d available upgrades, "
522
"%d locked, %d not installed, %d not available, "
523
"%d not available upgrades, %d not locked."
524
% (len(new_installed), len(new_available),
525
len(new_upgrades), len(new_locked),
526
len(not_installed), len(not_available),
527
len(not_upgrades), len(not_locked)))
507
529
def update_currently_known(result):
508
530
if new_installed:
521
543
self._store.remove_available_upgrades(not_upgrades)
523
545
self._store.remove_locked(not_locked)
546
# Something has changed wrt the former run, let's return True
525
549
result.addCallback(update_currently_known)
537
561
In all cases, the server is notified of the new situation
538
562
with a "packages" message.
564
@return: A deferred resulting in C{True} if package lock changes were
565
detected with respect to the previous run, or C{False} otherwise.
540
567
old_package_locks = set(self._store.get_package_locks())
541
568
current_package_locks = set(self._facade.get_package_locks())
550
577
message["deleted"] = sorted(unset_package_locks)
553
result = succeed(None)
555
message["type"] = "package-locks"
557
result = self._broker.send_message(message, True)
559
logging.info("Queuing message with changes in known package locks:"
560
" %d created, %d deleted." %
561
(len(set_package_locks), len(unset_package_locks)))
580
return succeed(False)
582
message["type"] = "package-locks"
583
result = self._broker.send_message(message, True)
585
logging.info("Queuing message with changes in known package locks:"
586
" %d created, %d deleted." %
587
(len(set_package_locks), len(unset_package_locks)))
563
589
def update_currently_known(result):
564
590
if set_package_locks:
565
591
self._store.add_package_locks(set_package_locks)
566
592
if unset_package_locks:
567
593
self._store.remove_package_locks(unset_package_locks)
569
596
result.addCallback(update_currently_known)