Show More
@@ -14,6 +14,8 b' from ..paths import get_ipython_package_dir' | |||
|
14 | 14 | from ..utils.path import expand_path, ensure_dir_exists |
|
15 | 15 | from traitlets import Unicode, Bool, observe |
|
16 | 16 | |
|
17 | from typing import Optional | |
|
18 | ||
|
17 | 19 | #----------------------------------------------------------------------------- |
|
18 | 20 | # Module errors |
|
19 | 21 | #----------------------------------------------------------------------------- |
@@ -68,18 +70,31 b' class ProfileDir(LoggingConfigurable):' | |||
|
68 | 70 | self.pid_dir = os.path.join(new, self.pid_dir_name) |
|
69 | 71 | self.static_dir = os.path.join(new, self.static_dir_name) |
|
70 | 72 | self.check_dirs() |
|
71 | ||
|
72 | def _mkdir(self, path, mode=None): | |
|
73 | ||
|
74 | def _mkdir(self, path: str, mode: Optional[int] = None) -> bool: | |
|
73 | 75 | """ensure a directory exists at a given path |
|
74 | 76 | |
|
75 | 77 | This is a version of os.mkdir, with the following differences: |
|
76 | 78 | |
|
77 |
- returns |
|
|
79 | - returns wether the directory has been created or not. | |
|
78 | 80 | - ignores EEXIST, protecting against race conditions where |
|
79 | 81 | the dir may have been created in between the check and |
|
80 | 82 | the creation |
|
81 | 83 | - sets permissions if requested and the dir already exists |
|
84 | ||
|
85 | Parameters | |
|
86 | ---------- | |
|
87 | path: str | |
|
88 | path of the dir to create | |
|
89 | mode: int | |
|
90 | see `mode` of `os.mkdir` | |
|
91 | ||
|
92 | Returns | |
|
93 | ------- | |
|
94 | bool: | |
|
95 | returns True if it created the directory, False otherwise | |
|
82 | 96 | """ |
|
97 | ||
|
83 | 98 | if os.path.exists(path): |
|
84 | 99 | if mode and os.stat(path).st_mode != mode: |
|
85 | 100 | try: |
@@ -109,16 +124,20 b' class ProfileDir(LoggingConfigurable):' | |||
|
109 | 124 | |
|
110 | 125 | @observe('startup_dir') |
|
111 | 126 | def check_startup_dir(self, change=None): |
|
112 | self._mkdir(self.startup_dir) | |
|
113 | ||
|
114 | readme = os.path.join(self.startup_dir, 'README') | |
|
115 |
|
|
|
116 | ||
|
117 | if not os.path.exists(src): | |
|
118 | self.log.warning("Could not copy README_STARTUP to startup dir. Source file %s does not exist.", src) | |
|
119 | ||
|
120 | if os.path.exists(src) and not os.path.exists(readme): | |
|
121 | shutil.copy(src, readme) | |
|
127 | if self._mkdir(self.startup_dir): | |
|
128 | readme = os.path.join(self.startup_dir, "README") | |
|
129 | src = os.path.join( | |
|
130 | get_ipython_package_dir(), "core", "profile", "README_STARTUP" | |
|
131 | ) | |
|
132 | ||
|
133 | if not os.path.exists(src): | |
|
134 | self.log.warning( | |
|
135 | "Could not copy README_STARTUP to startup dir. Source file %s does not exist.", | |
|
136 | src, | |
|
137 | ) | |
|
138 | ||
|
139 | if os.path.exists(src) and not os.path.exists(readme): | |
|
140 | shutil.copy(src, readme) | |
|
122 | 141 | |
|
123 | 142 | @observe('security_dir') |
|
124 | 143 | def check_security_dir(self, change=None): |
General Comments 0
You need to be logged in to leave comments.
Login now