Update `is_writeable()` for 2 methods (#4744)
Browse files* Writeable test
* Fix
* Cleanup
- utils/general.py +13 -11
utils/general.py
CHANGED
@@ -112,17 +112,19 @@ def user_config_dir(dir='Ultralytics'):
|
|
112 |
return path
|
113 |
|
114 |
|
115 |
-
def is_writeable(dir):
|
116 |
-
# Return True if directory has write permissions
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
|
128 |
def is_docker():
|
|
|
112 |
return path
|
113 |
|
114 |
|
115 |
+
def is_writeable(dir, test=False):
|
116 |
+
# Return True if directory has write permissions, test opening a file with write permissions if test=True
|
117 |
+
if test: # method 1
|
118 |
+
file = Path(dir) / 'tmp.txt'
|
119 |
+
try:
|
120 |
+
with open(file, 'w'): # open file with write permissions
|
121 |
+
pass
|
122 |
+
file.unlink() # remove file
|
123 |
+
return True
|
124 |
+
except IOError:
|
125 |
+
return False
|
126 |
+
else: # method 2
|
127 |
+
return os.access(dir, os.R_OK) # possible issues on Windows
|
128 |
|
129 |
|
130 |
def is_docker():
|