Show More
@@ -39,7 +39,7 b' from IPython.config.application import Application, catch_config_error' | |||||
39 | from IPython.config.loader import ConfigFileNotFound |
|
39 | from IPython.config.loader import ConfigFileNotFound | |
40 | from IPython.core import release, crashhandler |
|
40 | from IPython.core import release, crashhandler | |
41 | from IPython.core.profiledir import ProfileDir, ProfileDirError |
|
41 | from IPython.core.profiledir import ProfileDir, ProfileDirError | |
42 | from IPython.utils.path import get_ipython_dir, get_ipython_package_dir |
|
42 | from IPython.utils.path import get_ipython_dir, get_ipython_package_dir, ensure_dir_exists | |
43 | from IPython.utils import py3compat |
|
43 | from IPython.utils import py3compat | |
44 | from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance |
|
44 | from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, Set, Instance | |
45 |
|
45 | |||
@@ -220,20 +220,18 b' class BaseIPythonApplication(Application):' | |||||
220 | sys.getfilesystemencoding() |
|
220 | sys.getfilesystemencoding() | |
221 | ) |
|
221 | ) | |
222 | sys.path.append(str_path) |
|
222 | sys.path.append(str_path) | |
223 | if not os.path.isdir(new): |
|
223 | ensure_dir_exists(new) | |
224 | os.makedirs(new, mode=0o777) |
|
|||
225 | readme = os.path.join(new, 'README') |
|
224 | readme = os.path.join(new, 'README') | |
226 | readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') |
|
225 | readme_src = os.path.join(get_ipython_package_dir(), u'config', u'profile', 'README') | |
227 | if not os.path.exists(readme) and os.path.exists(readme_src): |
|
226 | if not os.path.exists(readme) and os.path.exists(readme_src): | |
228 | shutil.copy(readme_src, readme) |
|
227 | shutil.copy(readme_src, readme) | |
229 | for d in ('extensions', 'nbextensions'): |
|
228 | for d in ('extensions', 'nbextensions'): | |
230 | path = os.path.join(new, d) |
|
229 | path = os.path.join(new, d) | |
231 | if not os.path.exists(path): |
|
230 | try: | |
232 | try: |
|
231 | ensure_dir_exists(path) | |
233 | os.mkdir(path) |
|
232 | except OSError: | |
234 | except OSError as e: |
|
233 | # this will not be EEXIST | |
235 | if e.errno != errno.EEXIST: |
|
234 | self.log.error("couldn't create path %s: %s", path, e) | |
236 | self.log.error("couldn't create path %s: %s", path, e) |
|
|||
237 | self.log.debug("IPYTHONDIR set to: %s" % new) |
|
235 | self.log.debug("IPYTHONDIR set to: %s" % new) | |
238 |
|
236 | |||
239 | def load_config_file(self, suppress_errors=True): |
|
237 | def load_config_file(self, suppress_errors=True): |
@@ -1,27 +1,15 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """A class for managing IPython extensions. |
|
2 | """A class for managing IPython extensions.""" | |
3 |
|
3 | |||
4 | Authors: |
|
4 | # Copyright (c) IPython Development Team. | |
5 |
|
5 | # Distributed under the terms of the Modified BSD License. | ||
6 | * Brian Granger |
|
|||
7 | """ |
|
|||
8 |
|
||||
9 | #----------------------------------------------------------------------------- |
|
|||
10 | # Copyright (C) 2010-2011 The IPython Development Team |
|
|||
11 | # |
|
|||
12 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
13 | # the file COPYING, distributed as part of this software. |
|
|||
14 | #----------------------------------------------------------------------------- |
|
|||
15 |
|
||||
16 | #----------------------------------------------------------------------------- |
|
|||
17 | # Imports |
|
|||
18 | #----------------------------------------------------------------------------- |
|
|||
19 |
|
6 | |||
20 | import os |
|
7 | import os | |
21 | from shutil import copyfile |
|
8 | from shutil import copyfile | |
22 | import sys |
|
9 | import sys | |
23 |
|
10 | |||
24 | from IPython.config.configurable import Configurable |
|
11 | from IPython.config.configurable import Configurable | |
|
12 | from IPython.utils.path import ensure_dir_exists | |||
25 | from IPython.utils.traitlets import Instance |
|
13 | from IPython.utils.traitlets import Instance | |
26 | from IPython.utils.py3compat import PY3 |
|
14 | from IPython.utils.py3compat import PY3 | |
27 | if PY3: |
|
15 | if PY3: | |
@@ -77,8 +65,7 b' class ExtensionManager(Configurable):' | |||||
77 | return os.path.join(self.shell.ipython_dir, u'extensions') |
|
65 | return os.path.join(self.shell.ipython_dir, u'extensions') | |
78 |
|
66 | |||
79 | def _on_ipython_dir_changed(self): |
|
67 | def _on_ipython_dir_changed(self): | |
80 |
|
|
68 | ensure_dir_exists(self.ipython_extension_dir) | |
81 | os.makedirs(self.ipython_extension_dir, mode = 0o777) |
|
|||
82 |
|
69 | |||
83 | def load_extension(self, module_str): |
|
70 | def load_extension(self, module_str): | |
84 | """Load an IPython extension by its module name. |
|
71 | """Load an IPython extension by its module name. | |
@@ -162,8 +149,7 b' class ExtensionManager(Configurable):' | |||||
162 | Returns the full path to the installed file. |
|
149 | Returns the full path to the installed file. | |
163 | """ |
|
150 | """ | |
164 | # Ensure the extension directory exists |
|
151 | # Ensure the extension directory exists | |
165 |
|
|
152 | ensure_dir_exists(self.ipython_extension_dir) | |
166 | os.makedirs(self.ipython_extension_dir, mode = 0o777) |
|
|||
167 |
|
153 | |||
168 | if os.path.isfile(url): |
|
154 | if os.path.isfile(url): | |
169 | src_filename = os.path.basename(url) |
|
155 | src_filename = os.path.basename(url) |
@@ -66,7 +66,7 b' from IPython.utils import openpy' | |||||
66 | from IPython.utils.decorators import undoc |
|
66 | from IPython.utils.decorators import undoc | |
67 | from IPython.utils.io import ask_yes_no |
|
67 | from IPython.utils.io import ask_yes_no | |
68 | from IPython.utils.ipstruct import Struct |
|
68 | from IPython.utils.ipstruct import Struct | |
69 | from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename |
|
69 | from IPython.utils.path import get_home_dir, get_ipython_dir, get_py_filename, unquote_filename, ensure_dir_exists | |
70 | from IPython.utils.pickleshare import PickleShareDB |
|
70 | from IPython.utils.pickleshare import PickleShareDB | |
71 | from IPython.utils.process import system, getoutput |
|
71 | from IPython.utils.process import system, getoutput | |
72 | from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types, |
|
72 | from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types, | |
@@ -524,8 +524,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
524 | #------------------------------------------------------------------------- |
|
524 | #------------------------------------------------------------------------- | |
525 |
|
525 | |||
526 | def _ipython_dir_changed(self, name, new): |
|
526 | def _ipython_dir_changed(self, name, new): | |
527 | if not os.path.isdir(new): |
|
527 | ensure_dir_exists(new) | |
528 | os.makedirs(new, mode = 0o777) |
|
|||
529 |
|
528 | |||
530 | def set_autoindent(self,value=None): |
|
529 | def set_autoindent(self,value=None): | |
531 | """Set the autoindent flag, checking for readline support. |
|
530 | """Set the autoindent flag, checking for readline support. |
@@ -1,25 +1,8 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """ |
|
2 | """An object for managing IPython profile directories.""" | |
3 | An object for managing IPython profile directories. |
|
|||
4 |
|
3 | |||
5 | Authors: |
|
4 | # Copyright (c) IPython Development Team. | |
6 |
|
5 | # Distributed under the terms of the Modified BSD License. | ||
7 | * Brian Granger |
|
|||
8 | * Fernando Perez |
|
|||
9 | * Min RK |
|
|||
10 |
|
||||
11 | """ |
|
|||
12 |
|
||||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Copyright (C) 2011 The IPython Development Team |
|
|||
15 | # |
|
|||
16 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
17 | # the file COPYING, distributed as part of this software. |
|
|||
18 | #----------------------------------------------------------------------------- |
|
|||
19 |
|
||||
20 | #----------------------------------------------------------------------------- |
|
|||
21 | # Imports |
|
|||
22 | #----------------------------------------------------------------------------- |
|
|||
23 |
|
6 | |||
24 | import os |
|
7 | import os | |
25 | import shutil |
|
8 | import shutil | |
@@ -27,16 +10,11 b' import errno' | |||||
27 | import time |
|
10 | import time | |
28 |
|
11 | |||
29 | from IPython.config.configurable import LoggingConfigurable |
|
12 | from IPython.config.configurable import LoggingConfigurable | |
30 | from IPython.utils.path import get_ipython_package_dir, expand_path |
|
13 | from IPython.utils.path import get_ipython_package_dir, expand_path, ensure_dir_exists | |
31 | from IPython.utils import py3compat |
|
14 | from IPython.utils import py3compat | |
32 | from IPython.utils.traitlets import Unicode, Bool |
|
15 | from IPython.utils.traitlets import Unicode, Bool | |
33 |
|
16 | |||
34 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
35 | # Classes and functions |
|
|||
36 | #----------------------------------------------------------------------------- |
|
|||
37 |
|
||||
38 |
|
||||
39 | #----------------------------------------------------------------------------- |
|
|||
40 | # Module errors |
|
18 | # Module errors | |
41 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
42 |
|
20 | |||
@@ -80,16 +58,7 b' class ProfileDir(LoggingConfigurable):' | |||||
80 | if self._location_isset: |
|
58 | if self._location_isset: | |
81 | raise RuntimeError("Cannot set profile location more than once.") |
|
59 | raise RuntimeError("Cannot set profile location more than once.") | |
82 | self._location_isset = True |
|
60 | self._location_isset = True | |
83 | num_tries = 0 |
|
61 | ensure_dir_exists(new) | |
84 | max_tries = 5 |
|
|||
85 | while not os.path.isdir(new): |
|
|||
86 | try: |
|
|||
87 | os.makedirs(new) |
|
|||
88 | except OSError: |
|
|||
89 | if num_tries > max_tries: |
|
|||
90 | raise |
|
|||
91 | num_tries += 1 |
|
|||
92 | time.sleep(0.5) |
|
|||
93 |
|
62 | |||
94 | # ensure config files exist: |
|
63 | # ensure config files exist: | |
95 | self.security_dir = os.path.join(new, self.security_dir_name) |
|
64 | self.security_dir = os.path.join(new, self.security_dir_name) |
@@ -1,12 +1,8 b'' | |||||
1 | # coding: utf-8 |
|
1 | # coding: utf-8 | |
2 | """Utilities for installing Javascript extensions for the notebook""" |
|
2 | """Utilities for installing Javascript extensions for the notebook""" | |
3 |
|
3 | |||
4 | #----------------------------------------------------------------------------- |
|
4 | # Copyright (c) IPython Development Team. | |
5 | # Copyright (C) 2014 The IPython Development Team |
|
5 | # Distributed under the terms of the Modified BSD License. | |
6 | # |
|
|||
7 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
8 | # the file COPYING, distributed as part of this software. |
|
|||
9 | #----------------------------------------------------------------------------- |
|
|||
10 |
|
6 | |||
11 | from __future__ import print_function |
|
7 | from __future__ import print_function | |
12 |
|
8 | |||
@@ -24,7 +20,7 b' except ImportError:' | |||||
24 | from urlparse import urlparse |
|
20 | from urlparse import urlparse | |
25 | from urllib import urlretrieve |
|
21 | from urllib import urlretrieve | |
26 |
|
22 | |||
27 | from IPython.utils.path import get_ipython_dir |
|
23 | from IPython.utils.path import get_ipython_dir, ensure_dir_exists | |
28 | from IPython.utils.py3compat import string_types, cast_unicode_py2 |
|
24 | from IPython.utils.py3compat import string_types, cast_unicode_py2 | |
29 | from IPython.utils.tempdir import TemporaryDirectory |
|
25 | from IPython.utils.tempdir import TemporaryDirectory | |
30 |
|
26 | |||
@@ -109,8 +105,7 b' def install_nbextension(files, overwrite=False, symlink=False, ipython_dir=None,' | |||||
109 | ipython_dir = ipython_dir or get_ipython_dir() |
|
105 | ipython_dir = ipython_dir or get_ipython_dir() | |
110 | nbext = pjoin(ipython_dir, u'nbextensions') |
|
106 | nbext = pjoin(ipython_dir, u'nbextensions') | |
111 | # make sure nbextensions dir exists |
|
107 | # make sure nbextensions dir exists | |
112 | if not os.path.exists(nbext): |
|
108 | ensure_dir_exists(nbext) | |
113 | os.makedirs(nbext) |
|
|||
114 |
|
109 | |||
115 | if isinstance(files, string_types): |
|
110 | if isinstance(files, string_types): | |
116 | # one file given, turn it into a list |
|
111 | # one file given, turn it into a list |
@@ -1,21 +1,7 b'' | |||||
1 | """A notebook manager that uses the local file system for storage. |
|
1 | """A notebook manager that uses the local file system for storage.""" | |
2 |
|
2 | |||
3 | Authors: |
|
3 | # Copyright (c) IPython Development Team. | |
4 |
|
4 | # Distributed under the terms of the Modified BSD License. | ||
5 | * Brian Granger |
|
|||
6 | * Zach Sailer |
|
|||
7 | """ |
|
|||
8 |
|
||||
9 | #----------------------------------------------------------------------------- |
|
|||
10 | # Copyright (C) 2011 The IPython Development Team |
|
|||
11 | # |
|
|||
12 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
13 | # the file COPYING, distributed as part of this software. |
|
|||
14 | #----------------------------------------------------------------------------- |
|
|||
15 |
|
||||
16 | #----------------------------------------------------------------------------- |
|
|||
17 | # Imports |
|
|||
18 | #----------------------------------------------------------------------------- |
|
|||
19 |
|
5 | |||
20 | import io |
|
6 | import io | |
21 | import os |
|
7 | import os | |
@@ -26,6 +12,7 b' from tornado import web' | |||||
26 |
|
12 | |||
27 | from .nbmanager import NotebookManager |
|
13 | from .nbmanager import NotebookManager | |
28 | from IPython.nbformat import current |
|
14 | from IPython.nbformat import current | |
|
15 | from IPython.utils.path import ensure_dir_exists | |||
29 | from IPython.utils.traitlets import Unicode, Bool, TraitError |
|
16 | from IPython.utils.traitlets import Unicode, Bool, TraitError | |
30 | from IPython.utils.py3compat import getcwd |
|
17 | from IPython.utils.py3compat import getcwd | |
31 | from IPython.utils import tz |
|
18 | from IPython.utils import tz | |
@@ -402,8 +389,7 b' class FileNotebookManager(NotebookManager):' | |||||
402 | ) |
|
389 | ) | |
403 | os_path = self._get_os_path(path=path) |
|
390 | os_path = self._get_os_path(path=path) | |
404 | cp_dir = os.path.join(os_path, self.checkpoint_dir) |
|
391 | cp_dir = os.path.join(os_path, self.checkpoint_dir) | |
405 |
|
|
392 | ensure_dir_exists(cp_dir) | |
406 | os.mkdir(cp_dir) |
|
|||
407 | cp_path = os.path.join(cp_dir, filename) |
|
393 | cp_path = os.path.join(cp_dir, filename) | |
408 | return cp_path |
|
394 | return cp_path | |
409 |
|
395 | |||
@@ -429,8 +415,6 b' class FileNotebookManager(NotebookManager):' | |||||
429 | checkpoint_id = u"checkpoint" |
|
415 | checkpoint_id = u"checkpoint" | |
430 | cp_path = self.get_checkpoint_path(checkpoint_id, name, path) |
|
416 | cp_path = self.get_checkpoint_path(checkpoint_id, name, path) | |
431 | self.log.debug("creating checkpoint for notebook %s", name) |
|
417 | self.log.debug("creating checkpoint for notebook %s", name) | |
432 | if not os.path.exists(self.checkpoint_dir): |
|
|||
433 | os.mkdir(self.checkpoint_dir) |
|
|||
434 | self._copy(nb_path, cp_path) |
|
418 | self._copy(nb_path, cp_path) | |
435 |
|
419 | |||
436 | # return the checkpoint info |
|
420 | # return the checkpoint info |
@@ -8,7 +8,7 b' import os' | |||||
8 | import glob |
|
8 | import glob | |
9 |
|
9 | |||
10 | from IPython.utils.traitlets import Unicode |
|
10 | from IPython.utils.traitlets import Unicode | |
11 | from IPython.utils.path import link_or_copy |
|
11 | from IPython.utils.path import link_or_copy, ensure_dir_exists | |
12 | from IPython.utils.py3compat import unicode_type |
|
12 | from IPython.utils.py3compat import unicode_type | |
13 |
|
13 | |||
14 | from .base import WriterBase |
|
14 | from .base import WriterBase | |
@@ -28,8 +28,8 b' class FilesWriter(WriterBase):' | |||||
28 |
|
28 | |||
29 | # Make sure that the output directory exists. |
|
29 | # Make sure that the output directory exists. | |
30 | def _build_directory_changed(self, name, old, new): |
|
30 | def _build_directory_changed(self, name, old, new): | |
31 | if new and not os.path.isdir(new): |
|
31 | if new: | |
32 |
|
|
32 | ensure_dir_exists(new) | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | def __init__(self, **kw): |
|
35 | def __init__(self, **kw): | |
@@ -39,9 +39,9 b' class FilesWriter(WriterBase):' | |||||
39 |
|
39 | |||
40 | def _makedir(self, path): |
|
40 | def _makedir(self, path): | |
41 | """Make a directory if it doesn't already exist""" |
|
41 | """Make a directory if it doesn't already exist""" | |
42 | if path and not os.path.isdir(path): |
|
42 | if path: | |
43 | self.log.info("Making directory %s", path) |
|
43 | self.log.info("Making directory %s", path) | |
44 |
|
|
44 | ensure_dir_exists(path) | |
45 |
|
45 | |||
46 | def write(self, output, resources, notebook_name=None, **kw): |
|
46 | def write(self, output, resources, notebook_name=None, **kw): | |
47 | """ |
|
47 | """ |
@@ -1,23 +1,8 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """ |
|
2 | """Facilities for launching IPython processes asynchronously.""" | |
3 | Facilities for launching IPython processes asynchronously. |
|
|||
4 |
|
3 | |||
5 | Authors: |
|
4 | # Copyright (c) IPython Development Team. | |
6 |
|
5 | # Distributed under the terms of the Modified BSD License. | ||
7 | * Brian Granger |
|
|||
8 | * MinRK |
|
|||
9 | """ |
|
|||
10 |
|
||||
11 | #----------------------------------------------------------------------------- |
|
|||
12 | # Copyright (C) 2008-2011 The IPython Development Team |
|
|||
13 | # |
|
|||
14 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
15 | # the file COPYING, distributed as part of this software. |
|
|||
16 | #----------------------------------------------------------------------------- |
|
|||
17 |
|
||||
18 | #----------------------------------------------------------------------------- |
|
|||
19 | # Imports |
|
|||
20 | #----------------------------------------------------------------------------- |
|
|||
21 |
|
6 | |||
22 | import copy |
|
7 | import copy | |
23 | import logging |
|
8 | import logging | |
@@ -62,7 +47,7 b' from IPython.utils.traitlets import (' | |||||
62 | Any, Integer, CFloat, List, Unicode, Dict, Instance, HasTraits, CRegExp |
|
47 | Any, Integer, CFloat, List, Unicode, Dict, Instance, HasTraits, CRegExp | |
63 | ) |
|
48 | ) | |
64 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
49 | from IPython.utils.encoding import DEFAULT_ENCODING | |
65 | from IPython.utils.path import get_home_dir |
|
50 | from IPython.utils.path import get_home_dir, ensure_dir_exists | |
66 | from IPython.utils.process import find_cmd, FindCmdError |
|
51 | from IPython.utils.process import find_cmd, FindCmdError | |
67 | from IPython.utils.py3compat import iteritems, itervalues |
|
52 | from IPython.utils.py3compat import iteritems, itervalues | |
68 |
|
53 | |||
@@ -629,8 +614,7 b' class SSHLauncher(LocalProcessLauncher):' | |||||
629 | elif check == u'yes': |
|
614 | elif check == u'yes': | |
630 | break |
|
615 | break | |
631 | local_dir = os.path.dirname(local) |
|
616 | local_dir = os.path.dirname(local) | |
632 |
|
|
617 | ensure_dir_exists(local_dir, 775) | |
633 | os.makedirs(local_dir, 775) |
|
|||
634 | check_output(self.scp_cmd + [full_remote, local]) |
|
618 | check_output(self.scp_cmd + [full_remote, local]) | |
635 |
|
619 | |||
636 | def fetch_files(self): |
|
620 | def fetch_files(self): |
@@ -1,20 +1,13 b'' | |||||
1 | #----------------------------------------------------------------------------- |
|
1 | # Copyright (c) IPython Development Team. | |
2 | # Copyright (c) 2010, IPython Development Team. |
|
|||
3 | # |
|
|||
4 | # Distributed under the terms of the Modified BSD License. |
|
2 | # Distributed under the terms of the Modified BSD License. | |
5 | # |
|
|||
6 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
7 | #----------------------------------------------------------------------------- |
|
|||
8 |
|
3 | |||
9 | # Standard libary imports. |
|
|||
10 | from base64 import decodestring |
|
4 | from base64 import decodestring | |
11 | import os |
|
5 | import os | |
12 | import re |
|
6 | import re | |
13 |
|
7 | |||
14 | # System libary imports. |
|
|||
15 | from IPython.external.qt import QtCore, QtGui |
|
8 | from IPython.external.qt import QtCore, QtGui | |
16 |
|
9 | |||
17 | # Local imports |
|
10 | from IPython.utils.path import ensure_dir_exists | |
18 | from IPython.utils.traitlets import Bool |
|
11 | from IPython.utils.traitlets import Bool | |
19 | from IPython.qt.svg import save_svg, svg_to_clipboard, svg_to_image |
|
12 | from IPython.qt.svg import save_svg, svg_to_clipboard, svg_to_image | |
20 | from .ipython_widget import IPythonWidget |
|
13 | from .ipython_widget import IPythonWidget | |
@@ -233,8 +226,7 b' class RichIPythonWidget(IPythonWidget):' | |||||
233 | return "<b>Couldn't find image %s</b>" % match.group("name") |
|
226 | return "<b>Couldn't find image %s</b>" % match.group("name") | |
234 |
|
227 | |||
235 | if path is not None: |
|
228 | if path is not None: | |
236 |
|
|
229 | ensure_dir_exists(path) | |
237 | os.mkdir(path) |
|
|||
238 | relpath = os.path.basename(path) |
|
230 | relpath = os.path.basename(path) | |
239 | if image.save("%s/qt_img%s.%s" % (path, match.group("name"), format), |
|
231 | if image.save("%s/qt_img%s.%s" % (path, match.group("name"), format), | |
240 | "PNG"): |
|
232 | "PNG"): |
@@ -3,16 +3,8 b'' | |||||
3 | Utilities for path handling. |
|
3 | Utilities for path handling. | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | #----------------------------------------------------------------------------- |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # Copyright (C) 2008-2011 The IPython Development Team |
|
7 | # Distributed under the terms of the Modified BSD License. | |
8 | # |
|
|||
9 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
10 | # the file COPYING, distributed as part of this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
||||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 |
|
8 | |||
17 | import os |
|
9 | import os | |
18 | import sys |
|
10 | import sys | |
@@ -324,7 +316,7 b' def get_ipython_cache_dir():' | |||||
324 | return get_ipython_dir() |
|
316 | return get_ipython_dir() | |
325 | ipdir = os.path.join(xdgdir, "ipython") |
|
317 | ipdir = os.path.join(xdgdir, "ipython") | |
326 | if not os.path.exists(ipdir) and _writable_dir(xdgdir): |
|
318 | if not os.path.exists(ipdir) and _writable_dir(xdgdir): | |
327 |
|
|
319 | ensure_dir_exists(ipdir) | |
328 | elif not _writable_dir(xdgdir): |
|
320 | elif not _writable_dir(xdgdir): | |
329 | return get_ipython_dir() |
|
321 | return get_ipython_dir() | |
330 |
|
322 | |||
@@ -572,3 +564,17 b' def link_or_copy(src, dst):' | |||||
572 | # Either link isn't supported, or the filesystem doesn't support |
|
564 | # Either link isn't supported, or the filesystem doesn't support | |
573 | # linking, or 'src' and 'dst' are on different filesystems. |
|
565 | # linking, or 'src' and 'dst' are on different filesystems. | |
574 | shutil.copy(src, dst) |
|
566 | shutil.copy(src, dst) | |
|
567 | ||||
|
568 | def ensure_dir_exists(path, mode=0o777): | |||
|
569 | """ensure that a directory exists | |||
|
570 | ||||
|
571 | If it doesn't exist, try to create it and protect against a race condition | |||
|
572 | if another process is doing the same. | |||
|
573 | """ | |||
|
574 | if not os.path.exists(path): | |||
|
575 | try: | |||
|
576 | os.makedirs(path, mode=mode) | |||
|
577 | except OSError as e: | |||
|
578 | if e.errno != errno.EEXIST: | |||
|
579 | raise | |||
|
580 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now