pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Return whether and operation changed

Open tino opened this issue 1 year ago • 1 comments

I'd like to be able to do this:

changed = files.put("files/postgres/compose.yml", "postgres/compose.yml")
if changed:
    server.shell("cd postgres && docker compose up -d")

So I can run steps conditionally on whether something changed. Or is there a better way to do this?

PS. Sorry I post this here, I went for the Questions button, ended up on an unused Discord that linked me to Matrix, which I don't have but told me I could use Thunderbird (which I do have) but that didn't work ¯_(ツ)_/¯.

tino avatar Feb 08 '24 21:02 tino

This is already implemented, have a look at https://docs.pyinfra.com/en/2.x/using-operations.html#operation-changes-output

vojta001 avatar Feb 12 '24 17:02 vojta001

Nvm, I found out that this is already possible!

compose = files.put("files/postgres/compose.yml", "postgres/compose.yml")
if compose.changed:
    server.shell("cd postgres && docker compose up -d")

tino avatar Feb 24 '24 13:02 tino