megfile 2.0.4.post3__py3-none-any.whl → 2.0.5__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
@@ -15,7 +15,8 @@ from megfile.smart_path import SmartPath
15
15
  from megfile.utils import get_human_size
16
16
  from megfile.version import VERSION
17
17
 
18
- logging.basicConfig(level=logging.INFO)
18
+ logging.basicConfig(level=logging.ERROR)
19
+ logging.getLogger('megfile').setLevel(level=logging.INFO)
19
20
 
20
21
 
21
22
  @click.group()
@@ -122,7 +123,7 @@ def cp(
122
123
  no_target_directory: bool,
123
124
  progress_bar: bool,
124
125
  ):
125
- if smart_isdir(dst_path) and not no_target_directory:
126
+ if not no_target_directory and smart_isdir(dst_path):
126
127
  dst_path = smart_path_join(dst_path, os.path.basename(src_path))
127
128
  if recursive:
128
129
  with ThreadPoolExecutor(max_workers=(os.cpu_count() or 1) *
megfile/s3_path.py CHANGED
@@ -130,6 +130,11 @@ def get_scoped_config(profile_name: Optional[str] = None) -> Dict:
130
130
  profile_name=profile_name)._session.get_scoped_config()
131
131
 
132
132
 
133
+ @lru_cache()
134
+ def warning_endpoint_url(key: str, endpoint_url: str):
135
+ _logger.info("using %s: %s" % (key, endpoint_url))
136
+
137
+
133
138
  def get_endpoint_url(profile_name: Optional[str] = None) -> str:
134
139
  '''Get the endpoint url of S3
135
140
 
@@ -139,14 +144,13 @@ def get_endpoint_url(profile_name: Optional[str] = None) -> str:
139
144
  ) if profile_name else 'OSS_ENDPOINT'
140
145
  environ_endpoint_url = os.environ.get(environ_key)
141
146
  if environ_endpoint_url:
142
- _logger.info("using %s: %s" % (environ_key, environ_endpoint_url))
147
+ warning_endpoint_url(environ_key, environ_endpoint_url)
143
148
  return environ_endpoint_url
144
149
  try:
145
150
  config_endpoint_url = get_scoped_config(profile_name=profile_name).get(
146
151
  's3', {}).get('endpoint_url')
147
152
  if config_endpoint_url:
148
- _logger.info(
149
- "using ~/.aws/config: endpoint_url=%s" % config_endpoint_url)
153
+ warning_endpoint_url('~/.aws/config', config_endpoint_url)
150
154
  return config_endpoint_url
151
155
  except botocore.exceptions.ProfileNotFound: # pragma: no cover
152
156
  pass
@@ -1223,7 +1227,10 @@ class S3Path(URIPath):
1223
1227
  resp = self._client.head_object(Bucket=bucket, Key=key)
1224
1228
  return dict(
1225
1229
  (key.lower(), value) for key, value in resp['Metadata'].items())
1226
- except Exception:
1230
+ except Exception as error:
1231
+ if isinstance(error,
1232
+ (S3UnknownError, S3ConfigError, S3PermissionError)):
1233
+ raise error
1227
1234
  return {}
1228
1235
 
1229
1236
  def access(
@@ -1403,7 +1410,8 @@ class S3Path(URIPath):
1403
1410
  Bucket=bucket, Prefix=prefix, Delimiter='/', MaxKeys=1)
1404
1411
  except Exception as error:
1405
1412
  error = translate_s3_error(error, self.path_with_protocol)
1406
- if isinstance(error, (S3UnknownError, S3ConfigError)):
1413
+ if isinstance(error,
1414
+ (S3UnknownError, S3ConfigError, S3PermissionError)):
1407
1415
  raise error
1408
1416
  return False
1409
1417
 
@@ -1436,7 +1444,8 @@ class S3Path(URIPath):
1436
1444
  self._client.head_object(Bucket=bucket, Key=key)
1437
1445
  except Exception as error:
1438
1446
  error = translate_s3_error(error, s3_url)
1439
- if isinstance(error, (S3UnknownError, S3ConfigError)):
1447
+ if isinstance(error,
1448
+ (S3UnknownError, S3ConfigError, S3PermissionError)):
1440
1449
  raise error
1441
1450
  return False
1442
1451
  return True
@@ -1500,7 +1509,8 @@ class S3Path(URIPath):
1500
1509
  self._client.head_bucket(Bucket=bucket)
1501
1510
  except Exception as error:
1502
1511
  error = translate_s3_error(error, self.path_with_protocol)
1503
- if isinstance(error, (S3UnknownError, S3ConfigError)):
1512
+ if isinstance(error,
1513
+ (S3UnknownError, S3ConfigError, S3PermissionError)):
1504
1514
  raise error
1505
1515
  if isinstance(error, S3FileNotFoundError):
1506
1516
  return False
megfile/sftp_path.py CHANGED
@@ -2,6 +2,7 @@ import atexit
2
2
  import hashlib
3
3
  import io
4
4
  import os
5
+ import shlex
5
6
  import subprocess
6
7
  from functools import lru_cache
7
8
  from logging import getLogger as get_logger
@@ -497,9 +498,12 @@ class SftpPath(URIPath):
497
498
  :returns: True if the path is a directory, else False
498
499
 
499
500
  '''
