|
12 | 12 | import warnings
|
13 | 13 |
|
14 | 14 | import six
|
| 15 | +import copy |
15 | 16 |
|
16 | 17 | from plotly import exceptions, optional_imports, session, utils
|
17 | 18 | from plotly.files import (CONFIG_FILE, CREDENTIALS_FILE, FILE_CONTENT,
|
18 |
| - check_file_permissions) |
| 19 | + ensure_writable_plotly_dir) |
19 | 20 |
|
20 | 21 | DEFAULT_PLOTLY_COLORS = ['rgb(31, 119, 180)', 'rgb(255, 127, 14)',
|
21 | 22 | 'rgb(44, 160, 44)', 'rgb(214, 39, 40)',
|
@@ -78,7 +79,7 @@ def ensure_local_plotly_files():
|
78 | 79 | If the config or credential files aren't filled out, then write them
|
79 | 80 | to the disk.
|
80 | 81 | """
|
81 |
| - if check_file_permissions(): |
| 82 | + if ensure_writable_plotly_dir(): |
82 | 83 | for fn in [CREDENTIALS_FILE, CONFIG_FILE]:
|
83 | 84 | utils.ensure_file_exists(fn)
|
84 | 85 | contents = utils.load_json_dict(fn)
|
@@ -124,7 +125,7 @@ def set_credentials_file(username=None,
|
124 | 125 | :param (str) proxy_password: The pw associated with your Proxy un
|
125 | 126 |
|
126 | 127 | """
|
127 |
| - if not check_file_permissions(): |
| 128 | + if not ensure_writable_plotly_dir(): |
128 | 129 | raise exceptions.PlotlyError("You don't have proper file permissions "
|
129 | 130 | "to run this function.")
|
130 | 131 | ensure_local_plotly_files() # make sure what's there is OK
|
@@ -152,11 +153,13 @@ def get_credentials_file(*args):
|
152 | 153 | get_credentials_file('username')
|
153 | 154 |
|
154 | 155 | """
|
155 |
| - if check_file_permissions(): |
156 |
| - ensure_local_plotly_files() # make sure what's there is OK |
157 |
| - return utils.load_json_dict(CREDENTIALS_FILE, *args) |
158 |
| - else: |
159 |
| - return FILE_CONTENT[CREDENTIALS_FILE] |
| 156 | + # Read credentials from file if possible |
| 157 | + credentials = utils.load_json_dict(CREDENTIALS_FILE, *args) |
| 158 | + if not credentials: |
| 159 | + # Credentials could not be read, use defaults |
| 160 | + credentials = copy.copy(FILE_CONTENT[CREDENTIALS_FILE]) |
| 161 | + |
| 162 | + return credentials |
160 | 163 |
|
161 | 164 |
|
162 | 165 | def reset_credentials_file():
|
@@ -185,7 +188,7 @@ def set_config_file(plotly_domain=None,
|
185 | 188 | :param (bool) world_readable: True = public, False = private
|
186 | 189 |
|
187 | 190 | """
|
188 |
| - if not check_file_permissions(): |
| 191 | + if not ensure_writable_plotly_dir(): |
189 | 192 | raise exceptions.PlotlyError("You don't have proper file permissions "
|
190 | 193 | "to run this function.")
|
191 | 194 | ensure_local_plotly_files() # make sure what's there is OK
|
@@ -247,11 +250,13 @@ def get_config_file(*args):
|
247 | 250 | get_config_file('plotly_domain')
|
248 | 251 |
|
249 | 252 | """
|
250 |
| - if check_file_permissions(): |
251 |
| - ensure_local_plotly_files() # make sure what's there is OK |
252 |
| - return utils.load_json_dict(CONFIG_FILE, *args) |
253 |
| - else: |
254 |
| - return FILE_CONTENT[CONFIG_FILE] |
| 253 | + # Read config from file if possible |
| 254 | + config = utils.load_json_dict(CONFIG_FILE, *args) |
| 255 | + if not config: |
| 256 | + # Config could not be read, use defaults |
| 257 | + config = copy.copy(FILE_CONTENT[CONFIG_FILE]) |
| 258 | + |
| 259 | + return config |
255 | 260 |
|
256 | 261 |
|
257 | 262 | def reset_config_file():
|
|
0 commit comments