mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
Fix is_writeable()
for 3 OS support (#4743)
* Fix `is_writeable()` for 3 OS support * Update general.py
This commit is contained in:
parent
19e28e3bfe
commit
a144536f88
@ -105,19 +105,24 @@ def get_latest_run(search_dir='.'):
|
|||||||
|
|
||||||
def user_config_dir(dir='Ultralytics'):
|
def user_config_dir(dir='Ultralytics'):
|
||||||
# Return path of user configuration directory (make if necessary)
|
# Return path of user configuration directory (make if necessary)
|
||||||
system = platform.system()
|
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'} # 3 config dirs
|
||||||
cfg = {'Windows': 'AppData/Roaming', 'Linux': '.config', 'Darwin': 'Library/Application Support'}
|
path = Path.home() / cfg.get(platform.system(), '') # OS-specific config dir
|
||||||
path = Path.home() / cfg.get(system, '') / dir
|
path = (path if is_writeable(path) else Path('/tmp')) / dir # GCP and AWS lambda fix, only /tmp is writeable
|
||||||
if system == 'Linux' and not is_writeable(path): # GCP functions and AWS lambda solution, only /tmp is writeable
|
path.mkdir(exist_ok=True) # make if required
|
||||||
path = Path('/tmp') / dir
|
|
||||||
if not path.is_dir():
|
|
||||||
path.mkdir() # make dir if required
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def is_writeable(path):
|
def is_writeable(dir):
|
||||||
# Return True if path has write permissions (Warning: known issue on Windows)
|
# Return True if directory has write permissions
|
||||||
return os.access(path, os.R_OK)
|
# return os.access(path, os.R_OK) # known issue on Windows
|
||||||
|
file = Path(dir) / 'tmp.txt'
|
||||||
|
try:
|
||||||
|
with open(file, 'w'):
|
||||||
|
pass
|
||||||
|
file.unlink() # remove file
|
||||||
|
return True
|
||||||
|
except IOError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def is_docker():
|
def is_docker():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user