rclone-api 1.0.0__tar.gz
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-1.0.0/LICENSE +21 -0
- rclone_api-1.0.0/MANIFEST.in +3 -0
- rclone_api-1.0.0/PKG-INFO +36 -0
- rclone_api-1.0.0/README.md +21 -0
- rclone_api-1.0.0/pyproject.toml +44 -0
- rclone_api-1.0.0/requirements.testing.txt +7 -0
- rclone_api-1.0.0/setup.cfg +4 -0
- rclone_api-1.0.0/setup.py +23 -0
- rclone_api-1.0.0/src/rclone_api/__init__.py +0 -0
- rclone_api-1.0.0/src/rclone_api/assets/example.txt +1 -0
- rclone_api-1.0.0/src/rclone_api/cli.py +15 -0
- rclone_api-1.0.0/src/rclone_api/rclone.py +160 -0
- rclone_api-1.0.0/src/rclone_api.egg-info/PKG-INFO +36 -0
- rclone_api-1.0.0/src/rclone_api.egg-info/SOURCES.txt +15 -0
- rclone_api-1.0.0/src/rclone_api.egg-info/dependency_links.txt +1 -0
- rclone_api-1.0.0/src/rclone_api.egg-info/top_level.txt +1 -0
- rclone_api-1.0.0/tests/test_simple.py +16 -0
rclone_api-1.0.0/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 zackees
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: rclone_api
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: rclone api in python
|
5
|
+
Home-page: https://github.com/zackees/rclone-api
|
6
|
+
Maintainer: Zachary Vorhies
|
7
|
+
License: BSD 3-Clause License
|
8
|
+
Keywords: template-python-cmd
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Requires-Python: >=3.7
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Dynamic: home-page
|
14
|
+
Dynamic: maintainer
|
15
|
+
|
16
|
+
# template-python-cmd
|
17
|
+
A template for quickly making a python lib that has a command line program attached
|
18
|
+
|
19
|
+
[](../../actions/workflows/lint.yml)
|
20
|
+
|
21
|
+
[](../../actions/workflows/push_macos.yml)
|
22
|
+
[](../../actions/workflows/push_ubuntu.yml)
|
23
|
+
[](../../actions/workflows/push_win.yml)
|
24
|
+
|
25
|
+
Replace `template-python-cmd` and `template_python_cmd` with your command. Run tox until it's
|
26
|
+
correct.
|
27
|
+
|
28
|
+
To develop software, run `. ./activate.sh`
|
29
|
+
|
30
|
+
# Windows
|
31
|
+
|
32
|
+
This environment requires you to use `git-bash`.
|
33
|
+
|
34
|
+
# Linting
|
35
|
+
|
36
|
+
Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# template-python-cmd
|
2
|
+
A template for quickly making a python lib that has a command line program attached
|
3
|
+
|
4
|
+
[](../../actions/workflows/lint.yml)
|
5
|
+
|
6
|
+
[](../../actions/workflows/push_macos.yml)
|
7
|
+
[](../../actions/workflows/push_ubuntu.yml)
|
8
|
+
[](../../actions/workflows/push_win.yml)
|
9
|
+
|
10
|
+
Replace `template-python-cmd` and `template_python_cmd` with your command. Run tox until it's
|
11
|
+
correct.
|
12
|
+
|
13
|
+
To develop software, run `. ./activate.sh`
|
14
|
+
|
15
|
+
# Windows
|
16
|
+
|
17
|
+
This environment requires you to use `git-bash`.
|
18
|
+
|
19
|
+
# Linting
|
20
|
+
|
21
|
+
Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools>=65.5.1", "setuptools-scm", "wheel"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "rclone_api"
|
7
|
+
readme = "README.md"
|
8
|
+
description = "rclone api in python"
|
9
|
+
requires-python = ">=3.7"
|
10
|
+
keywords = ["template-python-cmd"]
|
11
|
+
license = { text = "BSD 3-Clause License" }
|
12
|
+
classifiers = ["Programming Language :: Python :: 3"]
|
13
|
+
dependencies = [
|
14
|
+
|
15
|
+
]
|
16
|
+
# Change this with the version number bump.
|
17
|
+
version = "1.0.0"
|
18
|
+
|
19
|
+
[tool.setuptools]
|
20
|
+
package-dir = {"" = "src"}
|
21
|
+
|
22
|
+
[tool.ruff]
|
23
|
+
line-length = 200
|
24
|
+
|
25
|
+
[tool.pylint."MESSAGES CONTROL"]
|
26
|
+
good-names = [
|
27
|
+
"c",
|
28
|
+
"i",
|
29
|
+
"ok",
|
30
|
+
"id",
|
31
|
+
"e",
|
32
|
+
"f"
|
33
|
+
]
|
34
|
+
disable = [
|
35
|
+
"missing-function-docstring",
|
36
|
+
"missing-module-docstring"
|
37
|
+
]
|
38
|
+
|
39
|
+
[tool.isort]
|
40
|
+
profile = "black"
|
41
|
+
|
42
|
+
[tool.mypy]
|
43
|
+
ignore_missing_imports = true
|
44
|
+
disable_error_code = ["import-untyped"]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"""
|
2
|
+
Setup file.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import os
|
6
|
+
import re
|
7
|
+
|
8
|
+
from setuptools import setup
|
9
|
+
|
10
|
+
URL = "https://github.com/zackees/rclone-api"
|
11
|
+
KEYWORDS = "rclone api python"
|
12
|
+
HERE = os.path.dirname(os.path.abspath(__file__))
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
if __name__ == "__main__":
|
17
|
+
setup(
|
18
|
+
maintainer="Zachary Vorhies",
|
19
|
+
keywords=KEYWORDS,
|
20
|
+
url=URL,
|
21
|
+
package_data={"": ["assets/example.txt"]},
|
22
|
+
include_package_data=True)
|
23
|
+
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Example assets that will be deployed with python code.
|
@@ -0,0 +1,160 @@
|
|
1
|
+
"""
|
2
|
+
Unit test file.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import json
|
6
|
+
import shutil
|
7
|
+
import subprocess
|
8
|
+
from dataclasses import dataclass
|
9
|
+
from pathlib import Path
|
10
|
+
from tempfile import TemporaryDirectory
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass
|
14
|
+
class RcloneConfig:
|
15
|
+
"""Rclone configuration dataclass."""
|
16
|
+
|
17
|
+
text: str
|
18
|
+
|
19
|
+
|
20
|
+
def _rclone_execute(
|
21
|
+
cmd: list[str],
|
22
|
+
rclone_conf: Path | RcloneConfig,
|
23
|
+
rclone_exe: Path,
|
24
|
+
verbose: bool = False,
|
25
|
+
) -> subprocess.CompletedProcess:
|
26
|
+
print(subprocess.list2cmdline(cmd))
|
27
|
+
tempdir: TemporaryDirectory | None = None
|
28
|
+
|
29
|
+
try:
|
30
|
+
if isinstance(rclone_conf, RcloneConfig):
|
31
|
+
tempdir = TemporaryDirectory()
|
32
|
+
tmpfile = Path(tempdir.name) / "rclone.conf"
|
33
|
+
tmpfile.write_text(rclone_conf.text, encoding="utf-8")
|
34
|
+
rclone_conf = tmpfile
|
35
|
+
cmd = (
|
36
|
+
[str(rclone_exe.resolve())] + ["--config", str(rclone_conf.resolve())] + cmd
|
37
|
+
)
|
38
|
+
if verbose:
|
39
|
+
cmd_str = subprocess.list2cmdline(cmd)
|
40
|
+
print(f"Running: {cmd_str}")
|
41
|
+
cp = subprocess.run(
|
42
|
+
cmd, capture_output=True, encoding="utf-8", check=True, shell=False
|
43
|
+
)
|
44
|
+
return cp
|
45
|
+
finally:
|
46
|
+
if tempdir:
|
47
|
+
try:
|
48
|
+
tempdir.cleanup()
|
49
|
+
except Exception as e:
|
50
|
+
print(f"Error cleaning up tempdir: {e}")
|
51
|
+
|
52
|
+
|
53
|
+
@dataclass
|
54
|
+
class RcloneExec:
|
55
|
+
"""Rclone execution dataclass."""
|
56
|
+
|
57
|
+
rclone_config: Path | RcloneConfig
|
58
|
+
rclone_exe: Path
|
59
|
+
|
60
|
+
def execute(self, cmd: list[str]) -> subprocess.CompletedProcess:
|
61
|
+
"""Execute rclone command."""
|
62
|
+
return _rclone_execute(cmd, self.rclone_config, self.rclone_exe)
|
63
|
+
|
64
|
+
|
65
|
+
@dataclass
|
66
|
+
class RemoteFile:
|
67
|
+
"""Remote file dataclass."""
|
68
|
+
|
69
|
+
path: str
|
70
|
+
name: str
|
71
|
+
size: int
|
72
|
+
mime_type: str
|
73
|
+
mod_time: str
|
74
|
+
is_dir: bool
|
75
|
+
# is_bucket: bool
|
76
|
+
|
77
|
+
@staticmethod
|
78
|
+
def from_dict(data: dict) -> "RemoteFile":
|
79
|
+
"""Create a RemoteFile from a dictionary."""
|
80
|
+
return RemoteFile(
|
81
|
+
data["Path"],
|
82
|
+
data["Name"],
|
83
|
+
data["Size"],
|
84
|
+
data["MimeType"],
|
85
|
+
data["ModTime"],
|
86
|
+
data["IsDir"],
|
87
|
+
# data["IsBucket"],
|
88
|
+
)
|
89
|
+
|
90
|
+
@staticmethod
|
91
|
+
def from_array(data: list[dict]) -> list["RemoteFile"]:
|
92
|
+
"""Create a RemoteFile from a dictionary."""
|
93
|
+
out: list[RemoteFile] = []
|
94
|
+
for d in data:
|
95
|
+
file: RemoteFile = RemoteFile.from_dict(d)
|
96
|
+
out.append(file)
|
97
|
+
return out
|
98
|
+
|
99
|
+
@staticmethod
|
100
|
+
def from_json_str(json_str: str) -> list["RemoteFile"]:
|
101
|
+
"""Create a RemoteFile from a JSON string."""
|
102
|
+
json_obj = json.loads(json_str)
|
103
|
+
if isinstance(json_obj, dict):
|
104
|
+
return [RemoteFile.from_dict(json_obj)]
|
105
|
+
return RemoteFile.from_array(json_obj)
|
106
|
+
|
107
|
+
def to_json(self) -> dict:
|
108
|
+
return {
|
109
|
+
"Path": self.path,
|
110
|
+
"Name": self.name,
|
111
|
+
"Size": self.size,
|
112
|
+
"MimeType": self.mime_type,
|
113
|
+
"ModTime": self.mod_time,
|
114
|
+
"IsDir": self.is_dir,
|
115
|
+
# "IsBucket": self.is_bucket,
|
116
|
+
}
|
117
|
+
|
118
|
+
def __str__(self) -> str:
|
119
|
+
out = self.to_json()
|
120
|
+
return json.dumps(out)
|
121
|
+
|
122
|
+
|
123
|
+
def _get_rclone_exe(rclone_exe: Path | None) -> Path:
|
124
|
+
if rclone_exe is None:
|
125
|
+
|
126
|
+
rclone_which_path = shutil.which("rclone")
|
127
|
+
if rclone_which_path is None:
|
128
|
+
raise ValueError("rclone executable not found")
|
129
|
+
return Path(rclone_which_path)
|
130
|
+
return rclone_exe
|
131
|
+
|
132
|
+
|
133
|
+
class Rclone:
|
134
|
+
def __init__(
|
135
|
+
self, rclone_conf: Path | RcloneConfig, rclone_exe: Path | None = None
|
136
|
+
) -> None:
|
137
|
+
if isinstance(rclone_conf, Path):
|
138
|
+
if not rclone_conf.exists():
|
139
|
+
raise ValueError(f"Rclone config file not found: {rclone_conf}")
|
140
|
+
self._exec = RcloneExec(rclone_conf, _get_rclone_exe(rclone_exe))
|
141
|
+
|
142
|
+
def _run(self, cmd: list[str]) -> subprocess.CompletedProcess:
|
143
|
+
return self._exec.execute(cmd)
|
144
|
+
|
145
|
+
def ls(self, path: str) -> list[RemoteFile]:
|
146
|
+
cmd = ["lsjson", path]
|
147
|
+
cp = self._run(cmd)
|
148
|
+
text = cp.stdout
|
149
|
+
out: list[RemoteFile] = RemoteFile.from_json_str(text)
|
150
|
+
return out
|
151
|
+
|
152
|
+
def listremotes(self) -> list[str]:
|
153
|
+
cmd = ["listremotes"]
|
154
|
+
cp = self._run(cmd)
|
155
|
+
text = cp.stdout
|
156
|
+
out = text.splitlines()
|
157
|
+
out = [o.strip() for o in out]
|
158
|
+
# strip out ":" from the end
|
159
|
+
out = [o.replace(":", "") for o in out]
|
160
|
+
return out
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: rclone_api
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: rclone api in python
|
5
|
+
Home-page: https://github.com/zackees/rclone-api
|
6
|
+
Maintainer: Zachary Vorhies
|
7
|
+
License: BSD 3-Clause License
|
8
|
+
Keywords: template-python-cmd
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Requires-Python: >=3.7
|
11
|
+
Description-Content-Type: text/markdown
|
12
|
+
License-File: LICENSE
|
13
|
+
Dynamic: home-page
|
14
|
+
Dynamic: maintainer
|
15
|
+
|
16
|
+
# template-python-cmd
|
17
|
+
A template for quickly making a python lib that has a command line program attached
|
18
|
+
|
19
|
+
[](../../actions/workflows/lint.yml)
|
20
|
+
|
21
|
+
[](../../actions/workflows/push_macos.yml)
|
22
|
+
[](../../actions/workflows/push_ubuntu.yml)
|
23
|
+
[](../../actions/workflows/push_win.yml)
|
24
|
+
|
25
|
+
Replace `template-python-cmd` and `template_python_cmd` with your command. Run tox until it's
|
26
|
+
correct.
|
27
|
+
|
28
|
+
To develop software, run `. ./activate.sh`
|
29
|
+
|
30
|
+
# Windows
|
31
|
+
|
32
|
+
This environment requires you to use `git-bash`.
|
33
|
+
|
34
|
+
# Linting
|
35
|
+
|
36
|
+
Run `./lint.sh` to find linting errors using `pylint`, `flake8` and `mypy`.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
LICENSE
|
2
|
+
MANIFEST.in
|
3
|
+
README.md
|
4
|
+
pyproject.toml
|
5
|
+
requirements.testing.txt
|
6
|
+
setup.py
|
7
|
+
src/rclone_api/__init__.py
|
8
|
+
src/rclone_api/cli.py
|
9
|
+
src/rclone_api/rclone.py
|
10
|
+
src/rclone_api.egg-info/PKG-INFO
|
11
|
+
src/rclone_api.egg-info/SOURCES.txt
|
12
|
+
src/rclone_api.egg-info/dependency_links.txt
|
13
|
+
src/rclone_api.egg-info/top_level.txt
|
14
|
+
src/rclone_api/assets/example.txt
|
15
|
+
tests/test_simple.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
rclone_api
|