rclone-api 1.3.6__py2.py3-none-any.whl → 1.3.7__py2.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.
rclone_api/__init__.py CHANGED
@@ -7,7 +7,7 @@ from .config import Config, Parsed, Section
7
7
  from .diff import DiffItem, DiffOption, DiffType
8
8
  from .dir import Dir
9
9
  from .dir_listing import DirListing
10
- from .file import File
10
+ from .file import File, FileItem
11
11
  from .filelist import FileList
12
12
 
13
13
  # Import the configure_logging function to make it available at package level
@@ -28,6 +28,7 @@ __all__ = [
28
28
  "RPath",
29
29
  "DirListing",
30
30
  "FileList",
31
+ "FileItem",
31
32
  "Process",
32
33
  "DiffItem",
33
34
  "DiffType",
rclone_api/file.py CHANGED
@@ -1,9 +1,46 @@
1
1
  import json
2
+ import warnings
3
+ from dataclasses import dataclass
2
4
  from pathlib import Path
3
5
 
4
6
  from rclone_api.rpath import RPath
5
7
 
6
8
 
9
+ # File is too complex, this is a simple dataclass that can be streamed out.
10
+ @dataclass
11
+ class FileItem:
12
+ """Remote file dataclass."""
13
+
14
+ path: str
15
+ name: str
16
+ size: int
17
+ mime_type: str
18
+ mod_time: str
19
+
20
+ @staticmethod
21
+ def from_json(data: dict) -> "FileItem | None":
22
+ try:
23
+ return FileItem(
24
+ data["Path"],
25
+ data["Name"],
26
+ data["Size"],
27
+ data["MimeType"],
28
+ data["ModTime"],
29
+ )
30
+ except KeyError:
31
+ warnings.warn(f"Invalid data: {data}")
32
+ return None
33
+
34
+ @staticmethod
35
+ def from_json_str(data: str) -> "FileItem | None":
36
+ try:
37
+ data_dict = json.loads(data)
38
+ return FileItem.from_json(data_dict)
39
+ except json.JSONDecodeError:
40
+ warnings.warn(f"Invalid JSON data: {data}")
41
+ return None
42
+
43
+
7
44
  class File:
8
45
  """Remote file dataclass."""
9
46
 
rclone_api/process.py CHANGED
@@ -72,6 +72,12 @@ class Process:
72
72
 
73
73
  atexit.register(exit_cleanup)
74
74
 
75
+ def __enter__(self) -> "Process":
76
+ return self
77
+
78
+ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
79
+ self.cleanup()
80
+
75
81
  def cleanup(self) -> None:
76
82
  if self.tempdir and self.needs_cleanup:
77
83
  try:
rclone_api/rclone.py CHANGED
@@ -24,7 +24,7 @@ from rclone_api.deprecated import deprecated
24
24
  from rclone_api.diff import DiffItem, DiffOption, diff_stream_from_running_process
25
25
  from rclone_api.dir_listing import DirListing
26
26
  from rclone_api.exec import RcloneExec
27
- from rclone_api.file import File
27
+ from rclone_api.file import File, FileItem
28
28
  from rclone_api.group_files import group_files
29
29
  from rclone_api.mount import Mount, clean_mount, prepare_mount
30
30
  from rclone_api.mount_read_chunker import MultiMountFileChunker
@@ -147,6 +147,34 @@ class Rclone:
147
147
  cp = self._run(cmd_list)
148
148
  return cp.stdout.strip()
149
149
 
150
+ def ls_stream_files(
151
+ self,
152
+ path: str,
153
+ max_depth: int = -1,
154
+ fast_list: bool = False,
155
+ ) -> Generator[FileItem, None, None]:
156
+ """List files in the given path"""
157
+ cmd = ["lsjson", path]
158
+ if max_depth < 0:
159
+ cmd.append("--recursive")
160
+ elif max_depth > 0:
161
+ cmd += ["--max-depth", str(max_depth)]
162
+ if fast_list:
163
+ cmd.append("--fast-list")
164
+ with self._launch_process(cmd, capture=True) as process:
165
+ for line in process.stdout:
166
+ linestr = line.decode("utf-8").strip()
167
+ if linestr.startswith("["):
168
+ continue
169
+ if linestr.endswith(","):
170
+ linestr = linestr[:-1]
171
+ if linestr.endswith("]"):
172
+ continue
173
+ fileitem: FileItem | None = FileItem.from_json_str(linestr)
174
+ if fileitem is None:
175
+ continue
176
+ yield fileitem
177
+
150
178
  def ls(
151
179
  self,
152
180
  path: Dir | Remote | str,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rclone_api
3
- Version: 1.3.6
3
+ Version: 1.3.7
4
4
  Summary: rclone api in python
5
5
  Home-page: https://github.com/zackees/rclone-api
6
6
  License: BSD 3-Clause License
@@ -1,4 +1,4 @@
1
- rclone_api/__init__.py,sha256=96hecpVEvaLklfaL5K_uBV-gaftt9kklC0XMlutZMf8,1197
1
+ rclone_api/__init__.py,sha256=bJ6x-7ySj1kC7xjQJqEEA-0cr46RUh_tvIZsebGcyu4,1224
2
2
  rclone_api/cli.py,sha256=dibfAZIh0kXWsBbfp3onKLjyZXo54mTzDjUdzJlDlWo,231
3
3
  rclone_api/completed_process.py,sha256=_IZ8IWK7DM1_tsbDEkH6wPZ-bbcrgf7A7smls854pmg,1775
4
4
  rclone_api/config.py,sha256=f6jEAxVorGFr31oHfcsu5AJTtOJj2wR5tTSsbGGZuIw,2558
@@ -8,14 +8,14 @@ rclone_api/diff.py,sha256=tMoJMAGmLSE6Q_7QhPf6PnCzb840djxMZtDmhc2GlGQ,5227
8
8
  rclone_api/dir.py,sha256=i4h7LX5hB_WmVixxDRWL_l1nifvscrdWct_8Wx7wHZc,3540
9
9
  rclone_api/dir_listing.py,sha256=GoziW8Sne6FY90MLNcb2aO3aaa3jphB6H8ExYrV0Ryo,1882
10
10
  rclone_api/exec.py,sha256=Bq0gkyZ10mEY0FRyzNZgdN4FaWP9vpeCk1kjpg-gN_8,1083
11
- rclone_api/file.py,sha256=EP5yT2dZ0H2p7CY5n0y5k5pHhIliV25pm8KOwBklUTk,1863
11
+ rclone_api/file.py,sha256=HdqzNpUKyOTGLb8XCgEMDAug5av5sEB3ieDow6MnPnk,2809
12
12
  rclone_api/filelist.py,sha256=xbiusvNgaB_b_kQOZoHMJJxn6TWGtPrWd2J042BI28o,767
13
13
  rclone_api/group_files.py,sha256=H92xPW9lQnbNw5KbtZCl00bD6iRh9yRbCuxku4j_3dg,8036
14
14
  rclone_api/log.py,sha256=VZHM7pNSXip2ZLBKMP7M1u-rp_F7zoafFDuR8CPUoKI,1271
15
15
  rclone_api/mount.py,sha256=TE_VIBMW7J1UkF_6HRCt8oi_jGdMov4S51bm2OgxFAM,10045
16
16
  rclone_api/mount_read_chunker.py,sha256=bi4N-VkyPdM4RWUYhIqJ71lQrXanck4PpF3pY8k2xnQ,4722
17
- rclone_api/process.py,sha256=rBj_S86jC6nqCYop-jq8r9eMSteKeObxUrJMgH8LZvI,5084
18
- rclone_api/rclone.py,sha256=mwHEkPhofQ6BAnE0x54W5E5kTb5pChxFa965DCxViJM,49175
17
+ rclone_api/process.py,sha256=xmI4T9i1tQfAy9lfwVU3w8sndkDkbM5KVUNWiKHCemY,5226
18
+ rclone_api/rclone.py,sha256=gL0b41BBedj23EmNJtZHpFI0_NGHbz2WT0PIq4KLZKg,50215
19
19
  rclone_api/remote.py,sha256=O9WDUFQy9f6oT1HdUbTixK2eg0xtBBm8k4Xl6aa6K00,431
20
20
  rclone_api/rpath.py,sha256=8ZA_1wxWtskwcy0I8V2VbjKDmzPkiWd8Q2JQSvh-sYE,2586
21
21
  rclone_api/scan_missing_folders.py,sha256=Kulca2Q6WZodt00ATFHkmqqInuoPvBkhTcS9703y6po,4740
@@ -35,9 +35,9 @@ rclone_api/s3/chunk_types.py,sha256=oSWv8No9V3BeM7IcGnowyR2a7YrszdAXzEJlxaeZcp0,
35
35
  rclone_api/s3/create.py,sha256=wgfkapv_j904CfKuWyiBIWJVxfAx_ftemFSUV14aT68,3149
36
36
  rclone_api/s3/types.py,sha256=Elmh__gvZJyJyElYwMmvYZIBIunDJiTRAbEg21GmsRU,1604
37
37
  rclone_api/s3/upload_file_multipart.py,sha256=d8ZWqO8n9wsqRF6JjmvAFmG1aCkFqdSB1L8yxe_5qiY,11669
38
- rclone_api-1.3.6.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
39
- rclone_api-1.3.6.dist-info/METADATA,sha256=SF9aoNhS9WW6bj-aESO1uOrKC29tmJCcZvjfJ-D4CZI,4536
40
- rclone_api-1.3.6.dist-info/WHEEL,sha256=rF4EZyR2XVS6irmOHQIJx2SUqXLZKRMUrjsg8UwN-XQ,109
41
- rclone_api-1.3.6.dist-info/entry_points.txt,sha256=TV8kwP3FRzYwUEr0RLC7aJh0W03SAefIJNXTJ-FdMIQ,200
42
- rclone_api-1.3.6.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
43
- rclone_api-1.3.6.dist-info/RECORD,,
38
+ rclone_api-1.3.7.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
39
+ rclone_api-1.3.7.dist-info/METADATA,sha256=OfqlMlZKb0YGl8hN6ae_Y1Icx2RKqlYj4UsMmcrAlEY,4536
40
+ rclone_api-1.3.7.dist-info/WHEEL,sha256=rF4EZyR2XVS6irmOHQIJx2SUqXLZKRMUrjsg8UwN-XQ,109
41
+ rclone_api-1.3.7.dist-info/entry_points.txt,sha256=TV8kwP3FRzYwUEr0RLC7aJh0W03SAefIJNXTJ-FdMIQ,200
42
+ rclone_api-1.3.7.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
43
+ rclone_api-1.3.7.dist-info/RECORD,,