500
- stat = self.stat(follow_symlinks=followlinks)
501
- if S_ISDIR(stat.st_mode):
502
- return True
501
+ try:
502
+ stat = self.stat(follow_symlinks=followlinks)
503
+ if S_ISDIR(stat.st_mode):
504
+ return True
505
+ except FileNotFoundError:
506
+ pass
503
507
  return False
504
508
 
505
509
  def is_file(self, followlinks: bool = False) -> bool:
@@ -514,9 +518,12 @@ class SftpPath(URIPath):
514
518
  :returns: True if the path is a file, else False
515
519
 
516
520
  '''
517
- stat = self.stat(follow_symlinks=followlinks)
518
- if S_ISREG(stat.st_mode):
519
- return True
521
+ try:
522
+ stat = self.stat(follow_symlinks=followlinks)
523
+ if S_ISREG(stat.st_mode):
524
+ return True
525
+ except FileNotFoundError:
526
+ pass
520
527
  return False
521
528
 
522
529
  def listdir(self) -> List[str]:
@@ -872,16 +879,13 @@ class SftpPath(URIPath):
872
879
 
873
880
  def open(self, mode: str = 'r', buffering=-1, **kwargs) -> IO[AnyStr]: # pytype: disable=signature-mismatch
874
881
  if 'w' in mode or 'x' in mode or 'a' in mode:
875
- try:
876
- if self.is_dir():
877
- raise IsADirectoryError(
878
- 'Is a directory: %r' % self.path_with_protocol)
879
- except FileNotFoundError:
880
- pass
882
+ if self.is_dir():
883
+ raise IsADirectoryError(
884
+ 'Is a directory: %r' % self.path_with_protocol)
881
885
  self.parent.mkdir(parents=True, exist_ok=True)
882
- elif not self.is_file():
883
- raise IsADirectoryError(
884
- 'Is a directory: %r' % self.path_with_protocol)
886
+ elif not self.exists():
887
+ raise FileNotFoundError(
888
+ 'No such file: %r' % self.path_with_protocol)
885
889
  fileobj = self._client.open(self._real_path, mode, bufsize=buffering)
886
890
  if 'r' in mode and 'b' not in mode:
887
891
  return io.TextIOWrapper(fileobj) # type: ignore
@@ -930,7 +934,7 @@ class SftpPath(URIPath):
930
934
  chan.settimeout(timeout)
931
935
  if environment:
932
936
  chan.update_environment(environment)
933
- chan.exec_command(" ".join(command))
937
+ chan.exec_command(' '.join(shlex.quote(arg) for arg in command))
934
938
  stdout = chan.makefile("r", bufsize)
935
939
  stderr = chan.makefile_stderr("r", bufsize)
936
940
  return subprocess.CompletedProcess(
megfile/version.py CHANGED
@@ -1 +1 @@
1
- VERSION = "2.0.4.post3"
1
+ VERSION = "2.0.5"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: megfile
3
- Version: 2.0.4.post3
3
+ Version: 2.0.5
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=wlijLJS6F8Vdm1xjpsjd9fKBeDGpgIMrVsXYSeOQ4Xw,5434
2
- megfile/cli.py,sha256=ky2o8F1NdEAkEfRmY-ZJo03IhVUG1RYCoBgMYehS_vQ,9974
2
+ megfile/cli.py,sha256=t299Wo9lA0EbZlS5k3tCxW19liCqY7-i7zbu8oHOwHo,10033
3
3
  megfile/errors.py,sha256=FE9mGMxnNFpsQdtNJWiL-BuZbPGbbx8es9eAo8osyio,11584
4
4
  megfile/fs.py,sha256=sjkm_LsvNCw8hj9Ee-1HSNzvg7bRHTPem8KTDDBQlCw,11621
5
5
  megfile/fs_path.py,sha256=xdMkmH0mVAWnP2yfhxudvfuI-7tEgCzk9CzbN08-8O4,37351
@@ -8,14 +8,14 @@ megfile/http_path.py,sha256=up1gB0Yk1a3ZbmHoJV-XWzOTiKh66hmm5p_Kzy3GMHo,4483
8
8
  megfile/interfaces.py,sha256=h3tWE8hVt5S-HopaMAX6lunPJ97vzhv6jH_2HubcDNc,6219
9
9
  megfile/pathlike.py,sha256=EKVSfr13IFYTyUIfkTxzli93UJXkxtTH3IXdv946DhE,28741
10
10
  megfile/s3.py,sha256=hlXqQvZuXuDJbLjsrK23LD25cblThO9f-r78eWFsYZ8,12456
11
- megfile/s3_path.py,sha256=zNSrEZaiED1uJaN6fwapXBrFnD2jQk-t0cMmxB9cABQ,84409
11
+ megfile/s3_path.py,sha256=WrKby1hDJPa8JGRWVggOWrakjvPtHlk6VmHMqlHkOiw,84774
12
12
  megfile/sftp.py,sha256=qzfgI-MGzNsr7adUQaiVKS7zRHGuK-Hs6o45wNIAcww,11943
13
- megfile/sftp_path.py,sha256=XxG_u-DhIREm99CF5Esh9HHSuVkK_YTHjaaOR1pGDfA,40243
13
+ megfile/sftp_path.py,sha256=1DH_we_ygn7oYc4S_uh-mXZjbXleWaZDnNINxzuNIU4,40345
14
14
  megfile/smart.py,sha256=InlLZHUCjSuUo9MYgEmz0Q_2UuFKiD5ckwH5oag2SBo,30484
15
15
  megfile/smart_path.py,sha256=OPFfRgv-wtdSgakt7eN01d3Sne4qGNe4_nL_9a4AyzA,6613
16
16
  megfile/stdio.py,sha256=qmi1c7VTll6Y6ya9MCd-dSKffocX2GafA-YUncZRU1Y,559
17
17
  megfile/stdio_path.py,sha256=77P-SEFy5EONViTe-J7gK8ID9VkfACLvB-7WXrWry6s,2672
18
- megfile/version.py,sha256=RehFieZTT6idWnbOgobMRSGluaaE4RJEm9-go097iIg,25
18
+ megfile/version.py,sha256=V8tafegt5EJPpw_OdTJ2xlmX0IbL6epFkgwbhD7aB-M,19
19
19
  megfile/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  megfile/lib/combine_reader.py,sha256=TkjvYvM5ZBVCh3tA7cOmTe8dYZc_eI7XbpPhnzqaNvU,4580
21
21
  megfile/lib/compat.py,sha256=ro07M9GU9hmqnSBu-IV13qKQQ9ktiMNDxaGGw9I9W3k,228
@@ -34,10 +34,10 @@ megfile/lib/shadow_handler.py,sha256=IbFyTw107t-yWH0cGrDjAJX-CS3xeEr77_PTGsnSgk4
34
34
  megfile/lib/stdio_handler.py,sha256=QDWtcZxz-hzi-rqQUiSlR3NrihX1fjK_Rj9T2mdTFEg,2044
35
35
  megfile/utils/__init__.py,sha256=gWplPIHzpSqV9AiQiRvUrBCkD737caNYyudsgwQBbKk,9025
36
36
  megfile/utils/mutex.py,sha256=BE16gbmZxr0RgU0ULaAFVDTZGwiOA-Jven-fDeG3ltQ,2461
37
- megfile-2.0.4.post3.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
38
- megfile-2.0.4.post3.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
39
- megfile-2.0.4.post3.dist-info/METADATA,sha256=wtFZYk0IBsgUhmBy6S8LVAtT6W6e9VjxwFEHNDSnPhk,10197
40
- megfile-2.0.4.post3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
41
- megfile-2.0.4.post3.dist-info/entry_points.txt,sha256=O8y31sCLdgUkNujumqaC4GDjJDOq55SJQ_uc7s1FeYw,50
42
- megfile-2.0.4.post3.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
43
- megfile-2.0.4.post3.dist-info/RECORD,,
37
+ megfile-2.0.5.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
38
+ megfile-2.0.5.dist-info/LICENSE.pyre,sha256=9lf5nT-5ZH25JijpYAequ0bl8E8z5JmZB1qrjiUMp84,1080
39
+ megfile-2.0.5.dist-info/METADATA,sha256=eXUyzBLc4ihdouSq74YpP8co_MyR55xQL8WLAzmSZn8,10191
40
+ megfile-2.0.5.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
41
+ megfile-2.0.5.dist-info/entry_points.txt,sha256=O8y31sCLdgUkNujumqaC4GDjJDOq55SJQ_uc7s1FeYw,50
42
+ megfile-2.0.5.dist-info/top_level.txt,sha256=i3rMgdU1ZAJekAceojhA-bkm3749PzshtRmLTbeLUPQ,8
43
+ megfile-2.0.5.dist-info/RECORD,,