提交 e9a30042 authored 作者: Frederic's avatar Frederic

better error message.

上级 bb58f1a6
...@@ -39,27 +39,32 @@ def filter_compiledir(path): ...@@ -39,27 +39,32 @@ def filter_compiledir(path):
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier # 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules). # to re-use compiled modules).
path = os.path.realpath(path) path = os.path.realpath(path)
valid = True if os.access(path, os.F_OK): # Do it exist?
if not os.access(path, os.R_OK | os.W_OK): if not os.access(path, os.R_OK | os.W_OK | os.X_OK):
# If it exist we need read, write and listing access
raise ValueError(
"compiledir '%s' exist but you don't have read, write or"
" listing permissions." % path)
else:
try: try:
os.makedirs(path, 0770) # read-write-execute for user and group os.makedirs(path, 0770) # read-write-execute for user and group
except OSError, e: except OSError, e:
# Maybe another parallel execution of theano was trying to create # Maybe another parallel execution of theano was trying to create
# the same directory at the same time. # the same directory at the same time.
if e.errno != errno.EEXIST: if e.errno != errno.EEXIST:
valid = False raise ValueError(
"We where not able to create the compiledir directory"
if valid: " '%s'. Check the permissions." % path)
try:
# PROBLEM: sometimes the initial approach based on try:
# os.system('touch') returned -1 for an unknown reason; the # PROBLEM: sometimes the initial approach based on
# alternate approach here worked in all cases... it was weird. # os.system('touch') returned -1 for an unknown reason; the
open(os.path.join(path, '__init__.py'), 'w').close() # alternate approach here worked in all cases... it was weird.
except: open(os.path.join(path, '__init__.py'), 'w').close()
valid = False except Exception:
# This should not happen as we checked that we have the permissions.
if not valid: raise ValueError('Failed to create the __init__.py file in the '
raise ValueError('Invalid value for compiledir: %s' % path) 'compiledir: "%s". Check the permissions.' % path)
return path return path
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论