megfile 3.0.5__py3-none-any.whl → 3.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
megfile/smart.py CHANGED
@@ -270,7 +270,11 @@ def _default_copy_func(
270
270
  src_path: PathLike,
271
271
  dst_path: PathLike,
272
272
  callback: Optional[Callable[[int], None]] = None,
273
- followlinks: bool = False) -> None:
273
+ followlinks: bool = False,
274
+ overwrite: bool = True) -> None:
275
+ if not overwrite and smart_exists(dst_path):
276
+ return
277
+
274
278
  with smart_open(src_path, 'rb', followlinks=followlinks) as fsrc:
275
279
  with smart_open(dst_path, 'wb') as fdst:
276
280
  # This magic number is copied from copyfileobj
@@ -295,7 +299,8 @@ def smart_copy(
295
299
  src_path: PathLike,
296
300
  dst_path: PathLike,
297
301
  callback: Optional[Callable[[int], None]] = None,
298
- followlinks: bool = False) -> None:
302
+ followlinks: bool = False,
303
+ overwrite: bool = True) -> None:
299
304
  '''
300
305
  Copy file from source path to destination path
301
306
 
@@ -319,6 +324,7 @@ def smart_copy(
319
324
  :param dst_path: Given destination path
320
325
  :param callback: Called periodically during copy, and the input parameter is the data size (in bytes) of copy since the last call
321
326
  :param followlinks: False if regard symlink as file, else True
327
+ :param overwrite: whether or not overwrite file when exists, default is True
322
328
  '''
323
329
  # this function contains plenty of manual polymorphism
324
330
  if smart_islink(src_path) and is_s3(dst_path) and not followlinks:
@@ -333,13 +339,19 @@ def smart_copy(
333
339
  copy_func = _default_copy_func
334
340
  try:
335
341
  copy_func(
336
- src_path, dst_path, callback=callback,
337
- followlinks=followlinks) # type: ignore
342
+ src_path,
343
+ dst_path,
344
+ callback=callback,
345
+ followlinks=followlinks,
346
+ overwrite=overwrite) # type: ignore
338
347
  except S3UnknownError as e:
339
348
  if 'cannot schedule new futures after interpreter shutdown' in str(e):
340
349
  _default_copy_func(
341
- src_path, dst_path, callback=callback,
342
- followlinks=followlinks) # type: ignore
350
+ src_path,
351
+ dst_path,
352
+ callback=callback,
353
+ followlinks=followlinks,
354
+ overwrite=overwrite) # type: ignore
343
355
  else:
344
356
  raise
345
357
 
@@ -352,6 +364,7 @@ def _smart_sync_single_file(items: dict):
352
364
  followlinks = items['followlinks']
353
365
  callback_after_copy_file = items['callback_after_copy_file']
354
366
  force = items['force']
367
+ overwrite = items['overwrite']
355
368
 
356
369
  content_path = os.path.relpath(src_file_path, start=src_root_path)
357
370
  if len(content_path) and content_path != '.':
@@ -365,7 +378,11 @@ def _smart_sync_single_file(items: dict):
365
378
  dst_protocol, _ = SmartPath._extract_protocol(dst_abs_file_path)
366
379
  should_sync = True
367
380
  try:
368
- if not force and smart_exists(dst_abs_file_path) and is_same_file(
381
+ if force:
382
+ pass
383
+ elif not overwrite and smart_exists(dst_abs_file_path):
384
+ should_sync = False
385
+ elif smart_exists(dst_abs_file_path) and is_same_file(
369
386
  smart_stat(src_file_path, follow_symlinks=followlinks),
370
387
  smart_stat(dst_abs_file_path, follow_symlinks=followlinks),
371
388
  get_sync_type(src_protocol, dst_protocol)):
@@ -382,6 +399,7 @@ def _smart_sync_single_file(items: dict):
382
399
  followlinks=followlinks)
383
400
  if callback_after_copy_file:
384
401
  callback_after_copy_file(src_file_path, dst_abs_file_path)
402
+ return should_sync
385
403
 
386
404
 
387
405
  def smart_sync(
@@ -392,9 +410,10 @@ def smart_sync(
392
410
  callback_after_copy_file: Optional[Callable[[str, str], None]] = None,
393
411
  src_file_stats: Optional[Iterable[FileEntry]] = None,
394
412
  map_func: Callable[[Callable, Iterable], Any] = map,
395
- force: bool = False) -> None:
413
+ force: bool = False,
414
+ overwrite: bool = True) -> None:
396
415
  '''
397
- Sync file or directory on s3 and fs
416
+ Sync file or directory
398
417
 
399
418
  .. note ::
400
419
 
@@ -437,6 +456,8 @@ def smart_sync(
437
456
  This parameter is in order to reduce file traversal times.
438
457
  :param map_func: A Callable func like `map`. You can use ThreadPoolExecutor.map, Pool.map and so on if you need concurrent capability.
439
458
  default is standard library `map`.
459
+ :param force: Sync file forcely, do not ignore same files, priority is higher than 'overwrite', default is False
460
+ :param overwrite: whether or not overwrite file when exists, default is True
440
461
  '''
