Skip to content

Commit 6803928

Browse files
Tim WeberFizzadar
Tim Weber
authored andcommitted
Allow specifying custom tempdir for files.download
1 parent 87ac4cf commit 6803928

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pyinfra/api/host.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,18 @@ def _get_temp_directory(self):
328328

329329
return temp_directory
330330

331-
def get_temp_filename(self, hash_key: Optional[str] = None, hash_filename: bool = True):
331+
def get_temp_filename(
332+
self,
333+
hash_key: Optional[str] = None,
334+
hash_filename: bool = True,
335+
*,
336+
temp_directory: Optional[str] = None,
337+
):
332338
"""
333339
Generate a temporary filename for this deploy.
334340
"""
335341

336-
temp_directory = self._get_temp_directory()
342+
temp_directory = temp_directory or self._get_temp_directory()
337343

338344
if not hash_key:
339345
hash_key = str(uuid4())

pyinfra/operations/files.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def download(
7575
headers: dict[str, str] | None = None,
7676
insecure=False,
7777
proxy: str | None = None,
78+
temp_dir: str | Path | None = None,
7879
):
7980
"""
8081
Download files from remote locations using ``curl`` or ``wget``.
@@ -93,6 +94,7 @@ def download(
9394
+ headers: optional dictionary of headers to set for the HTTP request
9495
+ insecure: disable SSL verification for the HTTP request
9596
+ proxy: simple HTTP proxy through which we can download files, form `http://<yourproxy>:<port>`
97+
+ temp_dir: use this custom temporary directory during the download
9698
9799
**Example:**
98100
@@ -148,7 +150,9 @@ def download(
148150

149151
# If we download, always do user/group/mode as SSH user may be different
150152
if download:
151-
temp_file = host.get_temp_filename(dest)
153+
temp_file = host.get_temp_filename(
154+
dest, temp_directory=str(temp_dir) if temp_dir is not None else None
155+
)
152156

153157
curl_args: list[Union[str, StringCommand]] = ["-sSLf"]
154158
wget_args: list[Union[str, StringCommand]] = ["-q"]

0 commit comments

Comments
 (0)