rclone-api 1.5.22__py3-none-any.whl → 1.5.24__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/fs.py +28 -21
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/METADATA +1 -1
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/RECORD +7 -7
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/WHEEL +0 -0
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/entry_points.txt +0 -0
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/licenses/LICENSE +0 -0
- {rclone_api-1.5.22.dist-info → rclone_api-1.5.24.dist-info}/top_level.txt +0 -0
rclone_api/fs.py
CHANGED
@@ -14,7 +14,7 @@ class FS(abc.ABC):
|
|
14
14
|
pass
|
15
15
|
|
16
16
|
@abc.abstractmethod
|
17
|
-
def
|
17
|
+
def read_bytes(self, path: Path | str) -> bytes:
|
18
18
|
pass
|
19
19
|
|
20
20
|
@abc.abstractmethod
|
@@ -41,15 +41,6 @@ class FS(abc.ABC):
|
|
41
41
|
def get_path(self, path: str) -> "FSPath":
|
42
42
|
pass
|
43
43
|
|
44
|
-
def read_text(self, path: Path | str) -> str:
|
45
|
-
utf = self.read_binary(path)
|
46
|
-
return utf.decode("utf-8")
|
47
|
-
|
48
|
-
def write_text(self, path: Path | str, data: str, encoding: str | None) -> None:
|
49
|
-
encoding = encoding or "utf-8"
|
50
|
-
utf = data.encode(encoding)
|
51
|
-
self.write_binary(path, utf)
|
52
|
-
|
53
44
|
|
54
45
|
class RealFS(FS):
|
55
46
|
|
@@ -70,7 +61,7 @@ class RealFS(FS):
|
|
70
61
|
def copy(self, src: Path | str, dest: Path | str) -> None:
|
71
62
|
shutil.copy(str(src), str(dest))
|
72
63
|
|
73
|
-
def
|
64
|
+
def read_bytes(self, path: Path | str) -> bytes:
|
74
65
|
with open(path, "rb") as f:
|
75
66
|
return f.read()
|
76
67
|
|
@@ -125,12 +116,15 @@ class RemoteFS(FS):
|
|
125
116
|
return path.as_posix()
|
126
117
|
return path
|
127
118
|
|
119
|
+
def _to_remote_path(self, path: str | Path) -> str:
|
120
|
+
return Path(path).relative_to(self.src).as_posix()
|
121
|
+
|
128
122
|
def copy(self, src: Path | str, dest: Path | str) -> None:
|
129
123
|
src = self._to_str(src)
|
130
|
-
dest = self.
|
124
|
+
dest = self._to_remote_path(dest)
|
131
125
|
self.rclone.copy(src, dest)
|
132
126
|
|
133
|
-
def
|
127
|
+
def read_bytes(self, path: Path | str) -> bytes:
|
134
128
|
path = self._to_str(path)
|
135
129
|
err = self.rclone.read_bytes(path)
|
136
130
|
if isinstance(err, Exception):
|
@@ -143,27 +137,29 @@ class RemoteFS(FS):
|
|
143
137
|
|
144
138
|
def exists(self, path: Path | str) -> bool:
|
145
139
|
path = self._to_str(path)
|
146
|
-
|
140
|
+
dst_rel = self._to_remote_path(path)
|
141
|
+
return self.server.exists(dst_rel)
|
147
142
|
|
148
143
|
def mkdir(self, path: str, parents=True, exist_ok=True) -> None:
|
149
144
|
# Ignore mkdir for remote backend, it will be made when file is written.
|
150
145
|
import warnings
|
146
|
+
|
151
147
|
warnings.warn("mkdir is not supported for remote backend", stacklevel=2)
|
152
148
|
return None
|
153
149
|
|
154
150
|
def is_dir(self, path: Path | str) -> bool:
|
155
|
-
path = self.
|
151
|
+
path = self._to_remote_path(path)
|
156
152
|
err = self.server.list(path)
|
157
153
|
return isinstance(err, list)
|
158
154
|
|
159
155
|
def is_file(self, path: Path | str) -> bool:
|
160
|
-
path = self.
|
156
|
+
path = self._to_remote_path(path)
|
161
157
|
err = self.server.list(path)
|
162
158
|
# Make faster.
|
163
159
|
return isinstance(err, Exception) and self.exists(path)
|
164
160
|
|
165
161
|
def ls(self, path: Path | str) -> list[str]:
|
166
|
-
path = self.
|
162
|
+
path = self._to_remote_path(path)
|
167
163
|
err = self.server.list(path)
|
168
164
|
if isinstance(err, Exception):
|
169
165
|
raise FileNotFoundError(f"File not found: {path}, because of {err}")
|
@@ -188,10 +184,16 @@ class FSPath:
|
|
188
184
|
self.path = path
|
189
185
|
|
190
186
|
def read_text(self) -> str:
|
191
|
-
|
187
|
+
data = self.read_bytes()
|
188
|
+
return data.decode("utf-8")
|
192
189
|
|
193
|
-
def
|
194
|
-
|
190
|
+
def read_bytes(self) -> bytes:
|
191
|
+
data: bytes | None = None
|
192
|
+
try:
|
193
|
+
data = self.fs.read_bytes(self.path)
|
194
|
+
return data
|
195
|
+
except Exception as e:
|
196
|
+
raise FileNotFoundError(f"File not found: {self.path}, because of {e}")
|
195
197
|
|
196
198
|
def exists(self) -> bool:
|
197
199
|
return self.fs.exists(self.path)
|
@@ -206,7 +208,12 @@ class FSPath:
|
|
206
208
|
self.fs.mkdir(self.path, parents=parents, exist_ok=exist_ok)
|
207
209
|
|
208
210
|
def write_text(self, data: str, encoding: str | None = None) -> None:
|
209
|
-
|
211
|
+
if encoding is None:
|
212
|
+
encoding = "utf-8"
|
213
|
+
self.write_bytes(data.encode(encoding))
|
214
|
+
|
215
|
+
def write_bytes(self, data: bytes) -> None:
|
216
|
+
self.fs.write_binary(self.path, data)
|
210
217
|
|
211
218
|
def rmtree(self, ignore_errors=False) -> None:
|
212
219
|
assert self.exists(), f"Path does not exist: {self.path}"
|
@@ -13,7 +13,7 @@ rclone_api/file_item.py,sha256=cH-AQYsxedhNPp4c8NHY1ad4Z7St4yf_VGbmiGD59no,1770
|
|
13
13
|
rclone_api/file_part.py,sha256=i6ByS5_sae8Eba-4imBVTxd-xKC8ExWy7NR8QGr0ors,6155
|
14
14
|
rclone_api/file_stream.py,sha256=_W3qnwCuigqA0hzXl2q5pAxSZDRaUSwet4BkT0lpnzs,1431
|
15
15
|
rclone_api/filelist.py,sha256=xbiusvNgaB_b_kQOZoHMJJxn6TWGtPrWd2J042BI28o,767
|
16
|
-
rclone_api/fs.py,sha256=
|
16
|
+
rclone_api/fs.py,sha256=drSne7MnV0t8LpsGV4EpWRJ5CoH4HU3ohrE5-eBG05w,7124
|
17
17
|
rclone_api/group_files.py,sha256=H92xPW9lQnbNw5KbtZCl00bD6iRh9yRbCuxku4j_3dg,8036
|
18
18
|
rclone_api/http_server.py,sha256=ZdL-rGaq0zIjcaIiRIbPBQ4OIWZ7dCu71aq0nRlKtY4,11686
|
19
19
|
rclone_api/install.py,sha256=Xb1BRn8rQcSpSd4dzmvIOELP2zM2DytUeIZ6jzv738A,2893
|
@@ -54,9 +54,9 @@ rclone_api/s3/multipart/upload_parts_inline.py,sha256=V7syKjFyVIe4U9Ahl5XgqVTzt9
|
|
54
54
|
rclone_api/s3/multipart/upload_parts_resumable.py,sha256=6-nlMclS8jyVvMvFbQDcZOX9MY1WbCcKA_s9bwuYxnk,9793
|
55
55
|
rclone_api/s3/multipart/upload_parts_server_side_merge.py,sha256=Fp2pdrs5dONQI9LkfNolgAGj1-Z2V1SsRd0r0sreuXI,18040
|
56
56
|
rclone_api/s3/multipart/upload_state.py,sha256=f-Aq2NqtAaMUMhYitlICSNIxCKurWAl2gDEUVizLIqw,6019
|
57
|
-
rclone_api-1.5.
|
58
|
-
rclone_api-1.5.
|
59
|
-
rclone_api-1.5.
|
60
|
-
rclone_api-1.5.
|
61
|
-
rclone_api-1.5.
|
62
|
-
rclone_api-1.5.
|
57
|
+
rclone_api-1.5.24.dist-info/licenses/LICENSE,sha256=b6pOoifSXiUaz_lDS84vWlG3fr4yUKwB8fzkrH9R8bQ,1064
|
58
|
+
rclone_api-1.5.24.dist-info/METADATA,sha256=X6Vra_UInDzwFwD1zC5tsGZcW_SI8JP5d71h9b2OTy4,37155
|
59
|
+
rclone_api-1.5.24.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
60
|
+
rclone_api-1.5.24.dist-info/entry_points.txt,sha256=fJteOlYVwgX3UbNuL9jJ0zUTuX2O79JFAeNgK7Sw7EQ,255
|
61
|
+
rclone_api-1.5.24.dist-info/top_level.txt,sha256=EvZ7uuruUpe9RiUyEp25d1Keq7PWYNT0O_-mr8FCG5g,11
|
62
|
+
rclone_api-1.5.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|