441
462
  if not smart_exists(src_path):
442
463
  raise FileNotFoundError(f'No match file: {src_path}')
@@ -458,6 +479,7 @@ def smart_sync(
458
479
  followlinks=followlinks,
459
480
  callback_after_copy_file=callback_after_copy_file,
460
481
  force=force,
482
+ overwrite=overwrite,
461
483
  )
462
484
 
463
485
  for _ in map_func(_smart_sync_single_file, create_generator()):
@@ -470,7 +492,24 @@ def smart_sync_with_progress(
470
492
  callback: Optional[Callable[[str, int], None]] = None,
471
493
  followlinks: bool = False,
472
494
  map_func: Callable[[Callable, Iterable], Iterator] = map,
473
- force: bool = False):
495
+ force: bool = False,
496
+ overwrite: bool = True):
497
+ '''
498
+ Sync file or directory with progress bar
499
+
500
+ :param src_path: Given source path
501
+ :param dst_path: Given destination path
502
+ :param callback: Called periodically during copy, and the input parameter is the data size (in bytes) of copy since the last call
503
+ :param followlinks: False if regard symlink as file, else True
504
+ :param callback_after_copy_file: Called after copy success, and the input parameter is src file path and dst file path
505
+ :param src_file_stats: If this parameter is not None, only this parameter's files will be synced,
506
+ and src_path is the root_path of these files used to calculate the path of the target file.
507
+ This parameter is in order to reduce file traversal times.
508
+ :param map_func: A Callable func like `map`. You can use ThreadPoolExecutor.map, Pool.map and so on if you need concurrent capability.
509
+ default is standard library `map`.
510
+ :param force: Sync file forcely, do not ignore same files, priority is higher than 'overwrite', default is False
511
+ :param overwrite: whether or not overwrite file when exists, default is True
512
+ '''
474
513
  if not smart_exists(src_path):
475
514
  raise FileNotFoundError(f'No match file: {src_path}')
476
515
 
@@ -497,6 +536,7 @@ def smart_sync_with_progress(
497
536
  src_file_stats=file_stats,
498
537
  map_func=map_func,
499
538
  force=force,
539
+ overwrite=overwrite,
500
540
  )
501
541
  tbar.close()
502
542
  sbar.close()
@@ -513,37 +553,41 @@ def smart_remove(path: PathLike, missing_ok: bool = False) -> None:
513
553
  SmartPath(path).remove(missing_ok=missing_ok)
514
554
 
515
555
 
516
- def smart_rename(src_path: PathLike, dst_path: PathLike) -> None:
556
+ def smart_rename(
557
+ src_path: PathLike, dst_path: PathLike, overwrite: bool = True) -> None:
517
558
  '''
518
559
  Move file on s3 or fs. `s3://` or `s3://bucket` is not allowed to move
519
560
 
520
561
  :param src_path: Given source path
521
562
  :param dst_path: Given destination path
563
+ :param overwrite: whether or not overwrite file when exists
522
564
  '''
523
565
  if smart_isdir(src_path):
524
566
  raise IsADirectoryError('%r is a directory' % src_path)
525
567
  src_protocol, _ = SmartPath._extract_protocol(src_path)
526
568
  dst_protocol, _ = SmartPath._extract_protocol(dst_path)
527
569
  if src_protocol == dst_protocol:
528
- SmartPath(src_path).rename(dst_path)
570
+ SmartPath(src_path).rename(dst_path, overwrite=overwrite)
529
571
  return
530
- smart_copy(src_path, dst_path)
572
+ smart_copy(src_path, dst_path, overwrite=overwrite)
531
573
  smart_unlink(src_path)
532
574
 
533
575
 
534
- def smart_move(src_path: PathLike, dst_path: PathLike) -> None:
576
+ def smart_move(
577
+ src_path: PathLike, dst_path: PathLike, overwrite: bool = True) -> None:
535
578
  '''
536
579
  Move file/directory on s3 or fs. `s3://` or `s3://bucket` is not allowed to move
537
580
 
538
581
  :param src_path: Given source path
539
582
  :param dst_path: Given destination path
583
+ :param overwrite: whether or not overwrite file when exists
540
584
  '''
541
585
  src_protocol, _ = SmartPath._extract_protocol(src_path)
542
586
  dst_protocol, _ = SmartPath._extract_protocol(dst_path)
543
587
  if src_protocol == dst_protocol:
544
- SmartPath(src_path).rename(dst_path)
588
+ SmartPath(src_path).rename(dst_path, overwrite=overwrite)
545
589
  return
