rclone-api 1.0.77__tar.gz → 1.0.79__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {rclone_api-1.0.77 → rclone_api-1.0.79}/PKG-INFO +1 -1
- {rclone_api-1.0.77 → rclone_api-1.0.79}/pyproject.toml +1 -1
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/__init__.py +1 -2
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/dir_listing.py +10 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/file.py +7 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/group_files.py +3 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/rclone.py +41 -40
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/types.py +4 -3
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/PKG-INFO +1 -1
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_size_files.py +5 -4
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.aiderignore +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.github/workflows/lint.yml +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.github/workflows/push_macos.yml +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.github/workflows/push_ubuntu.yml +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.github/workflows/push_win.yml +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.gitignore +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.pylintrc +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.vscode/launch.json +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.vscode/settings.json +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/.vscode/tasks.json +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/LICENSE +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/MANIFEST.in +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/README.md +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/clean +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/install +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/lint +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/requirements.testing.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/setup.cfg +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/setup.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/assets/example.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/cli.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/cmd/list_files.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/completed_process.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/config.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/convert.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/deprecated.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/diff.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/dir.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/exec.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/filelist.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/process.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/remote.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/rpath.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/scan_missing_folders.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/util.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api/walk.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/SOURCES.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/dependency_links.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/entry_points.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/requires.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/src/rclone_api.egg-info/top_level.txt +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/test +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_cmd_list_files.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_copy.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_copy_files.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_diff.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_group_files.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_is_synced.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_ls.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_mount.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_mount_s3.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_mount_webdav.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_obscure.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_remote_control.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_remotes.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_scan_missing_folders.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_serve_webdav.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tests/test_walk.py +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/tox.ini +0 -0
- {rclone_api-1.0.77 → rclone_api-1.0.79}/upload_package.sh +0 -0
@@ -9,7 +9,7 @@ from .process import Process
|
|
9
9
|
from .rclone import Rclone, rclone_verbose
|
10
10
|
from .remote import Remote
|
11
11
|
from .rpath import RPath
|
12
|
-
from .types import
|
12
|
+
from .types import ListingOption, Order, SizeResult
|
13
13
|
|
14
14
|
__all__ = [
|
15
15
|
"Rclone",
|
@@ -29,6 +29,5 @@ __all__ = [
|
|
29
29
|
"ListingOption",
|
30
30
|
"Order",
|
31
31
|
"ListingOption",
|
32
|
-
"GroupingOption",
|
33
32
|
"SizeResult",
|
34
33
|
]
|
@@ -29,6 +29,16 @@ class DirListing:
|
|
29
29
|
self.dirs: list[Dir] = [Dir(d) for d in dirs_and_files if d.is_dir]
|
30
30
|
self.files: list[File] = [File(f) for f in dirs_and_files if not f.is_dir]
|
31
31
|
|
32
|
+
def files_relative(self, prefix: str) -> list[str]:
|
33
|
+
"""Return a list of file paths relative to the root directory."""
|
34
|
+
from rclone_api.file import File
|
35
|
+
|
36
|
+
out: list[str] = []
|
37
|
+
f: File
|
38
|
+
for f in self.files:
|
39
|
+
out.append(f.relative_to(prefix))
|
40
|
+
return out
|
41
|
+
|
32
42
|
def __str__(self) -> str:
|
33
43
|
n_files = len(self.files)
|
34
44
|
n_dirs = len(self.dirs)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import json
|
2
|
+
from pathlib import Path
|
2
3
|
|
3
4
|
from rclone_api.rpath import RPath
|
4
5
|
|
@@ -47,6 +48,12 @@ class File:
|
|
47
48
|
return f"{remote.name}:{rest}"
|
48
49
|
return rest
|
49
50
|
|
51
|
+
def relative_to(self, prefix: str) -> str:
|
52
|
+
"""Return the relative path to the other directory."""
|
53
|
+
self_path = Path(str(self))
|
54
|
+
rel_path = self_path.relative_to(prefix)
|
55
|
+
return str(rel_path.as_posix())
|
56
|
+
|
50
57
|
@property
|
51
58
|
def size(self) -> int:
|
52
59
|
"""Get the size of the file."""
|
@@ -182,6 +182,9 @@ def group_under_remote(
|
|
182
182
|
files: list[str], fully_qualified: bool = True
|
183
183
|
) -> dict[str, list[str]]:
|
184
184
|
"""split between filename and remote"""
|
185
|
+
|
186
|
+
#### DOE STHIS NEED TO BE REMOVEDD????? #####
|
187
|
+
|
185
188
|
assert fully_qualified is True, "Not implemented for fully_qualified=False"
|
186
189
|
out: dict[str, list[str]] = {}
|
187
190
|
for file in files:
|
@@ -24,14 +24,11 @@ from rclone_api.exec import RcloneExec
|
|
24
24
|
from rclone_api.file import File
|
25
25
|
from rclone_api.group_files import (
|
26
26
|
group_files,
|
27
|
-
group_under_remote,
|
28
|
-
group_under_remote_bucket,
|
29
27
|
)
|
30
28
|
from rclone_api.process import Process
|
31
29
|
from rclone_api.remote import Remote
|
32
30
|
from rclone_api.rpath import RPath
|
33
31
|
from rclone_api.types import (
|
34
|
-
GroupingOption,
|
35
32
|
ListingOption,
|
36
33
|
ModTimeStrategy,
|
37
34
|
Order,
|
@@ -840,54 +837,50 @@ class Rclone:
|
|
840
837
|
|
841
838
|
def size_files(
|
842
839
|
self,
|
840
|
+
src: str,
|
843
841
|
files: list[str],
|
844
842
|
fast_list: bool = True,
|
845
843
|
other_args: list[str] | None = None,
|
846
|
-
grouping: GroupingOption = GroupingOption.BUCKET,
|
847
844
|
check: bool | None = False,
|
848
845
|
verbose: bool | None = None,
|
849
846
|
) -> SizeResult:
|
850
847
|
"""Get the size of a list of files. Example of files items: "remote:bucket/to/file"."""
|
851
848
|
verbose = get_verbose(verbose)
|
852
849
|
check = get_check(check)
|
853
|
-
|
854
|
-
if grouping == GroupingOption.BUCKET:
|
855
|
-
file_list = group_under_remote_bucket(files)
|
856
|
-
elif grouping == GroupingOption.REMOTE:
|
857
|
-
file_list = group_under_remote(files)
|
850
|
+
files = list(files)
|
858
851
|
all_files: list[File] = []
|
859
|
-
for src_path, files in file_list.items():
|
860
|
-
cmd = ["lsjson", src_path, "--files-only", "-R"]
|
861
|
-
with TemporaryDirectory() as tmpdir:
|
862
|
-
# print("files: " + ",".join(files))
|
863
|
-
include_files_txt = Path(tmpdir) / "include_files.txt"
|
864
|
-
include_files_txt.write_text("\n".join(files), encoding="utf-8")
|
865
|
-
cmd += ["--files-from", str(include_files_txt)]
|
866
|
-
if fast_list:
|
867
|
-
cmd.append("--fast-list")
|
868
|
-
if other_args:
|
869
|
-
cmd += other_args
|
870
|
-
cp = self._run(cmd, check=check)
|
871
852
|
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
853
|
+
cmd = ["lsjson", src, "--files-only", "-R"]
|
854
|
+
with TemporaryDirectory() as tmpdir:
|
855
|
+
# print("files: " + ",".join(files))
|
856
|
+
include_files_txt = Path(tmpdir) / "include_files.txt"
|
857
|
+
include_files_txt.write_text("\n".join(files), encoding="utf-8")
|
858
|
+
cmd += ["--files-from", str(include_files_txt)]
|
859
|
+
if fast_list:
|
860
|
+
cmd.append("--fast-list")
|
861
|
+
if other_args:
|
862
|
+
cmd += other_args
|
863
|
+
cp = self._run(cmd, check=check)
|
864
|
+
|
865
|
+
if cp.returncode != 0:
|
866
|
+
if check:
|
867
|
+
raise ValueError(f"Error getting file sizes: {cp.stderr}")
|
883
868
|
else:
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
869
|
+
warnings.warn(f"Error getting file sizes: {cp.stderr}")
|
870
|
+
stdout = cp.stdout
|
871
|
+
pieces = src.split(":", 1)
|
872
|
+
remote_name = pieces[0]
|
873
|
+
parent_path: str | None
|
874
|
+
if len(pieces) > 1:
|
875
|
+
parent_path = pieces[1]
|
876
|
+
else:
|
877
|
+
parent_path = None
|
878
|
+
remote = Remote(name=remote_name, rclone=self)
|
879
|
+
paths: list[RPath] = RPath.from_json_str(
|
880
|
+
stdout, remote, parent_path=parent_path
|
881
|
+
)
|
882
|
+
# print(paths)
|
883
|
+
all_files += [File(p) for p in paths]
|
891
884
|
file_sizes: dict[str, int] = {}
|
892
885
|
f: File
|
893
886
|
for f in all_files:
|
@@ -900,5 +893,13 @@ class Rclone:
|
|
900
893
|
warnings.warn(f"File size is 0: {p}")
|
901
894
|
file_sizes[p] = f.size
|
902
895
|
total_size = sum(file_sizes.values())
|
903
|
-
|
896
|
+
file_sizes_path_corrected: dict[str, int] = {}
|
897
|
+
for path, size in file_sizes.items():
|
898
|
+
# remove the prefix
|
899
|
+
path_path = Path(path)
|
900
|
+
path_str = path_path.relative_to(src).as_posix()
|
901
|
+
file_sizes_path_corrected[path_str] = size
|
902
|
+
out: SizeResult = SizeResult(
|
903
|
+
prefix=src, total_size=total_size, file_sizes=file_sizes_path_corrected
|
904
|
+
)
|
904
905
|
return out
|
@@ -19,14 +19,15 @@ class Order(Enum):
|
|
19
19
|
RANDOM = "random"
|
20
20
|
|
21
21
|
|
22
|
-
class GroupingOption(Enum):
|
23
|
-
|
24
|
-
|
22
|
+
# class GroupingOption(Enum):
|
23
|
+
# BUCKET = "bucket"
|
24
|
+
# REMOTE = "remote"
|
25
25
|
|
26
26
|
|
27
27
|
@dataclass
|
28
28
|
class SizeResult:
|
29
29
|
"""Size result dataclass."""
|
30
30
|
|
31
|
+
prefix: str
|
31
32
|
total_size: int
|
32
33
|
file_sizes: dict[str, int]
|
@@ -61,7 +61,8 @@ class RcloneSizeFilesTester(unittest.TestCase):
|
|
61
61
|
dirlisting: DirListing
|
62
62
|
is_first = True
|
63
63
|
files: list[str] = []
|
64
|
-
|
64
|
+
src = f"dst:{BUCKET_NAME}"
|
65
|
+
for dirlisting in rclone.walk(src, max_depth=1):
|
65
66
|
if is_first:
|
66
67
|
# assert just one file
|
67
68
|
# assert len(dirlisting.files) == 1
|
@@ -70,12 +71,12 @@ class RcloneSizeFilesTester(unittest.TestCase):
|
|
70
71
|
self.assertEqual(dirlisting.files[0].name, "first.txt")
|
71
72
|
is_first = False
|
72
73
|
# print(dirlisting)
|
73
|
-
for file in dirlisting.
|
74
|
-
files.append(
|
74
|
+
for file in dirlisting.files_relative(src):
|
75
|
+
files.append(file)
|
75
76
|
|
76
77
|
# print(files)
|
77
78
|
|
78
|
-
size_map: SizeResult = rclone.size_files(files, check=True)
|
79
|
+
size_map: SizeResult = rclone.size_files(src=src, files=files, check=True)
|
79
80
|
print(size_map)
|
80
81
|
print("done")
|
81
82
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|