##// 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 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 #-----------------------------------------------------------------------------
@@ -69,17 +71,30 b' class ProfileDir(LoggingConfigurable):'
69 71 self.static_dir = os.path.join(new, self.static_dir_name)
70 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 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 True if it created the directory, False otherwise
79 - returns whether 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 src = os.path.join(get_ipython_package_dir(), u'core', u'profile', u'README_STARTUP')
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)
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 )
119 132
120 if os.path.exists(src) and not os.path.exists(readme):
133 if os.path.exists(src):
134 if not os.path.exists(readme):
121 135 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 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