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