Unverified 提交 22ee6fb7 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Update `is_writeable()` for 2 methods (#4744)

* Writeable test * Fix * Cleanup
上级 ff352925
...@@ -112,17 +112,19 @@ def user_config_dir(dir='Ultralytics'): ...@@ -112,17 +112,19 @@ def user_config_dir(dir='Ultralytics'):
return path return path
def is_writeable(dir): def is_writeable(dir, test=False):
# Return True if directory has write permissions # Return True if directory has write permissions, test opening a file with write permissions if test=True
# return os.access(path, os.R_OK) # known issue on Windows if test: # method 1
file = Path(dir) / 'tmp.txt' file = Path(dir) / 'tmp.txt'
try: try:
with open(file, 'w'): with open(file, 'w'): # open file with write permissions
pass pass
file.unlink() # remove file file.unlink() # remove file
return True return True
except IOError: except IOError:
return False return False
else: # method 2
return os.access(dir, os.R_OK) # possible issues on Windows
def is_docker(): def is_docker():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论