Show More
@@ -5,6 +5,7 b'' | |||
|
5 | 5 | import json |
|
6 | 6 | import os |
|
7 | 7 | import io |
|
8 | import errno | |
|
8 | 9 | from tornado import web |
|
9 | 10 | |
|
10 | 11 | from IPython.utils.py3compat import PY3 |
@@ -33,8 +34,19 b' def recursive_update(target, new):' | |||
|
33 | 34 | class ConfigHandler(IPythonHandler): |
|
34 | 35 | SUPPORTED_METHODS = ('GET', 'PUT', 'PATCH') |
|
35 | 36 | |
|
37 | @property | |
|
38 | def config_dir(self): | |
|
39 | return os.path.join(self.profile_dir, 'nbconfig') | |
|
40 | ||
|
41 | def ensure_config_dir_exists(self): | |
|
42 | try: | |
|
43 | os.mkdir(self.config_dir, 0o755) | |
|
44 | except OSError as e: | |
|
45 | if e.errno != errno.EEXIST: | |
|
46 | raise | |
|
47 | ||
|
36 | 48 | def file_name(self, section_name): |
|
37 |
return os.path.join(self. |
|
|
49 | return os.path.join(self.config_dir, section_name+'.json') | |
|
38 | 50 | |
|
39 | 51 | @web.authenticated |
|
40 | 52 | @json_errors |
@@ -52,6 +64,7 b' class ConfigHandler(IPythonHandler):' | |||
|
52 | 64 | def put(self, section_name): |
|
53 | 65 | self.get_json_body() # Will raise 400 if content is not valid JSON |
|
54 | 66 | filename = self.file_name(section_name) |
|
67 | self.ensure_config_dir_exists() | |
|
55 | 68 | with open(filename, 'wb') as f: |
|
56 | 69 | f.write(self.request.body) |
|
57 | 70 | self.set_status(204) |
@@ -69,6 +82,7 b' class ConfigHandler(IPythonHandler):' | |||
|
69 | 82 | update = self.get_json_body() |
|
70 | 83 | recursive_update(section, update) |
|
71 | 84 | |
|
85 | self.ensure_config_dir_exists() | |
|
72 | 86 | if PY3: |
|
73 | 87 | f = io.open(filename, 'w', encoding='utf-8') |
|
74 | 88 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now