megfile 3.0.0.post1__py3-none-any.whl → 3.0.2__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 CHANGED
@@ -104,8 +104,10 @@ def _ls(path: str, long: bool, recursive: bool, human_readable: bool):
104
104
  echo_func = simple_echo
105
105
 
106
106
  total_size = 0
107
+ total_count = 0
107
108
  for file_stat in scan_func(path):
108
109
  total_size += file_stat.stat.size
110
+ total_count += 1
109
111
  output = echo_func(file_stat, base_path, full_path=full_path)
110
112
  if file_stat.is_symlink():
111
113
  try:
@@ -115,7 +117,7 @@ def _ls(path: str, long: bool, recursive: bool, human_readable: bool):
115
117
  output += ' -> %s' % link
116
118
  click.echo(output)
117
119
  if long:
118
- click.echo(f'total: {get_human_size(total_size)}')
120
+ click.echo(f'total({total_count}): {get_human_size(total_size)}')
119
121
 
120
122
 
121
123
  @cli.command(short_help='List all the objects in the path.')
@@ -441,7 +443,12 @@ def head(path: str, lines: int):
441
443
  type=click.INT,
442
444
  default=10,
443
445
  help='print the last NUM lines')
444
- def tail(path: str, lines: int):
446
+ @click.option(
447
+ '-f',
448
+ '--follow',
449
+ is_flag=True,
450
+ help='output appended data as the file grows')
451
+ def tail(path: str, lines: int, follow: bool):
445
452
  line_list = []
446
453
  with smart_open(path, 'rb') as f:
447
454
  f.seek(0, os.SEEK_END)
@@ -462,8 +469,23 @@ def tail(path: str, lines: int):
462
469
  break
463
470
  else:
464
471
  line_list = block_lines
465
- for line in line_list:
472
+
473
+ for line in line_list[:-1]:
466
474
  click.echo(line)
475
+ if line_list:
476
+ click.echo(line_list[-1], nl=False)
477
+
478
+ if follow:
479
+ offset = file_size
480
+ while True:
481
+ with smart_open(path, 'rb') as f:
482
+ f.seek(offset)
483
+ line = f.readline()
484
+ offset = f.tell()
485
+ if not line:
486
+ time.sleep(1)
487
+ continue
488
+ click.echo(line, nl=False)
467
489
 
468
490
 
469
491
  @cli.command(short_help='Write bytes from stdin to file.')
megfile/sftp_path.py CHANGED
@@ -105,8 +105,13 @@ def sftp_should_retry(error: Exception) -> bool:
105
105
  socket.timeout,
106
106
  )):
107
107
  return True
108
- elif isinstance(error, OSError) and str(error) == 'Socket is closed':
109
- return True
108
+ elif isinstance(error, OSError):
109
+ for err_msg in [
110
+ 'Socket is closed',
111
+ 'Cannot assign requested address',
112
+ ]:
113
+ if err_msg in str(error):
114
+ return True
110
115
  return False
111
116
 
112
117
 
@@ -1117,6 +1122,8 @@ class SftpPath(URIPath):
1117
1122
  if not self.is_symlink():
1118
1123
  raise OSError('Not a symlink: %s' % self.path_with_protocol)
1119
1124
  path = self._client.readlink(self._real_path)
1125
+ if not path:
1126
+ raise OSError('Not a symlink: %s' % self.path_with_protocol)
1120
1127
  if not path.startswith('/'):
1121
1128
  return self.parent.joinpath(path)
1122
1129
  return self._generate_path_object(path)
megfile/smart.py CHANGED
@@ -7,7 +7,7 @@ from typing import IO, Any, AnyStr, BinaryIO, Callable, Iterable, Iterator, List
7
7
 
8
8
  from tqdm import tqdm
9
9
 
10
- from megfile.errors import SameFileError
10
+ from megfile.errors import S3UnknownError
11
11
  from megfile.fs import fs_copy, is_fs
12
12
  from megfile.interfaces import Access, ContextIterator, FileCacher, FileEntry, NullCacher, PathLike, StatResult
13
13
  from megfile.lib.combine_reader import CombineReader
