rclone-api 1.0.7__py2.py3-none-any.whl → 1.0.8__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/dir.py CHANGED
@@ -8,10 +8,10 @@ class Dir:
8
8
  def __init__(self, path: RPath) -> None:
9
9
  self.path = path
10
10
 
11
- def ls(self) -> DirListing:
11
+ def ls(self, max_depth: int = 0) -> DirListing:
12
12
  """List files and directories in the given path."""
13
13
  assert self.path.rclone is not None
14
- return self.path.rclone.ls(self.path.path)
14
+ return self.path.rclone.ls(self.path.path, max_depth=max_depth)
15
15
 
16
16
  def __str__(self) -> str:
17
17
  return str(self.path)
rclone_api/walk.py ADDED
@@ -0,0 +1,82 @@
1
+ from concurrent.futures import ThreadPoolExecutor
2
+ from queue import Empty, Queue
3
+ from typing import Generator
4
+
5
+ from rclone_api import Dir
6
+ from rclone_api.dir_listing import DirListing
7
+
8
+
9
+ def walk(
10
+ dir: Dir, max_depth: int = -1, max_workers: int = 4
11
+ ) -> Generator[DirListing, None, None]:
12
+ """Walk through the given directory recursively.
13
+
14
+ Args:
15
+ dir: Directory to walk through
16
+ max_depth: Maximum depth to traverse (-1 for unlimited)
17
+
18
+ Yields:
19
+ DirListing: Directory listing for each directory encountered
20
+ """
21
+ pending: Queue[tuple[Dir | None, int]] = Queue()
22
+ results: Queue[DirListing | Exception] = Queue()
23
+
24
+ def worker():
25
+ while True:
26
+ try:
27
+ # Add timeout to allow checking for sentinel value
28
+ try:
29
+ current_dir, depth = pending.get(timeout=0.1)
30
+ except Empty:
31
+ continue
32
+
33
+ # Check for sentinel value
34
+ if current_dir is None:
35
+ pending.task_done()
36
+ break
37
+
38
+ listing = current_dir.ls()
39
+ results.put(listing)
40
+
41
+ if max_depth == -1 or depth < max_depth:
42
+ for d in listing.dirs:
43
+ pending.put((d, depth + 1))
44
+
45
+ pending.task_done()
46
+ except Exception as e:
47
+ results.put(e)
48
+ pending.task_done()
49
+ break
50
+ return None
51
+
52
+ # Start workers
53
+ with ThreadPoolExecutor(max_workers=max_workers) as executor:
54
+ workers = [executor.submit(worker) for _ in range(max_workers)]
55
+
56
+ # Start walking
57
+ pending.put((dir, 0))
58
+
59
+ # Process results while workers are running
60
+ completed = 0
61
+ while completed < max_workers:
62
+ try:
63
+ result = results.get(timeout=0.1)
64
+ if isinstance(result, Exception):
65
+ # Propagate exception
66
+ raise result
67
+ yield result
68
+ except Empty:
69
+ # Check if any workers have completed
70
+ completed = sum(1 for w in workers if w.done())
71
+ continue
72
+
73
+ # Signal workers to stop
74
+ for _ in range(max_workers):
75
+ pending.put((None, 0))
76
+
77
+ # Drain any remaining results
78
+ while not results.empty():
79
+ result = results.get()
80
+ if isinstance(result, Exception):
81
+ raise result
82
+ yield result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rclone_api
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: rclone api in python
5
5
  Home-page: https://github.com/zackees/rclone-api
6
6
  Maintainer: Zachary Vorhies
@@ -1,7 +1,7 @@
1
1
  rclone_api/__init__.py,sha256=YH7KQaPwUiJWJiRf0NRKD7XHhMXsxWdXDjt9WLSwdjA,265
2
2
  rclone_api/cli.py,sha256=dibfAZIh0kXWsBbfp3onKLjyZXo54mTzDjUdzJlDlWo,231
3
3
  rclone_api/config.py,sha256=UujjDNcpwgipgdyFPMhC3zikvlsrurUvvZiwXm5NlPg,471
4
- rclone_api/dir.py,sha256=gzQ9tvnvtddVWN8GmumoAasP3LtMFh20CVyaMH-HxJk,447
4
+ rclone_api/dir.py,sha256=ajCrMOgR86R1HuviPEZk220aTri1KipwvWtyVK-a6MI,488
5
5
  rclone_api/dir_listing.py,sha256=NWleKHCCRW7_eh9JfRwE6r3QbjmiHD5ZEGQcd2vm4uY,458
6
6
  rclone_api/file.py,sha256=409neYPfCUKQX2w7Uw7_D0wR2PtH42srNe9u_nnOLxM,925
7
7
  rclone_api/rclone.py,sha256=Q3xwC8m47gBVULWSn2XttIBDl33DtCBopvxcOG5LeEA,1837
@@ -9,9 +9,10 @@ rclone_api/remote.py,sha256=RSD-X2jCnm_hq7K6ovJ_0ugM1OpI0vpECIHHEz16-Fs,173
9
9
  rclone_api/rpath.py,sha256=_k59z-O75hAhpPyUSH4glPEoiYtIS3RUQb7ltU9Ianw,2009
10
10
  rclone_api/types.py,sha256=Yp15HrjwZonSQhE323R0WP7fA4NWqKjAfM7z3OwHpWI,518
11
11
  rclone_api/util.py,sha256=EXnijLLdFHqwoZvHrZdqeM8r6T7ad9-pN7qBN1b0I_g,1465
12
+ rclone_api/walk.py,sha256=I-i010WNjGauQTCeH9EZByh9NNi53vw_OS3NvY0B9z8,2604
12
13
  rclone_api/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
13
- rclone_api-1.0.7.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
14
- rclone_api-1.0.7.dist-info/METADATA,sha256=gRqNUEJTfkOc25YPpehD9M9ntNx22hai32FXDVib6fU,1244
15
- rclone_api-1.0.7.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
16
- rclone_api-1.0.7.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
17
- rclone_api-1.0.7.dist-info/RECORD,,
14
+ rclone_api-1.0.8.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
15
+ rclone_api-1.0.8.dist-info/METADATA,sha256=ewOBVcqgDOTdc-SlXamj645GtkqEDpNKMWGVz6DAuh4,1244
16
+ rclone_api-1.0.8.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
17
+ rclone_api-1.0.8.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
18
+ rclone_api-1.0.8.dist-info/RECORD,,