charms.reactive.helpers

Summary

any_file_changed Check if any of the given files have changed since the last time this was called.
any_hook Assert that the currently executing hook matches one of the given patterns.
data_changed Check if the given set of data has changed since the previous call.
is_data_changed Check if the given set of data has changed since the last time data_changed was called.
mark_invoked Mark the given ID as having been invoked, for use with was_invoked().
was_invoked Returns whether the given ID has been invoked before, as per mark_invoked().

Reference

charms.reactive.helpers.data_changed(data_id, data, hash_type='md5')

Check if the given set of data has changed since the previous call.

This works by hashing the JSON-serialization of the data. Note that, while the data will be serialized using sort_keys=True, some types of data structures, such as sets, may lead to false positivies.

Parameters:
  • data_id (str) – Unique identifier for this set of data.
  • data – JSON-serializable data.
  • hash_type (str) – Any hash algorithm supported by hashlib.
charms.reactive.helpers.is_data_changed(data_id, data, hash_type='md5')

Check if the given set of data has changed since the last time data_changed was called.

That is, this is a non-destructive way to check if the data has changed.

Parameters:
  • data_id (str) – Unique identifier for this set of data.
  • data – JSON-serializable data.
  • hash_type (str) – Any hash algorithm supported by hashlib.
charms.reactive.helpers.any_file_changed(filenames, hash_type='md5')

Check if any of the given files have changed since the last time this was called.

Parameters:
  • filenames (list) – Names of files to check. Accepts callables returning the filename.
  • hash_type (str) – Algorithm to use to check the files.