- Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathfiles.py
37 lines (30 loc) · 922 Bytes
/
files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
importos
PLOTLY_DIR=os.environ.get(
"PLOTLY_DIR", os.path.join(os.path.expanduser("~"), ".plotly")
)
TEST_FILE=os.path.join(PLOTLY_DIR, ".permission_test")
def_permissions():
try:
ifnotos.path.exists(PLOTLY_DIR):
try:
os.mkdir(PLOTLY_DIR)
exceptException:
# in case of race
ifnotos.path.isdir(PLOTLY_DIR):
raise
withopen(TEST_FILE, "w") asf:
f.write("testing\n")
try:
os.remove(TEST_FILE)
exceptException:
pass
returnTrue
exceptException: # Do not trap KeyboardInterrupt.
returnFalse
_file_permissions=None
defensure_writable_plotly_dir():
# Cache permissions status
global_file_permissions
if_file_permissionsisNone:
_file_permissions=_permissions()
return_file_permissions