Skip to content

Commit 276cd1c

Browse files
committed
- (reverted from commit dd8f677) (reverted from commit c608bf4)
1 parent c608bf4 commit 276cd1c

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

source_py3/python_toolbox/temp_file_tools.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616

1717
@context_management.ContextManagerType
18-
def create_temp_folder(*, prefix=tempfile.template, suffix='', dir=None):
18+
def create_temp_folder(*, prefix=tempfile.template, suffix='',
19+
parent_folder=None, chmod=None):
1920
'''
2021
Context manager that creates a temporary folder and deletes it after usage.
2122
@@ -37,10 +38,18 @@ def create_temp_folder(*, prefix=tempfile.template, suffix='', dir=None):
3738
3839
Use the `prefix` and `suffix` string arguments to dictate a prefix and/or a
3940
suffix to the temporary folder's name in the filesystem.
41+
42+
If you'd like to set the permissions of the temporary folder, pass them to
43+
the optional `chmod` argument, like this:
44+
45+
create_temp_folder(chmod=0o550)
46+
4047
'''
4148
temp_folder = pathlib.Path(tempfile.mkdtemp(prefix=prefix, suffix=suffix,
42-
dir=dir))
49+
dir=parent_folder))
4350
try:
51+
if chmod is not None:
52+
temp_folder.chmod(chmod)
4453
yield temp_folder
4554
finally:
4655
shutil.rmtree(str(temp_folder))

source_py3/test_python_toolbox/test_temp_file_tools/test_create_temp_folder.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,17 @@ def test_prefix_suffix():
9090
assert tf1.name.startswith('hocus')
9191
assert tf1.name.endswith('pocus')
9292

93-
def test_dir():
93+
def test_parent_folder():
9494
with create_temp_folder() as tf1:
95-
with create_temp_folder(dir=str(tf1)) as tf2:
95+
with create_temp_folder(parent_folder=str(tf1)) as tf2:
9696
assert isinstance(tf2, pathlib.Path)
9797
assert str(tf2).startswith(str(tf1))
98+
99+
def test_chmod():
100+
with create_temp_folder(chomd=0o777) as liberal_temp_folder, \
101+
create_temp_folder(chomd=0o000) as conservative_temp_folder:
102+
liberal_temp_folder.stat().st_mode & 0o777
103+
1 / 0 # blocktodo write this test
104+
105+
98106

0 commit comments

Comments
 (0)