megfile 3.0.4__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/cli.py +21 -10
- megfile/config.py +9 -0
- megfile/errors.py +37 -21
- megfile/fs.py +9 -5
- megfile/fs_path.py +72 -15
- megfile/hdfs.py +3 -2
- megfile/hdfs_path.py +16 -6
- megfile/http_path.py +151 -22
- megfile/lib/base_prefetch_reader.py +2 -2
- megfile/lib/hdfs_prefetch_reader.py +2 -2
- megfile/lib/http_prefetch_reader.py +28 -12
- megfile/lib/s3_prefetch_reader.py +2 -2
- megfile/lib/s3_share_cache_reader.py +2 -2
- megfile/pathlike.py +10 -3
- megfile/s3.py +14 -7
- megfile/s3_path.py +57 -27
- megfile/sftp.py +18 -9
- megfile/sftp_path.py +63 -31
- megfile/smart.py +60 -16
- megfile/version.py +1 -1
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/METADATA +1 -1
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/RECORD +27 -27
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/LICENSE +0 -0
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/LICENSE.pyre +0 -0
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/WHEEL +0 -0
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/entry_points.txt +0 -0
- {megfile-3.0.4.dist-info → megfile-3.0.6.dist-info}/top_level.txt +0 -0
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
|
|
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
|
|
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,
|
|
337
|
-
|
|
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,
|
|
342
|
-
|
|
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
|
|
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
|
|
413
|
+
force: bool = False,
|
|
414
|
+
overwrite: bool = True) -> None:
|
|
396
415
|
'''
|
|
397
|
-
Sync file or directory
|
|
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(
|
|
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(
|
|
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.
|
|
1
|
+
VERSION = "3.0.6"
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
megfile/__init__.py,sha256=MT8SIXsmEUvtSpd1GHv6e3fFfR1gRnlEdkNNqv3gngo,6534
|
|
2
|
-
megfile/cli.py,sha256=
|
|
3
|
-
megfile/config.py,sha256=
|
|
4
|
-
megfile/errors.py,sha256=
|
|
5
|
-
megfile/fs.py,sha256=
|
|
6
|
-
megfile/fs_path.py,sha256=
|
|
7
|
-
megfile/hdfs.py,sha256=
|
|
8
|
-
megfile/hdfs_path.py,sha256=
|
|
2
|
+
megfile/cli.py,sha256=vPrFVWVx1iQOzv6QE1BChix5pCpbzkiGlB2S4eBW8gM,22445
|
|
3
|
+
megfile/config.py,sha256=YeLuxsFoJz6ZmZq7Pufe_021PeRWs4H6GN-v0MvsV6E,1136
|
|
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=
|
|
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=
|
|
13
|
-
megfile/s3.py,sha256=
|
|
14
|
-
megfile/s3_path.py,sha256=
|
|
15
|
-
megfile/sftp.py,sha256=
|
|
16
|
-
megfile/sftp_path.py,sha256=
|
|
17
|
-
megfile/smart.py,sha256=
|
|
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=
|
|
21
|
+
megfile/version.py,sha256=aH_mbFf1JWAamOobRndDlivMY_OR5K3g0b3oshnbkyc,19
|
|
22
22
|
megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
|
-
megfile/lib/base_prefetch_reader.py,sha256=
|
|
23
|
+
megfile/lib/base_prefetch_reader.py,sha256=rrHB9FdVX_MKOJD2lGZ00LruTjRY9u0Hj4UdI-CxNO0,13231
|
|
24
24
|
megfile/lib/combine_reader.py,sha256=XFSqEY5A5X5Uf7eQ6AXAzrvNteESSXvKNVPktGjo3KY,4546
|
|
25
25
|
megfile/lib/compare.py,sha256=yG2fZve_gMg32rQVCdwixBdqgYRsjn-24TqhALQaOrA,2233
|
|
26
26
|
megfile/lib/compat.py,sha256=0wt3_atcYhSLCxUj_WuDlQa3E1atjZfwJQ12thiFh5Q,234
|
|
27
27
|
megfile/lib/fnmatch.py,sha256=HgdlnEWBsdFUOZqnW_v1kj1jeH_9lMcCqW85pyMu4vM,4054
|
|
28
28
|
megfile/lib/glob.py,sha256=7i9dIput9rI9JIPyTZX-JDmFS7IP_THlX1k-35foAfw,9732
|
|
29
|
-
megfile/lib/hdfs_prefetch_reader.py,sha256=
|
|
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=
|
|
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
|
|
@@ -36,17 +36,17 @@ megfile/lib/s3_cached_handler.py,sha256=xuWiThi6pJtGL_ErSBmcu8rDv1XyXNmEhiFBnRF4
|
|
|
36
36
|
megfile/lib/s3_limited_seekable_writer.py,sha256=14gySEdbS349hpSdUcX5uvRr93HACv7BRZbgIki4b34,6150
|
|
37
37
|
megfile/lib/s3_memory_handler.py,sha256=6Tj89xzc8z-FycVggGpjF_8lEbPsqRVB6undZwWsugo,3971
|
|
38
38
|
megfile/lib/s3_pipe_handler.py,sha256=hG8sEajO9dv9bLTeXsERxDioHHhzi4t8NC61lSbYk94,3557
|
|
39
|
-
megfile/lib/s3_prefetch_reader.py,sha256=
|
|
40
|
-
megfile/lib/s3_share_cache_reader.py,sha256=
|
|
39
|
+
megfile/lib/s3_prefetch_reader.py,sha256=iLvPaJGlJHaZ6jcyNPf-8A8URJgoJ0RN0C1YD--6wZ4,4285
|
|
40
|
+
megfile/lib/s3_share_cache_reader.py,sha256=jyx6f3LAR05qtf-qq_RTu8wE6wqTrqg4qkwWRSdPGQ4,3600
|
|
41
41
|
megfile/lib/shadow_handler.py,sha256=IbFyTw107t-yWH0cGrDjAJX-CS3xeEr77_PTGsnSgk4,2683
|
|
42
42
|
megfile/lib/stdio_handler.py,sha256=QDWtcZxz-hzi-rqQUiSlR3NrihX1fjK_Rj9T2mdTFEg,2044
|
|
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.
|
|
47
|
-
megfile-3.0.
|
|
48
|
-
megfile-3.0.
|
|
49
|
-
megfile-3.0.
|
|
50
|
-
megfile-3.0.
|
|
51
|
-
megfile-3.0.
|
|
52
|
-
megfile-3.0.
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|