efs-cli 1.0.9__tar.gz → 1.1.1__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.
- {efs_cli-1.0.9 → efs_cli-1.1.1}/PKG-INFO +1 -1
- efs_cli-1.1.1/src/efs_cli/__init__.py +2 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli/cli.py +96 -9
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/PKG-INFO +1 -1
- efs_cli-1.0.9/src/efs_cli/__init__.py +0 -2
- {efs_cli-1.0.9 → efs_cli-1.1.1}/LICENSE +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/README.md +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/pyproject.toml +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/setup.cfg +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/SOURCES.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/dependency_links.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/entry_points.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/requires.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.1}/src/efs_cli.egg-info/top_level.txt +0 -0
|
@@ -3,6 +3,7 @@ from efs_wrapper import __version__ as wrapper_version
|
|
|
3
3
|
from efs_wrapper.v1 import EepyFileServer, EepyFileServerPublic, DiskUsageObject
|
|
4
4
|
from argparse import ArgumentParser, Namespace
|
|
5
5
|
import os
|
|
6
|
+
import pathlib
|
|
6
7
|
from tempfile import NamedTemporaryFile
|
|
7
8
|
import json
|
|
8
9
|
import sys
|
|
@@ -36,20 +37,72 @@ def get_conf():
|
|
|
36
37
|
def init_api():
|
|
37
38
|
conf = get_conf()
|
|
38
39
|
|
|
39
|
-
if conf is None:
|
|
40
|
-
print("Please authorize with 'efs-cli auth <base_url> <password>'")
|
|
40
|
+
if conf is None or conf.get("base_url", None) is None:
|
|
41
|
+
print("Please authorize with 'efs-cli auth <base_url> <password> (password is optional but you will be able only to read and download public files)'")
|
|
41
42
|
sys.exit(1)
|
|
42
43
|
|
|
43
44
|
base_url = conf.get("base_url")
|
|
45
|
+
custom_api_path = conf.get("custom_api_path", "/api/v1")
|
|
44
46
|
password = conf.get("password", None)
|
|
45
|
-
efs = EepyFileServerPublic(base_url, ignore_initialization = True) if password is None else EepyFileServer(base_url, password, ignore_initialization = True)
|
|
47
|
+
efs = EepyFileServerPublic(base_url, custom_api_path, ignore_initialization = True) if password is None else EepyFileServer(base_url, password, custom_api_path, ignore_initialization = True)
|
|
46
48
|
return efs
|
|
47
49
|
|
|
48
50
|
@exception_handler
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
def config(reset, **__):
|
|
52
|
+
conf = get_conf()
|
|
53
|
+
if conf is None or reset:
|
|
54
|
+
with open(CONFIG_PATH, "w") as file:
|
|
55
|
+
json.dump({"base_url": None, "password": None, "custom_api_path": "/api/v1", "editor": "nano"}, file)
|
|
56
|
+
if reset:
|
|
57
|
+
print("Config reset")
|
|
58
|
+
sys.exit(0)
|
|
59
|
+
editor = conf.get("editor", "nano")
|
|
60
|
+
|
|
61
|
+
status = os.system(f"{editor} {CONFIG_PATH}")
|
|
62
|
+
if status:
|
|
63
|
+
print("using default editor: nano")
|
|
64
|
+
os.system(f"nano {CONFIG_PATH}")
|
|
65
|
+
print("Config saved successfully")
|
|
66
|
+
|
|
67
|
+
@exception_handler
|
|
68
|
+
def efs_config(verbose, **__):
|
|
69
|
+
conf = get_conf()
|
|
70
|
+
api = init_api()
|
|
71
|
+
editor = conf.get("editor", "nano")
|
|
72
|
+
if not hasattr(api, "get_config"):
|
|
73
|
+
print("Login using 'efs-cli auth <base url> <password>' to get the config")
|
|
74
|
+
sys.exit(1)
|
|
75
|
+
data = api.get_config()
|
|
76
|
+
with NamedTemporaryFile(suffix = ".json", mode="w+") as tmp:
|
|
77
|
+
json.dump(data, tmp)
|
|
78
|
+
tmp.seek(0)
|
|
79
|
+
status = os.system(f"{editor} {tmp.name}")
|
|
80
|
+
if status:
|
|
81
|
+
print("using default editor: nano")
|
|
82
|
+
os.system(f"nano {tmp.name}")
|
|
83
|
+
api.update_config(json.load(tmp), _print_warnings = verbose)
|
|
84
|
+
print("Config saved successfully")
|
|
85
|
+
|
|
86
|
+
@exception_handler
|
|
87
|
+
def auth(base_url, password, custom_api_path, **__):
|
|
88
|
+
conf = get_conf()
|
|
89
|
+
if custom_api_path is None:
|
|
90
|
+
custom_api_path = "/api/v1"
|
|
91
|
+
if custom_api_path.endswith("/"):
|
|
92
|
+
custom_api_path = custom_api_path[:-1]
|
|
93
|
+
if base_url.endswith("/"):
|
|
94
|
+
base_url = base_url[:-1]
|
|
95
|
+
|
|
96
|
+
data = {"base_url": base_url, "password": password, "custom_api_path": custom_api_path, "editor": "nano"}
|
|
97
|
+
|
|
98
|
+
if conf is not None:
|
|
99
|
+
conf.update(data)
|
|
100
|
+
with open(CONFIG_PATH, "w") as file:
|
|
101
|
+
json.dump(conf, file)
|
|
102
|
+
|
|
103
|
+
else:
|
|
104
|
+
with open(CONFIG_PATH, "w") as file:
|
|
105
|
+
json.dump(data, file)
|
|
53
106
|
print("Saved eepyfileserver password and base url in config.json")
|
|
54
107
|
|
|
55
108
|
@exception_handler
|
|
@@ -66,11 +119,11 @@ def download(from_path, to_path, public, **__):
|
|
|
66
119
|
print(f"Downloaded {from_path} to {to_path}")
|
|
67
120
|
|
|
68
121
|
@exception_handler
|
|
69
|
-
def read(file_path, **__):
|
|
122
|
+
def read(file_path, no_less, **__):
|
|
70
123
|
api = init_api()
|
|
71
124
|
file = api.get_file(file_path)
|
|
72
125
|
_file = file.fetch_file()
|
|
73
|
-
if sys.platform in ["linux", "darwin"]:
|
|
126
|
+
if sys.platform in ["linux", "darwin"] and not no_less:
|
|
74
127
|
with NamedTemporaryFile() as tmp:
|
|
75
128
|
tmp.write(_file.load())
|
|
76
129
|
tmp.seek(0)
|
|
@@ -78,6 +131,26 @@ def read(file_path, **__):
|
|
|
78
131
|
else:
|
|
79
132
|
print(_file.load().decode("utf-8"))
|
|
80
133
|
|
|
134
|
+
@exception_handler
|
|
135
|
+
def edit(file_path, **__):
|
|
136
|
+
api = init_api()
|
|
137
|
+
conf = get_conf()
|
|
138
|
+
editor = conf.get("editor", "nano")
|
|
139
|
+
if not hasattr(api, "overwrite_file"):
|
|
140
|
+
print("Login using 'efs-cli auth <base url> <password>' to overwrite files")
|
|
141
|
+
sys.exit(1)
|
|
142
|
+
file = api.get_file(file_path)
|
|
143
|
+
_file = file.fetch_file()
|
|
144
|
+
with NamedTemporaryFile(suffix = "".join(pathlib.Path(file_path).suffixes)) as tmp:
|
|
145
|
+
tmp.write(_file.load())
|
|
146
|
+
tmp.seek(0)
|
|
147
|
+
status = os.system(f"{editor} {tmp.name}")
|
|
148
|
+
if status:
|
|
149
|
+
print("using default editor: nano")
|
|
150
|
+
os.system(f"nano {tmp.name}")
|
|
151
|
+
api.overwrite_file(file_path, tmp)
|
|
152
|
+
print(f"{file_path} overwritten")
|
|
153
|
+
|
|
81
154
|
@exception_handler
|
|
82
155
|
def upload(from_path, to_path, **__):
|
|
83
156
|
api = init_api()
|
|
@@ -172,6 +245,7 @@ def main():
|
|
|
172
245
|
auth_parser = subparser.add_parser("auth", help="authorize to eepyfileserver", aliases=["login"])
|
|
173
246
|
auth_parser.add_argument("base_url", help="the base url of your eepyfileserver instance")
|
|
174
247
|
auth_parser.add_argument("password", nargs="?", help="password to login in your eepyfileserver instance", default=None)
|
|
248
|
+
auth_parser.add_argument("-c", "--custom-api-path", nargs="?", help="custom api path, default is /api/v1", default=None)
|
|
175
249
|
auth_parser.set_defaults(func=auth)
|
|
176
250
|
|
|
177
251
|
download_parser = subparser.add_parser("download", help="download a file", aliases=["get", "d"])
|
|
@@ -182,6 +256,7 @@ def main():
|
|
|
182
256
|
|
|
183
257
|
read_parser = subparser.add_parser("read", help="read a file", aliases=["cat"])
|
|
184
258
|
read_parser.add_argument("file_path", help="the efs path of the file to read")
|
|
259
|
+
read_parser.add_argument("-n", "--no-less", action="store_true", help="just print out the file contents if set")
|
|
185
260
|
read_parser.set_defaults(func=read)
|
|
186
261
|
|
|
187
262
|
upload_parser = subparser.add_parser("upload", help="upload a file", aliases=["post", "up", "put"])
|
|
@@ -218,6 +293,18 @@ def main():
|
|
|
218
293
|
urlfor_parser.add_argument("-c", "--check-if-exists", action="store_true", help="check if the file exists before returning the url")
|
|
219
294
|
urlfor_parser.set_defaults(func=url_for)
|
|
220
295
|
|
|
296
|
+
config_parser = subparser.add_parser("cli-config", help="view or change your cli config", aliases=["conf", "config"])
|
|
297
|
+
config_parser.add_argument("--reset", action="store_true", help="if set, resets your ENTIRE config")
|
|
298
|
+
config_parser.set_defaults(func=config)
|
|
299
|
+
|
|
300
|
+
efs_config_parser = subparser.add_parser("efs-config", help="view or change your eepyfileserver config", aliases=["efs-conf"])
|
|
301
|
+
efs_config_parser.add_argument("-v", "--verbose", action="store_true", help="prints info out if a key is not changed")
|
|
302
|
+
efs_config_parser.set_defaults(func=efs_config)
|
|
303
|
+
|
|
304
|
+
edit_parser = subparser.add_parser("edit", help="edit your files on efs remotely")
|
|
305
|
+
edit_parser.add_argument("file_path", help="the efs file path to edit")
|
|
306
|
+
edit_parser.set_defaults(func=edit)
|
|
307
|
+
|
|
221
308
|
args = parser.parse_args()
|
|
222
309
|
if args == Namespace():
|
|
223
310
|
args = parser.parse_args(["-h"])
|
|
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
|