Show More
@@ -1,6 +1,7 b'' | |||
|
1 | 1 | import io |
|
2 | 2 | import json |
|
3 | 3 | import os |
|
4 | import shutil | |
|
4 | 5 | import sys |
|
5 | 6 | |
|
6 | 7 | pjoin = os.path.join |
@@ -130,6 +131,35 b' class KernelSpecManager(HasTraits):' | |||
|
130 | 131 | raise NoSuchKernel(kernel_name) |
|
131 | 132 | return KernelSpec.from_resource_dir(resource_dir) |
|
132 | 133 | |
|
134 | def install_kernel_spec(self, source_dir, kernel_name=None, system=False, | |
|
135 | replace=False): | |
|
136 | """Install a kernel spec by copying its directory. | |
|
137 | ||
|
138 | If ``kernel_name`` is not given, the basename of ``source_dir`` will | |
|
139 | be used. | |
|
140 | ||
|
141 | If ``system`` is True, it will attempt to install into the systemwide | |
|
142 | kernel registry. If the process does not have appropriate permissions, | |
|
143 | an :exc:`OSError` will be raised. | |
|
144 | ||
|
145 | If ``replace`` is True, this will replace an existing kernel of the same | |
|
146 | name. Otherwise, if the destination already exists, an :exc:`OSError` | |
|
147 | will be raised. | |
|
148 | """ | |
|
149 | if not kernel_name: | |
|
150 | kernel_name = os.path.basename(source_dir) | |
|
151 | kernel_name = kernel_name.lower() | |
|
152 | ||
|
153 | if system: | |
|
154 | destination = os.path.join(SYSTEM_KERNEL_DIR, kernel_name) | |
|
155 | else: | |
|
156 | destination = os.path.join(self.user_kernel_dir, kernel_name) | |
|
157 | ||
|
158 | if replace and os.path.isdir(destination): | |
|
159 | shutil.rmtree(destination) | |
|
160 | ||
|
161 | shutil.copytree(source_dir, destination) | |
|
162 | ||
|
133 | 163 | def find_kernel_specs(): |
|
134 | 164 | """Returns a dict mapping kernel names to resource directories.""" |
|
135 | 165 | return KernelSpecManager().find_kernel_specs() |
@@ -140,3 +170,8 b' def get_kernel_spec(kernel_name):' | |||
|
140 | 170 | Raises KeyError if the given kernel name is not found. |
|
141 | 171 | """ |
|
142 | 172 | return KernelSpecManager().get_kernel_spec(kernel_name) |
|
173 | ||
|
174 | def install_kernel_spec(source_dir, kernel_name=None, system=False): | |
|
175 | return KernelSpecManager().install_kernel_spec(source_dir, kernel_name, system) | |
|
176 | ||
|
177 | install_kernel_spec.__doc__ = KernelSpecManager.install_kernel_spec.__doc__ |
General Comments 0
You need to be logged in to leave comments.
Login now