efs-cli 1.0.7__tar.gz → 1.0.9__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.7 → efs_cli-1.0.9}/PKG-INFO +1 -1
- efs_cli-1.0.9/src/efs_cli/__init__.py +2 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli/cli.py +36 -2
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli.egg-info/PKG-INFO +1 -1
- efs_cli-1.0.7/src/efs_cli/__init__.py +0 -2
- {efs_cli-1.0.7 → efs_cli-1.0.9}/LICENSE +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/README.md +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/pyproject.toml +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/setup.cfg +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli.egg-info/SOURCES.txt +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli.egg-info/dependency_links.txt +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli.egg-info/entry_points.txt +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/src/efs_cli.egg-info/requires.txt +0 -0
- {efs_cli-1.0.7 → efs_cli-1.0.9}/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
|
+
from tempfile import NamedTemporaryFile
|
|
6
7
|
import json
|
|
7
8
|
import sys
|
|
8
9
|
|
|
@@ -10,6 +11,19 @@ CONFIG_PATH = os.path.expanduser("~/.efs-cli_config.json")
|
|
|
10
11
|
if os.path.exists(os.path.expanduser("~/.config/")):
|
|
11
12
|
CONFIG_PATH = os.path.expanduser("~/.config/efs-cli.json")
|
|
12
13
|
|
|
14
|
+
def exception_handler(func):
|
|
15
|
+
def wrapper(*args, **kwargs):
|
|
16
|
+
try:
|
|
17
|
+
func(*args, **kwargs)
|
|
18
|
+
except Exception as exc:
|
|
19
|
+
if len(exc.args) == 2:
|
|
20
|
+
if isinstance(exc.args[1], int):
|
|
21
|
+
print(f"Error: {exc.args[0]}")
|
|
22
|
+
sys.exit(1)
|
|
23
|
+
print(f"Error: {exc.__class__.__name__}: {exc}")
|
|
24
|
+
sys.exit(1)
|
|
25
|
+
return wrapper
|
|
26
|
+
|
|
13
27
|
def get_conf():
|
|
14
28
|
conf = None
|
|
15
29
|
|
|
@@ -31,14 +45,18 @@ def init_api():
|
|
|
31
45
|
efs = EepyFileServerPublic(base_url, ignore_initialization = True) if password is None else EepyFileServer(base_url, password, ignore_initialization = True)
|
|
32
46
|
return efs
|
|
33
47
|
|
|
48
|
+
@exception_handler
|
|
34
49
|
def auth(base_url, password, **__):
|
|
35
50
|
data = {"base_url": base_url, "password": password}
|
|
36
51
|
with open(CONFIG_PATH, "w") as file:
|
|
37
52
|
json.dump(data, file)
|
|
38
53
|
print("Saved eepyfileserver password and base url in config.json")
|
|
39
54
|
|
|
55
|
+
@exception_handler
|
|
40
56
|
def download(from_path, to_path, public, **__):
|
|
41
57
|
api = init_api()
|
|
58
|
+
if to_path is None:
|
|
59
|
+
to_path = from_path.split("/")[-1]
|
|
42
60
|
if public and not isinstance(api, EepyFileServerPublic):
|
|
43
61
|
api = api.public
|
|
44
62
|
if from_path.startswith("/public"):
|
|
@@ -47,11 +65,20 @@ def download(from_path, to_path, public, **__):
|
|
|
47
65
|
file.fetch_file().save(to_path)
|
|
48
66
|
print(f"Downloaded {from_path} to {to_path}")
|
|
49
67
|
|
|
68
|
+
@exception_handler
|
|
50
69
|
def read(file_path, **__):
|
|
51
70
|
api = init_api()
|
|
52
71
|
file = api.get_file(file_path)
|
|
53
|
-
|
|
72
|
+
_file = file.fetch_file()
|
|
73
|
+
if sys.platform in ["linux", "darwin"]:
|
|
74
|
+
with NamedTemporaryFile() as tmp:
|
|
75
|
+
tmp.write(_file.load())
|
|
76
|
+
tmp.seek(0)
|
|
77
|
+
os.system(f"less {tmp.name}")
|
|
78
|
+
else:
|
|
79
|
+
print(_file.load().decode("utf-8"))
|
|
54
80
|
|
|
81
|
+
@exception_handler
|
|
55
82
|
def upload(from_path, to_path, **__):
|
|
56
83
|
api = init_api()
|
|
57
84
|
if hasattr(api, "upload_file"):
|
|
@@ -62,10 +89,12 @@ def upload(from_path, to_path, **__):
|
|
|
62
89
|
print("Login using 'efs-cli auth <base url> <password>' to upload files")
|
|
63
90
|
sys.exit(1)
|
|
64
91
|
|
|
92
|
+
@exception_handler
|
|
65
93
|
def list_files(**__):
|
|
66
94
|
api = init_api()
|
|
67
95
|
print(api.get_filelist())
|
|
68
96
|
|
|
97
|
+
@exception_handler
|
|
69
98
|
def remove(file_path, **__):
|
|
70
99
|
api = init_api()
|
|
71
100
|
if hasattr(api, "delete_file"):
|
|
@@ -75,6 +104,7 @@ def remove(file_path, **__):
|
|
|
75
104
|
print("Login using 'efs-cli auth <base url> <password>' to delete files")
|
|
76
105
|
sys.exit(1)
|
|
77
106
|
|
|
107
|
+
@exception_handler
|
|
78
108
|
def ver(**__):
|
|
79
109
|
conf = get_conf()
|
|
80
110
|
print(f"efs-cli: {version}")
|
|
@@ -83,6 +113,7 @@ def ver(**__):
|
|
|
83
113
|
api = init_api()
|
|
84
114
|
print(f"EepyFileServer ({conf['base_url']}): {api.get_instance_info()['instance']['version']}")
|
|
85
115
|
|
|
116
|
+
@exception_handler
|
|
86
117
|
def instance(**__):
|
|
87
118
|
api = init_api()
|
|
88
119
|
instance_info = api.get_instance_info()["instance"]
|
|
@@ -94,6 +125,7 @@ def instance(**__):
|
|
|
94
125
|
print(f" Used : {disk_usage.human.used} Megabytes")
|
|
95
126
|
print(f" Free : {disk_usage.human.free} Megabytes")
|
|
96
127
|
|
|
128
|
+
@exception_handler
|
|
97
129
|
def url_for(file_path, public, check_if_exists, **__):
|
|
98
130
|
api = init_api()
|
|
99
131
|
if public and not isinstance(api, EepyFileServerPublic):
|
|
@@ -106,6 +138,7 @@ def url_for(file_path, public, check_if_exists, **__):
|
|
|
106
138
|
print(e.args[0])
|
|
107
139
|
sys.exit(1)
|
|
108
140
|
|
|
141
|
+
@exception_handler
|
|
109
142
|
def overwrite(from_path, to_path, **__):
|
|
110
143
|
api = init_api()
|
|
111
144
|
if hasattr(api, "overwrite_file"):
|
|
@@ -116,6 +149,7 @@ def overwrite(from_path, to_path, **__):
|
|
|
116
149
|
print("Login using 'efs-cli auth <base url> <password>' to delete files")
|
|
117
150
|
sys.exit(1)
|
|
118
151
|
|
|
152
|
+
@exception_handler
|
|
119
153
|
def metadata(path, public, **__):
|
|
120
154
|
api = init_api()
|
|
121
155
|
if public and not isinstance(api, EepyFileServerPublic):
|
|
@@ -142,7 +176,7 @@ def main():
|
|
|
142
176
|
|
|
143
177
|
download_parser = subparser.add_parser("download", help="download a file", aliases=["get", "d"])
|
|
144
178
|
download_parser.add_argument("from_path", help="the efs path of the file to download")
|
|
145
|
-
download_parser.add_argument("to_path", help="the local path to download the file to")
|
|
179
|
+
download_parser.add_argument("to_path", nargs="?", help="the local path to download the file to")
|
|
146
180
|
download_parser.add_argument("-p", "--public", action="store_true", help="use a public url if set")
|
|
147
181
|
download_parser.set_defaults(func=download)
|
|
148
182
|
|
|
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
|