rclone-api 1.0.4__py2.py3-none-any.whl → 1.0.6__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
@@ -1,8 +1,9 @@
1
1
  from .dir import Dir
2
+ from .dir_listing import DirListing
2
3
  from .file import File
3
4
  from .rclone import Rclone
4
5
  from .remote import Remote
5
6
  from .rpath import RPath
6
7
  from .types import Config
7
8
 
8
- __all__ = ["Rclone", "File", "Config", "Remote", "Dir", "RPath"]
9
+ __all__ = ["Rclone", "File", "Config", "Remote", "Dir", "RPath", "DirListing"]
rclone_api/dir.py CHANGED
@@ -1,4 +1,4 @@
1
- from rclone_api.file import File
1
+ from rclone_api.dir_listing import DirListing
2
2
  from rclone_api.rpath import RPath
3
3
 
4
4
 
@@ -8,20 +8,10 @@ class Dir:
8
8
  def __init__(self, path: RPath) -> None:
9
9
  self.path = path
10
10
 
11
- def ls(self) -> tuple[list["Dir"], list[File]]:
11
+ def ls(self) -> DirListing:
12
12
  """List files and directories in the given path."""
13
- cmd = ["lsjson", "--files-only", "--dirs-only", "--json", str(self.path)]
14
13
  assert self.path.rclone is not None
15
- cp = self.path.rclone._run(cmd)
16
- text = cp.stdout
17
- tmp: list[RPath] = RPath.from_json_str(text)
18
- for t in tmp:
19
- t.set_rclone(self.path.rclone)
20
- # dirs = [o for o in out if o.is_dir]
21
- # files = [o for o in out if not o.is_dir]
22
- dirs = [Dir(p) for p in tmp if p.is_dir]
23
- files = [File(p) for p in tmp if not p.is_dir]
24
- return dirs, files
14
+ return self.path.rclone.ls(self.path.path)
25
15
 
26
16
  def __str__(self) -> str:
27
17
  return str(self.path)
@@ -0,0 +1,12 @@
1
+ from dataclasses import dataclass
2
+
3
+ from rclone_api.dir import Dir
4
+ from rclone_api.file import File
5
+
6
+
7
+ @dataclass
8
+ class DirListing:
9
+ """Remote file dataclass."""
10
+
11
+ dirs: list[Dir]
12
+ files: list[File]
rclone_api/rclone.py CHANGED
@@ -5,6 +5,9 @@ Unit test file.
5
5
  import subprocess
6
6
  from pathlib import Path
7
7
 
8
+ from rclone_api.dir import Dir
9
+ from rclone_api.dir_listing import DirListing
10
+ from rclone_api.file import File
8
11
  from rclone_api.remote import Remote
9
12
  from rclone_api.rpath import RPath
10
13
  from rclone_api.types import Config, RcloneExec
@@ -23,7 +26,7 @@ class Rclone:
23
26
  def _run(self, cmd: list[str]) -> subprocess.CompletedProcess:
24
27
  return self._exec.execute(cmd)
25
28
 