546
- smart_sync(src_path, dst_path, followlinks=True)
590
+ smart_sync(src_path, dst_path, followlinks=True, overwrite=overwrite)
547
591
  smart_remove(src_path)
548
592
 
549
593
 
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "3.0.5"
1
+ VERSION = "3.0.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: megfile
3
- Version: 3.0.5
3
+ Version: 3.0.6
4
4
  Summary: Megvii file operation library
5
5
  Home-page: https://github.com/megvii-research/megfile
6
6
  Author: megvii
@@ -1,24 +1,24 @@
1
1
  megfile/__init__.py,sha256=MT8SIXsmEUvtSpd1GHv6e3fFfR1gRnlEdkNNqv3gngo,6534
2
- megfile/cli.py,sha256=yB2VnSaxrjNS67KL6CYRaMo72VNgyvuxCXuSfcGu6hM,21880
2
+ megfile/cli.py,sha256=vPrFVWVx1iQOzv6QE1BChix5pCpbzkiGlB2S4eBW8gM,22445
3
3
  megfile/config.py,sha256=YeLuxsFoJz6ZmZq7Pufe_021PeRWs4H6GN-v0MvsV6E,1136
4
- megfile/errors.py,sha256=SXaFhPj7Prgt0Zp904g949aP225rngThDho1JAEXI7U,13571
5
- megfile/fs.py,sha256=OfY0z4GSl8fT3mDGdeqP2hWFsd1QJl-h8RkSbg6-M8I,11547
6
- megfile/fs_path.py,sha256=sHn-sBcvq7SvYN71onkA_ssLs71NzM1MM3d3Sug8uzo,38237
7
- megfile/hdfs.py,sha256=aAkHobOO0nDcLoqj0tx_1tvgoLOCooTWuukq0pO-nQA,9156
8
- megfile/hdfs_path.py,sha256=obfMMKSuBcSGgtEN18jXhEldm4hawMhxk8QoRv4k790,26859
4
+ megfile/errors.py,sha256=jVkQAv3XAmAxh2l2gGc5wptNsx61uGCHwX02ugQynns,13733
5
+ megfile/fs.py,sha256=xLVSS4VWp2xcA7-vlVPbgJBG6s0zxH3JGaINwd9x57U,11850
6
+ megfile/fs_path.py,sha256=2GbJYB4qbRhThWedM7VgbhjaNTKCENYUfsPBFp9JGfU,40651
7
+ megfile/hdfs.py,sha256=9kEf6b-TVy6I3B_j5jufODzjNA5ngdTqW_mEForGFas,9200
8
+ megfile/hdfs_path.py,sha256=iQGIS81PhV7bl9xAZkV14WjCp7O9Fb9yz12RfL2Z41w,27402
9
9
  megfile/http.py,sha256=a3oAuARSSaIU8VMx86Mui0N5Vh-EI0AoHnwxRU5DSMU,2032
10
- megfile/http_path.py,sha256=moBUIJmAeOKshi8AVm4OAyk9lGWM4HzOrH5BNFeqc1o,15466
10
+ megfile/http_path.py,sha256=nCMx_8ETZynfDbNOnNkwY8vzHzCnFCx_H33PHVJQlug,16261
11
11
  megfile/interfaces.py,sha256=h3tWE8hVt5S-HopaMAX6lunPJ97vzhv6jH_2HubcDNc,6219
12
- megfile/pathlike.py,sha256=Ere6tMf2nsI7bDsZo0WBzl_2HRrS_4iKOpYp0zZltAU,29487
13
- megfile/s3.py,sha256=siBZfveWX1TDA4Mp41UvugcG3zlrhl_iPUbixUp1TmI,12352
14
- megfile/s3_path.py,sha256=Bj1U70pCiVoikf-FcC5Z2hbcV177Qo7n5plnt5K44uE,91341
15
- megfile/sftp.py,sha256=JCkF2v1ZbHuIy_Bg3l85AesjFDimDzx9Gh1gRoMsahc,12524
16
- megfile/sftp_path.py,sha256=Fe6yMiolhiAOdvpnT1DeixtLludhsGTKwvAo9yk3SZc,51732
17
- megfile/smart.py,sha256=y5Dzr7_f0jS2FJDF4tWbEO4SPf39zqYftqkVgMhiJds,33725
12
+ megfile/pathlike.py,sha256=JhSP_bxRI7bwVGkubVvIkAqSYDcxdJr9h1DfZXEgc-g,29785
13
+ megfile/s3.py,sha256=RmfUsmMVUD9-7A_O2d55dHBZ8_QX2FiFV4QAd_a1DZs,12830
14
+ megfile/s3_path.py,sha256=S0rsYibPxcLOTOnz3nBS4OmsPcbL23570UsrN4NrJrM,92664
15
+ megfile/sftp.py,sha256=dp0x84RYnxEX43NNIHqNZBCd69HgPqVg0EZPKT6vsCg,12978
16
+ megfile/sftp_path.py,sha256=B_uOcKBdhZaYKh7mTieY1v-cvAheixrE3UFhA_JF6Z0,53253
17
+ megfile/smart.py,sha256=vnm1sgxYShPSMVUl0qbVFnXu7I8NgCLHcxAXyPxXRr8,35967
18
18
  megfile/smart_path.py,sha256=Y0UFh4J2ccydRY2W-wX2ubaf9zzJx1M2nf-VLBGe4mk,6749
