MCPcopy
hub / github.com/alibaba/EasyCV / exists

Method exists

easycv/file/file_io.py:263–292  ·  view source on GitHub ↗

Whether the file exists, same usage as `os.path.exists`. Support local path and oss path. Example: from easycv.file import io io.access_oss(your oss config) # only oss file need, refer to `IO.access_oss` ret = io.exists('oss://bucket_name

(self, path)

Source from the content-addressed store, hash-verified

261 raise ValueError('invalid mode: %s' % mode)
262
263 def exists(self, path):
264 """
265 Whether the file exists, same usage as `os.path.exists`.
266 Support local path and oss path.
267
268 Example:
269 from easycv.file import io
270 io.access_oss(your oss config) # only oss file need, refer to `IO.access_oss`
271 ret = io.exists('oss://bucket_name/dir')
272 print(ret)
273 Args:
274 path: oss path or local path
275 """
276 if not is_oss_path(path):
277 return super().exists(path)
278
279 bucket, _path = self._get_bucket_obj_and_path(path)
280 # TODO: 网络不稳时try,其他错误直接抛出
281 if not path.endswith('/'):
282 # if file exists
283 exists = self._obj_exists(bucket, _path)
284 # if bucket exists
285 if not exists:
286 _path = self._correct_oss_dir(_path)
287 exists = self._obj_exists(bucket, _path)
288 else:
289 # if bucket exists
290 exists = self._obj_exists(bucket, _path)
291
292 return exists
293
294 def _obj_exists(self, bucket, path):
295 return bucket.object_exists(path)

Callers 15

_read_ossMethod · 0.95
_write_ossMethod · 0.95
_append_ossMethod · 0.95
rmtreeMethod · 0.95
isdirMethod · 0.95
isfileMethod · 0.95
get_hashFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 4

_obj_existsMethod · 0.95
_correct_oss_dirMethod · 0.95
is_oss_pathFunction · 0.85

Tested by 15

get_tmp_dirFunction · 0.36
clean_tmpMethod · 0.36
test_openMethod · 0.36
test_existsMethod · 0.36
test_moveMethod · 0.36
test_copyMethod · 0.36
test_copytreeMethod · 0.36
test_openMethod · 0.36
test_existsMethod · 0.36