Skip to content

Commit fb3f2ff

Browse files
committed
Adds a sanity check for outdir write permissions. Fixes #73
1 parent baae79f commit fb3f2ff

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

structure_threader/sanity_checks/sanity.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,29 @@ def file_checker(path, msg=None, is_file=True):
185185
:param if_file, True if path is a file, False if a dir
186186
"""
187187
if is_file is False:
188-
if not os.path.exists(path) or not os.path.isdir(path):
189-
try:
188+
try:
189+
if not os.path.exists(path) or not os.path.isdir(path):
190190
os.makedirs(path)
191-
except FileExistsError:
192-
if not msg:
193-
logging.error("'{}' should be the path to a directory, not "
194-
"to a file.'".format(path))
195-
else:
196-
logging.error("{}".format(msg))
197-
raise SystemExit(1)
191+
elif not os.access(path, os.W_OK | os.X_OK):
192+
raise PermissionError
193+
except FileExistsError:
194+
if not msg:
195+
logging.error("'{}' should be the path to a directory, not "
196+
"to a file.'".format(path))
197+
else:
198+
logging.error("{}".format(msg))
199+
raise SystemExit(1)
200+
except PermissionError:
201+
logging.critical("Your user does not have permissions to write "
202+
"to the results directory ({}). Either "
203+
"chanage this path to one to which you have "
204+
"write permissions to, or change the "
205+
"permissions on this directory (if you "
206+
"can).".format(path))
207+
raise SystemExit(1)
208+
209+
210+
198211
else:
199212
if os.path.isdir(path):
200213
if not msg:

0 commit comments

Comments
 (0)