@@ -331,9 +331,17 @@ def smart_copy(
331
331
  copy_func = _copy_funcs[src_protocol][dst_protocol]
332
332
  except KeyError:
333
333
  copy_func = _default_copy_func
334
- copy_func(
335
- src_path, dst_path, callback=callback,
336
- followlinks=followlinks) # type: ignore
334
+ try:
335
+ copy_func(
336
+ src_path, dst_path, callback=callback,
337
+ followlinks=followlinks) # type: ignore
338
+ except S3UnknownError as e:
339
+ if 'cannot schedule new futures after interpreter shutdown' in str(e):
340
+ _default_copy_func(
341
+ src_path, dst_path, callback=callback,
342
+ followlinks=followlinks) # type: ignore
343
+ else:
344
+ raise
337
345
 
338
346
 
339
347
  def _smart_sync_single_file(items: dict):
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "3.0.0.post1"
1
+ VERSION = "3.0.2"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: megfile
3
- Version: 3.0.0.post1
3
+ Version: 3.0.2
4
4
  Summary: Megvii file operation library
5
5
  Home-page: https://github.com/megvii-research/megfile
6
6
  Author: megvii
@@ -1,5 +1,5 @@
1
1
  megfile/__init__.py,sha256=MT8SIXsmEUvtSpd1GHv6e3fFfR1gRnlEdkNNqv3gngo,6534
2
- megfile/cli.py,sha256=yaECF7bn-_QjeK6MLnZgvgJjIHcUIQrrKVl_JaxOEDo,21283
2
+ megfile/cli.py,sha256=yB2VnSaxrjNS67KL6CYRaMo72VNgyvuxCXuSfcGu6hM,21880
3
3
  megfile/config.py,sha256=Mz91CpRJJtepidOPXs98wYskmbbHRByG1VCeKJ81kVg,658
4
4
  megfile/errors.py,sha256=Sbx3UEKnzuyUmB1tFU9cZv61Yr4dRa79J6D0UMmkvj4,13323
5
5
  megfile/fs.py,sha256=OfY0z4GSl8fT3mDGdeqP2hWFsd1QJl-h8RkSbg6-M8I,11547
@@ -13,12 +13,12 @@ megfile/pathlike.py,sha256=Ere6tMf2nsI7bDsZo0WBzl_2HRrS_4iKOpYp0zZltAU,29487
13
13
  megfile/s3.py,sha256=siBZfveWX1TDA4Mp41UvugcG3zlrhl_iPUbixUp1TmI,12352
14
14
  megfile/s3_path.py,sha256=FYGjifwbhfraWZKKGRcuRAyllJwFcv_H1wjN5kYGzcw,90791
15
15
  megfile/sftp.py,sha256=JCkF2v1ZbHuIy_Bg3l85AesjFDimDzx9Gh1gRoMsahc,12524
16
- megfile/sftp_path.py,sha256=L26usr4jHhjxzAfNRoguxm3J8JNNaFWyrRYG2W7zCk0,51440
17
- megfile/smart.py,sha256=YoRvxEaZ_C-A5gQlFEs4sGBJ6D26s0qYEBJEcny_jBg,33416
16
+ megfile/sftp_path.py,sha256=ErPKmwgaCOvvhp3aKhqX9WKIAGbWR30QUWvptQWtag8,51666
17
+ megfile/smart.py,sha256=y5Dzr7_f0jS2FJDF4tWbEO4SPf39zqYftqkVgMhiJds,33725
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=kMj-Zcr5CPQqqnyAXYysUF5loOzPHPIw9kUQCBiOepA,25
21
+ megfile/version.py,sha256=HGcItPfK5-rkjDD8Y1bmaADbd3qo7wyXrM39-uif4RY,19
22
22
  megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  megfile/lib/base_prefetch_reader.py,sha256=9HT0tcgXa95BdbyclpDEDw8WwKi6091GRQerS90-pjE,13191
24
24
  megfile/lib/combine_reader.py,sha256=XFSqEY5A5X5Uf7eQ6AXAzrvNteESSXvKNVPktGjo3KY,4546
@@ -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=qdX8FF_dYFKwp1BIWx3JeSGd91s7AKUDSEpDv9tORcM,9162
45
45
  megfile/utils/mutex.py,sha256=-2KH3bNovKRd9zvsXq9n3bWM7rQdoG9hO7tUPxVG_Po,2538
46
- megfile-3.0.0.post1.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
- megfile-3.0.0.post1.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
- megfile-3.0.0.post1.dist-info/METADATA,sha256=8JE1q74gWq4onYy2ws28_CiXNsNHdRgS0_bf4TQvky8,8922
49
- megfile-3.0.0.post1.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
50
- megfile-3.0.0.post1.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
- megfile-3.0.0.post1.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
- megfile-3.0.0.post1.dist-info/RECORD,,
46
+ megfile-3.0.2.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
47
+ megfile-3.0.2.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
48
+ megfile-3.0.2.dist-info/METADATA,sha256=DnkmGRjSQJP0v3CgkHNwp7th5pKwJcF7qyKUN1tKaDs,8916
49
+ megfile-3.0.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
50
+ megfile-3.0.2.dist-info/entry_points.txt,sha256=M6ZWSSv5_5_QtIpZafy3vq7WuOJ_5dSGQQnEZbByt2Q,49
51
+ megfile-3.0.2.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
52
+ megfile-3.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.41.2)
2
+ Generator: bdist_wheel (0.42.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5