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