efs-cli 1.0.9__tar.gz → 1.1.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.
- {efs_cli-1.0.9 → efs_cli-1.1.0}/PKG-INFO +1 -1
- efs_cli-1.1.0/src/efs_cli/__init__.py +2 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/src/efs_cli/cli.py +85 -7
- {efs_cli-1.0.9 → efs_cli-1.1.0}/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.0}/LICENSE +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/README.md +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/pyproject.toml +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/setup.cfg +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/src/efs_cli.egg-info/SOURCES.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/src/efs_cli.egg-info/dependency_links.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/src/efs_cli.egg-info/entry_points.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/src/efs_cli.egg-info/requires.txt +0 -0
- {efs_cli-1.0.9 → efs_cli-1.1.0}/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,8 +37,8 @@ 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,11 +46,55 @@ def init_api():
|
|
|
45
46
|
efs = EepyFileServerPublic(base_url, ignore_initialization = True) if password is None else EepyFileServer(base_url, password, ignore_initialization = True)
|
|
46
47
|
return efs
|
|
47
48
|
|
|
49
|
+
@exception_handler
|
|
50
|
+
def config(reset, **__):
|
|
51
|
+
conf = get_conf()
|
|
52
|
+
if conf is None or reset:
|
|
53
|
+
with open(CONFIG_PATH, "w") as file:
|
|
54
|
+
json.dump({"base_url": None, "password": None, "editor": "nano"}, file)
|
|
55
|
+
if reset:
|
|
56
|
+
print("Config reset")
|
|
57
|
+
sys.exit(0)
|
|
58
|
+
editor = conf.get("editor", "nano")
|
|
59
|
+
|
|
60
|
+
status = os.system(f"{editor} {CONFIG_PATH}")
|
|
61
|
+
if status:
|
|
62
|
+
print("using default editor: nano")
|
|
63
|
+
os.system(f"nano {CONFIG_PATH}")
|
|
64
|
+
print("Config saved successfully")
|
|
65
|
+
|
|
66
|
+
@exception_handler
|
|
67
|
+
def efs_config(verbose, **__):
|
|
68
|
+
conf = get_conf()
|
|
69
|
+
api = init_api()
|
|
70
|
+
editor = conf.get("editor", "nano")
|
|
71
|
+
if not hasattr(api, "get_config"):
|
|
72
|
+
print("Login using 'efs-cli auth <base url> <password>' to get the config")
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
data = api.get_config()
|
|
75
|
+
with NamedTemporaryFile(suffix = ".json", mode="w+") as tmp:
|
|
76
|
+
json.dump(data, tmp)
|
|
77
|
+
tmp.seek(0)
|
|
78
|
+
status = os.system(f"{editor} {tmp.name}")
|
|
79
|
+
if status:
|
|
80
|
+
print("using default editor: nano")
|
|
81
|
+
os.system(f"nano {tmp.name}")
|
|
82
|
+
api.update_config(json.load(tmp), _print_warnings = verbose)
|
|
83
|
+
print("Config saved successfully")
|
|
84
|
+
|
|
48
85
|
@exception_handler
|
|
49
86
|
def auth(base_url, password, **__):
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
87
|
+
conf = get_conf()
|
|
88
|
+
data = {"base_url": base_url, "password": password, "editor": "nano"}
|
|
89
|
+
|
|
90
|
+
if conf is not None:
|
|
91
|
+
conf.update(data)
|
|
92
|
+
with open(CONFIG_PATH, "w") as file:
|
|
93
|
+
json.dump(conf, file)
|
|
94
|
+
|
|
95
|
+
else:
|
|
96
|
+
with open(CONFIG_PATH, "w") as file:
|
|
97
|
+
json.dump(data, file)
|
|
53
98
|
print("Saved eepyfileserver password and base url in config.json")
|
|
54
99
|
|
|
55
100
|
@exception_handler
|
|
@@ -66,11 +111,11 @@ def download(from_path, to_path, public, **__):
|
|
|
66
111
|
print(f"Downloaded {from_path} to {to_path}")
|
|
67
112
|
|
|
68
113
|
@exception_handler
|
|
69
|
-
def read(file_path, **__):
|
|
114
|
+
def read(file_path, no_less, **__):
|
|
70
115
|
api = init_api()
|
|
71
116
|
file = api.get_file(file_path)
|
|
72
117
|
_file = file.fetch_file()
|
|
73
|
-
if sys.platform in ["linux", "darwin"]:
|
|
118
|
+
if sys.platform in ["linux", "darwin"] and not no_less:
|
|
74
119
|
with NamedTemporaryFile() as tmp:
|
|
75
120
|
tmp.write(_file.load())
|
|
76
121
|
tmp.seek(0)
|
|
@@ -78,6 +123,26 @@ def read(file_path, **__):
|
|
|
78
123
|
else:
|
|
79
124
|
print(_file.load().decode("utf-8"))
|
|
80
125
|
|
|
126
|
+
@exception_handler
|
|
127
|
+
def edit(file_path, **__):
|
|
128
|
+
api = init_api()
|
|
129
|
+
conf = get_conf()
|
|
130
|
+
editor = conf.get("editor", "nano")
|
|
131
|
+
if not hasattr(api, "overwrite_file"):
|
|
132
|
+
print("Login using 'efs-cli auth <base url> <password>' to overwrite files")
|
|
133
|
+
sys.exit(1)
|
|
134
|
+
file = api.get_file(file_path)
|
|
135
|
+
_file = file.fetch_file()
|
|
136
|
+
with NamedTemporaryFile(suffix = "".join(pathlib.Path(file_path).suffixes)) as tmp:
|
|
137
|
+
tmp.write(_file.load())
|
|
138
|
+
tmp.seek(0)
|
|
139
|
+
status = os.system(f"{editor} {tmp.name}")
|
|
140
|
+
if status:
|
|
141
|
+
print("using default editor: nano")
|
|
142
|
+
os.system(f"nano {tmp.name}")
|
|
143
|
+
api.overwrite_file(file_path, tmp)
|
|
144
|
+
print(f"{file_path} overwritten")
|
|
145
|
+
|
|
81
146
|
@exception_handler
|
|
82
147
|
def upload(from_path, to_path, **__):
|
|
83
148
|
api = init_api()
|
|
@@ -182,6 +247,7 @@ def main():
|
|
|
182
247
|
|
|
183
248
|
read_parser = subparser.add_parser("read", help="read a file", aliases=["cat"])
|
|
184
249
|
read_parser.add_argument("file_path", help="the efs path of the file to read")
|
|
250
|
+
read_parser.add_argument("-n", "--no-less", action="store_true", help="just print out the file contents if set")
|
|
185
251
|
read_parser.set_defaults(func=read)
|
|
186
252
|
|
|
187
253
|
upload_parser = subparser.add_parser("upload", help="upload a file", aliases=["post", "up", "put"])
|
|
@@ -218,6 +284,18 @@ def main():
|
|
|
218
284
|
urlfor_parser.add_argument("-c", "--check-if-exists", action="store_true", help="check if the file exists before returning the url")
|
|
219
285
|
urlfor_parser.set_defaults(func=url_for)
|
|
220
286
|
|
|
287
|
+
config_parser = subparser.add_parser("cli-config", help="view or change your cli config", aliases=["conf"])
|
|
288
|
+
config_parser.add_argument("--reset", action="store_true", help="if set, resets your ENTIRE config")
|
|
289
|
+
config_parser.set_defaults(func=config)
|
|
290
|
+
|
|
291
|
+
efs_config_parser = subparser.add_parser("efs-config", help="view or change your eepyfileserver config", aliases=["efs-conf"])
|
|
292
|
+
efs_config_parser.add_argument("-v", "--verbose", action="store_true", help="prints info out if a key is not changed")
|
|
293
|
+
efs_config_parser.set_defaults(func=efs_config)
|
|
294
|
+
|
|
295
|
+
edit_parser = subparser.add_parser("edit", help="edit your files on efs remotely")
|
|
296
|
+
edit_parser.add_argument("file_path", help="the efs file path to edit")
|
|
297
|
+
edit_parser.set_defaults(func=edit)
|
|
298
|
+
|
|
221
299
|
args = parser.parse_args()
|
|
222
300
|
if args == Namespace():
|
|
223
301
|
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
|