MCPcopy
hub / github.com/deadc0de6/dotdrop / removepath

Function removepath

dotdrop/utils.py:157–193  ·  view source on GitHub ↗

remove a file/directory/symlink raises OSError in case of error unless logger is defined. When logger is defined, a logger.warn is printed and a boolean returned

(path, logger=None)

Source from the content-addressed store, hash-verified

155
156
157def removepath(path, logger=None):
158 """
159 remove a file/directory/symlink
160 raises OSError in case of error
161 unless logger is defined.
162
163 When logger is defined, a logger.warn
164 is printed and a boolean returned
165 """
166 if not path:
167 return True
168 if not os.path.lexists(path):
169 return True
170 if os.path.normpath(os.path.expanduser(path)) in NOREMOVE:
171 err = f'Dotdrop refuses to remove {path}'
172 if logger:
173 logger.warn(err)
174 return False
175 LOG.err(err)
176 raise OSError(err)
177 if logger:
178 logger.dbg(f'removing {path}')
179 try:
180 if os.path.islink(path) or os.path.isfile(path):
181 os.unlink(path)
182 elif os.path.isdir(path):
183 shutil.rmtree(path)
184 else:
185 err = f'Unsupported file type for deletion: {path}'
186 raise OSError(err)
187 except Exception as exc:
188 err = str(exc)
189 if logger:
190 logger.warn(err)
191 return False
192 raise OSError(err) from exc
193 return True
194
195
196def samefile(path1, path2):

Callers 15

_remove_pathMethod · 0.90
_updateMethod · 0.90
_apply_trans_updateMethod · 0.90
_handle_dirMethod · 0.90
_apply_trans_updateMethod · 0.90
_dotfile_compareFunction · 0.90
_dotfile_installFunction · 0.90
cmd_installFunction · 0.90
cmd_removeFunction · 0.90
apply_install_transFunction · 0.90
_exec_commandFunction · 0.90
_symlinkMethod · 0.90

Calls 3

warnMethod · 0.80
errMethod · 0.80
dbgMethod · 0.80

Tested by 1

test_removepathMethod · 0.72