pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Add `TEMPDIR` fact and use in place of default `config.TEMP_DIR`

Open Fizzadar opened this issue 2 years ago • 0 comments

Inspired by: https://github.com/Fizzadar/pyinfra/issues/880.

Currently temporary files (used for uploads/templates before moving to final location) use the config.TEMP_FILE parameter, which defaults to /tmp:

https://github.com/Fizzadar/pyinfra/blob/0e4fe02824b262f81e44d397827203d2172d73d8/pyinfra/api/config.py#L15-L16

While this works in many systems, it would be nicer if this was based on any TEMPDIR environment variable (unless the user explicitly sets config.TEMP_DIR). So the temp directory should be per-host and selected from (in order of preference):

  • An explicit config.TEMP_DIR (default changes to None)
  • The value of TEMPDIR environment variable on the target host
  • The builtin pyinfra default /tmp matching the current code, thus should be backwards compatible

TODO:

  • Move the State.get_temp_filename function to Host.get_temp_filename
  • Create new server.TempDir fact to get the correct location
  • make Host.get_temp_filename use the config or fact as above

Fizzadar avatar Nov 03 '22 15:11 Fizzadar