26
- def ls(self, path: str | Remote, max_depth: int = 0) -> list[RPath]:
29
+ def ls(self, path: str | Remote, max_depth: int = 0) -> DirListing:
27
30
  """List files in the given path.
28
31
 
29
32
  Args:
@@ -40,10 +43,12 @@ class Rclone:
40
43
 
41
44
  cp = self._run(cmd)
42
45
  text = cp.stdout
43
- out: list[RPath] = RPath.from_json_str(text)
44
- for o in out:
46
+ paths: list[RPath] = RPath.from_json_str(text)
47
+ for o in paths:
45
48
  o.set_rclone(self)
46
- return out
49
+ dirs: list[Dir] = [Dir(o) for o in paths if o.is_dir]
50
+ files: list[File] = [File(o) for o in paths if not o.is_dir]
51
+ return DirListing(dirs=dirs, files=files)
47
52
 
48
53
  def listremotes(self) -> list[Remote]:
49
54
  cmd = ["listremotes"]
rclone_api/rpath.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import json
2
- from pathlib import Path
3
2
  from typing import Any
4
3
 
5
4
 
@@ -73,41 +72,6 @@ class RPath:
73
72
  # "IsBucket": self.is_bucket,
74
73
  }
75
74
 
76
- def read_text(self) -> str:
77
- """Read the file contents as bytes.
78
-
79
- Returns:
80
- bytes: The file contents
81
-
82
- Raises:
83
- RuntimeError: If no rclone instance is associated with this file
84
- RuntimeError: If the path represents a directory
85
- """
86
- if self.rclone is None:
87
- raise RuntimeError("No rclone instance associated with this file")
88
- if self.is_dir:
89
- raise RuntimeError("Cannot read a directory as bytes")
90
-
91
- result = self.rclone._run(["cat", self.path])
92
- return result.stdout
93
-
94
- def read(self, dest: Path) -> None:
95
- """Copy the remote file to a local destination path.
96
-
97
- Args:
98
- dest: Local destination path where the file will be copied
99
-
100
- Raises:
101
- RuntimeError: If no rclone instance is associated with this file
102
- RuntimeError: If the path represents a directory
103
- """
104
- if self.rclone is None:
105
- raise RuntimeError("No rclone instance associated with this file")
106
- if self.is_dir:
107
- raise RuntimeError("Cannot read a directory as a file")
108
-
109
- self.rclone._run(["copyto", self.path, str(dest)])
110
-
111
75
  def __str__(self) -> str:
112
76
  out = self.to_json()
113
77
  return json.dumps(out)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rclone_api
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: rclone api in python
5
5
  Home-page: https://github.com/zackees/rclone-api
6
6
  Maintainer: Zachary Vorhies
@@ -0,0 +1,17 @@
1
+ rclone_api/__init__.py,sha256=YH7KQaPwUiJWJiRf0NRKD7XHhMXsxWdXDjt9WLSwdjA,265
2
+ rclone_api/cli.py,sha256=dibfAZIh0kXWsBbfp3onKLjyZXo54mTzDjUdzJlDlWo,231
3
+ rclone_api/config.py,sha256=UujjDNcpwgipgdyFPMhC3zikvlsrurUvvZiwXm5NlPg,471
4
+ rclone_api/dir.py,sha256=gzQ9tvnvtddVWN8GmumoAasP3LtMFh20CVyaMH-HxJk,447
5
+ rclone_api/dir_listing.py,sha256=N2tEcAx721r1HlV0Cax-sutkLJMW4AAofZMVA-Z_aQQ,206
6
+ rclone_api/file.py,sha256=409neYPfCUKQX2w7Uw7_D0wR2PtH42srNe9u_nnOLxM,925
7
+ rclone_api/rclone.py,sha256=J7pFhe4mHaN415yFP2k_9jr9UnrEiq3lDaKhefepVfA,2053
8
+ rclone_api/remote.py,sha256=RSD-X2jCnm_hq7K6ovJ_0ugM1OpI0vpECIHHEz16-Fs,173
9
+ rclone_api/rpath.py,sha256=_k59z-O75hAhpPyUSH4glPEoiYtIS3RUQb7ltU9Ianw,2009
10
+ rclone_api/types.py,sha256=Yp15HrjwZonSQhE323R0WP7fA4NWqKjAfM7z3OwHpWI,518
11
+ rclone_api/util.py,sha256=EXnijLLdFHqwoZvHrZdqeM8r6T7ad9-pN7qBN1b0I_g,1465
12
+ rclone_api/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
13
+ rclone_api-1.0.6.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
14
+ rclone_api-1.0.6.dist-info/METADATA,sha256=hQ9HbGL2oL7TKOOfI4H10DzXZS_vgb-6zKZzJBQbJLA,1244
15
+ rclone_api-1.0.6.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
16
+ rclone_api-1.0.6.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
17
+ rclone_api-1.0.6.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- rclone_api/__init__.py,sha256=VPzZJdb7ZzYjUHV2cZc2rE6MMu_EI8KZn31b4FJSLZo,215
2
- rclone_api/cli.py,sha256=dibfAZIh0kXWsBbfp3onKLjyZXo54mTzDjUdzJlDlWo,231
3
- rclone_api/config.py,sha256=UujjDNcpwgipgdyFPMhC3zikvlsrurUvvZiwXm5NlPg,471
4
- rclone_api/dir.py,sha256=H83MhwabdxjBiT_3IHvAgo9taeXq6ZhOKIrpFOZwHnY,896
5
- rclone_api/file.py,sha256=409neYPfCUKQX2w7Uw7_D0wR2PtH42srNe9u_nnOLxM,925
6
- rclone_api/rclone.py,sha256=-c9cskRzGT1t5uQjGg8T9puRAGeQqH9vt1sy5o0Cl_U,1773
7
- rclone_api/remote.py,sha256=RSD-X2jCnm_hq7K6ovJ_0ugM1OpI0vpECIHHEz16-Fs,173
8
- rclone_api/rpath.py,sha256=UQ08-crLe4t4IK1UCqijGybByj4vzRMY0vD7b5xYzMo,3237
9
- rclone_api/types.py,sha256=Yp15HrjwZonSQhE323R0WP7fA4NWqKjAfM7z3OwHpWI,518
10
- rclone_api/util.py,sha256=EXnijLLdFHqwoZvHrZdqeM8r6T7ad9-pN7qBN1b0I_g,1465
11
- rclone_api/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
12
- rclone_api-1.0.4.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
13
- rclone_api-1.0.4.dist-info/METADATA,sha256=5cimbaT1kOtrJwOmPl0ZlHWFtcukf6pf2O6a7nCmRjk,1244
14
- rclone_api-1.0.4.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
15
- rclone_api-1.0.4.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
16
- rclone_api-1.0.4.dist-info/RECORD,,