19
19
  megfile/stdio.py,sha256=yRhlfUA2DHi3bq-9cXsSlbLCnHvS_zvglO2IYYyPsGc,707
20
20
  megfile/stdio_path.py,sha256=eQulTXUwHvUKA-5PKCGfVNiEPkJhG9YtVhtU58OcmoM,2873
21
- megfile/version.py,sha256=GG6OWfWAjPQ5lWwRUMjdZhwT0vYC3rWZeMCsigOCJXA,19
21
+ megfile/version.py,sha256=aH_mbFf1JWAamOobRndDlivMY_OR5K3g0b3oshnbkyc,19
22
22
  megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  megfile/lib/base_prefetch_reader.py,sha256=rrHB9FdVX_MKOJD2lGZ00LruTjRY9u0Hj4UdI-CxNO0,13231
24
24
  megfile/lib/combine_reader.py,sha256=XFSqEY5A5X5Uf7eQ6AXAzrvNteESSXvKNVPktGjo3KY,4546
@@ -28,7 +28,7 @@ megfile/lib/fnmatch.py,sha256=HgdlnEWBsdFUOZqnW_v1kj1jeH_9lMcCqW85pyMu4vM,4054
28
28
  megfile/lib/glob.py,sha256=7i9dIput9rI9JIPyTZX-JDmFS7IP_THlX1k-35foAfw,9732
29
29
  megfile/lib/hdfs_prefetch_reader.py,sha256=50oVBNmEB8KRNwHnyDzxpxvwNABWxbOaIjyiTkmcemU,2080
30
30
  megfile/lib/hdfs_tools.py,sha256=t4GeoBxO0HPahIQDrsK17WBsLZtcfAaNwWfappzZ5q8,442
31
- megfile/lib/http_prefetch_reader.py,sha256=nD1EN5OmdC7yaL60TC0PA1He48OA8FSH90xDQl3T98E,3392
31
+ megfile/lib/http_prefetch_reader.py,sha256=1F94fFY7ZtyP7Bm9Wphu0iLtvOt771rehhouflqVojk,4328
32
32
  megfile/lib/joinpath.py,sha256=D4Px6-lnDDpYs1LMUHkTIGqMPJQ0oCBGfTzREs373iU,929
33
33
  megfile/lib/lazy_handler.py,sha256=f1rip2_T57vVo0WRNXve2bAa4LArvVheMfQg1S0vFzg,1915
34
34
  megfile/lib/s3_buffered_writer.py,sha256=ZvCtaJsGZdFy-8K6EMHFakzu3oIKXnKof-a6nBa6AY4,7017
@@ -43,10 +43,10 @@ megfile/lib/stdio_handler.py,sha256=QDWtcZxz-hzi-rqQUiSlR3NrihX1fjK_Rj9T2mdTFEg,
43
43
  megfile/lib/url.py,sha256=VbQLjo0s4AaV0iSk66BcjI68aUTcN9zBZ5x6-cM4Qvs,103
44
44
  megfile/utils/__init__.py,sha256=xrBIJcVJTb_yR68ekAyd9u4HQ46s3xgIjUZoH_Lx7hU,9531
45
45
  megfile/utils/mutex.py,sha256=-2KH3bNovKRd9zvsXq9n3bWM7rQdoG9hO7tUPxVG_Po,2538
46
- megfile-3.0.5.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
- megfile-3.0.5.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
- megfile-3.0.5.dist-info/METADATA,sha256=vE3zfEswG2nEZ37V493PCznwEdsGg90C7Zq-sVdytg0,8963
49
- megfile-3.0.5.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
50
- megfile-3.0.5.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
- megfile-3.0.5.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
- megfile-3.0.5.dist-info/RECORD,,
46
+ megfile-3.0.6.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
+ megfile-3.0.6.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
+ megfile-3.0.6.dist-info/METADATA,sha256=GyU4MB9acbaLDMV5LS7gYt9p0py0yIn3bk13g-A38xs,8963
49
+ megfile-3.0.6.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
50
+ megfile-3.0.6.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
+ megfile-3.0.6.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
+ megfile-3.0.6.dist-info/RECORD,,