rclone-api 1.0.3__py2.py3-none-any.whl → 1.0.5__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,7 +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
5
+ from .remote import Remote
4
6
  from .rpath import RPath
5
- from .types import Config, Remote
7
+ from .types import Config
6
8
 
7
- __all__ = ["Rclone", "File", "Config", "Remote", "Dir", "RPath"]
9
+ __all__ = ["Rclone", "File", "Config", "Remote", "Dir", "RPath", "DirListing"]
rclone_api/config.py ADDED
@@ -0,0 +1,19 @@
1
+ import subprocess
2
+ from dataclasses import dataclass
3
+ from pathlib import Path
4
+
5
+ from rclone_api.types import Config
6
+
7
+
8
+ @dataclass
9
+ class RcloneExec:
10
+ """Rclone execution dataclass."""
11
+
12
+ rclone_config: Path | Config
13
+ rclone_exe: Path
14
+
15
+ def execute(self, cmd: list[str]) -> subprocess.CompletedProcess:
16
+ """Execute rclone command."""
17
+ from rclone_api.util import rclone_execute
18
+
19
+ return rclone_execute(cmd, self.rclone_config, self.rclone_exe)
@@ -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,8 +5,12 @@ 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
11
+ from rclone_api.remote import Remote
8
12
  from rclone_api.rpath import RPath
9
- from rclone_api.types import Config, RcloneExec, Remote
13
+ from rclone_api.types import Config, RcloneExec
10
14
  from rclone_api.util import get_rclone_exe
11
15
 
12
16
 
@@ -22,7 +26,7 @@ class Rclone:
22
26
  def _run(self, cmd: list[str]) -> subprocess.CompletedProcess:
23
27
  return self._exec.execute(cmd)
24
28
 
25
- def ls(self, path: str | Remote, max_depth: int = 0) -> list[RPath]:
29
+ def ls(self, path: str | Remote, max_depth: int = 0) -> DirListing:
26
30
  """List files in the given path.
27
31
 
28
32
  Args:
@@ -39,10 +43,12 @@ class Rclone:
39
43
 
40
44
  cp = self._run(cmd)
41
45
  text = cp.stdout
42
- out: list[RPath] = RPath.from_json_str(text)
43
- for o in out:
46
+ paths: list[RPath] = RPath.from_json_str(text)
47
+ for o in paths:
44
48
  o.set_rclone(self)
45
- 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)
46
52
 
47
53
  def listremotes(self) -> list[Remote]:
48
54
  cmd = ["listremotes"]
rclone_api/remote.py ADDED
@@ -0,0 +1,8 @@
1
+ class Remote:
2
+ """Remote dataclass."""
3
+
4
+ def __init__(self, name: str) -> None:
5
+ self.name = name
6
+
7
+ def __str__(self) -> str:
8
+ return f"{self.name}:"
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)
rclone_api/types.py CHANGED
@@ -22,13 +22,3 @@ class RcloneExec:
22
22
  from rclone_api.util import rclone_execute
23
23
 
24
24
  return rclone_execute(cmd, self.rclone_config, self.rclone_exe)
25
-
26
-
27
- class Remote:
28
- """Remote dataclass."""
29
-
30
- def __init__(self, name: str) -> None:
31
- self.name = name
32
-
33
- def __str__(self) -> str:
34
- return f"{self.name}:"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rclone_api
3
- Version: 1.0.3
3
+ Version: 1.0.5
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=H83MhwabdxjBiT_3IHvAgo9taeXq6ZhOKIrpFOZwHnY,896
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.5.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
14
+ rclone_api-1.0.5.dist-info/METADATA,sha256=hq4p_iOF7VcpnDFFBcQU1G_ANEn4Ui0ei0RAjyTwCLQ,1244
15
+ rclone_api-1.0.5.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
16
+ rclone_api-1.0.5.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
17
+ rclone_api-1.0.5.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- rclone_api/__init__.py,sha256=ygZEO9GcF4UfdIDIinrfL2ExoWe3pWwKYIL8COeswe4,196
2
- rclone_api/cli.py,sha256=dibfAZIh0kXWsBbfp3onKLjyZXo54mTzDjUdzJlDlWo,231
3
- rclone_api/dir.py,sha256=H83MhwabdxjBiT_3IHvAgo9taeXq6ZhOKIrpFOZwHnY,896
4
- rclone_api/file.py,sha256=409neYPfCUKQX2w7Uw7_D0wR2PtH42srNe9u_nnOLxM,925
5
- rclone_api/rclone.py,sha256=YlaWsWg-vtbqAOp1QbfZCIQ0KwfT3fkZQ3lZVR1nNmw,1743
6
- rclone_api/rpath.py,sha256=UQ08-crLe4t4IK1UCqijGybByj4vzRMY0vD7b5xYzMo,3237
7
- rclone_api/types.py,sha256=I_7WSHF0INm-XA7jEWMsFiGkpXPNmij6B5exsFUKggI,693
8
- rclone_api/util.py,sha256=EXnijLLdFHqwoZvHrZdqeM8r6T7ad9-pN7qBN1b0I_g,1465
9
- rclone_api/assets/example.txt,sha256=lTBovRjiz0_TgtAtbA1C5hNi2ffbqnNPqkKg6UiKCT8,54
10
- rclone_api-1.0.3.dist-info/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
11
- rclone_api-1.0.3.dist-info/METADATA,sha256=s-dUfLdnZCfaXSouGP_XypTADEUPub24idrl79fo21w,1244
12
- rclone_api-1.0.3.dist-info/WHEEL,sha256=9Hm2OB-j1QcCUq9Jguht7ayGIIZBRTdOXD1qg9cCgPM,109
13
- rclone_api-1.0.3.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
14
- rclone_api-1.0.3.dist-info/RECORD,,