efs-cli 1.0.7__tar.gz → 1.0.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: efs-cli
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: EepyFileServer API CLI written in Python
5
5
  Author: maxie
6
6
  License-Expression: MIT
@@ -0,0 +1,2 @@
1
+ __version__ = "1.0.8"
2
+
@@ -10,6 +10,17 @@ CONFIG_PATH = os.path.expanduser("~/.efs-cli_config.json")
10
10
  if os.path.exists(os.path.expanduser("~/.config/")):
11
11
  CONFIG_PATH = os.path.expanduser("~/.config/efs-cli.json")
12
12
 
13
+ def exception_handler(func):
14
+ def wrapper(*args, **kwargs):
15
+ try:
16
+ func(*args, **kwargs)
17
+ except Exception as exc:
18
+ if isinstance(exc.args[1], int):
19
+ print(f"Error: {exc.args[0]}")
20
+ sys.exit(1)
21
+ print(f"Error: {exc.__class__.__name__}: {exc}")
22
+ return wrapper
23
+
13
24
  def get_conf():
14
25
  conf = None
15
26
 
@@ -31,14 +42,18 @@ def init_api():
31
42
  efs = EepyFileServerPublic(base_url, ignore_initialization = True) if password is None else EepyFileServer(base_url, password, ignore_initialization = True)
32
43
  return efs
33
44
 
45
+ @exception_handler
34
46
  def auth(base_url, password, **__):
35
47
  data = {"base_url": base_url, "password": password}
36
48
  with open(CONFIG_PATH, "w") as file:
37
49
  json.dump(data, file)
38
50
  print("Saved eepyfileserver password and base url in config.json")
39
51
 
52
+ @exception_handler
40
53
  def download(from_path, to_path, public, **__):
41
54
  api = init_api()
55
+ if to_path is None:
56
+ to_path = from_path.split("/")[-1]
42
57
  if public and not isinstance(api, EepyFileServerPublic):
43
58
  api = api.public
44
59
  if from_path.startswith("/public"):
@@ -47,11 +62,13 @@ def download(from_path, to_path, public, **__):
47
62
  file.fetch_file().save(to_path)
48
63
  print(f"Downloaded {from_path} to {to_path}")
49
64
 
65
+ @exception_handler
50
66
  def read(file_path, **__):
51
67
  api = init_api()
52
68
  file = api.get_file(file_path)
53
69
  print(file.fetch_file().load().decode("utf-8"))
54
70
 
71
+ @exception_handler
55
72
  def upload(from_path, to_path, **__):
56
73
  api = init_api()
57
74
  if hasattr(api, "upload_file"):
@@ -62,10 +79,12 @@ def upload(from_path, to_path, **__):
62
79
  print("Login using 'efs-cli auth <base url> <password>' to upload files")
63
80
  sys.exit(1)
64
81
 
82
+ @exception_handler
65
83
  def list_files(**__):
66
84
  api = init_api()
67
85
  print(api.get_filelist())
68
86
 
87
+ @exception_handler
69
88
  def remove(file_path, **__):
70
89
  api = init_api()
71
90
  if hasattr(api, "delete_file"):
@@ -75,6 +94,7 @@ def remove(file_path, **__):
75
94
  print("Login using 'efs-cli auth <base url> <password>' to delete files")
76
95
  sys.exit(1)
77
96
 
97
+ @exception_handler
78
98
  def ver(**__):
79
99
  conf = get_conf()
80
100
  print(f"efs-cli: {version}")
@@ -83,6 +103,7 @@ def ver(**__):
83
103
  api = init_api()
84
104
  print(f"EepyFileServer ({conf['base_url']}): {api.get_instance_info()['instance']['version']}")
85
105
 
106
+ @exception_handler
86
107
  def instance(**__):
87
108
  api = init_api()
88
109
  instance_info = api.get_instance_info()["instance"]
@@ -94,6 +115,7 @@ def instance(**__):
94
115
  print(f" Used : {disk_usage.human.used} Megabytes")
95
116
  print(f" Free : {disk_usage.human.free} Megabytes")
96
117
 
118
+ @exception_handler
97
119
  def url_for(file_path, public, check_if_exists, **__):
98
120
  api = init_api()
99
121
  if public and not isinstance(api, EepyFileServerPublic):
@@ -106,6 +128,7 @@ def url_for(file_path, public, check_if_exists, **__):
106
128
  print(e.args[0])
107
129
  sys.exit(1)
108
130
 
131
+ @exception_handler
109
132
  def overwrite(from_path, to_path, **__):
110
133
  api = init_api()
111
134
  if hasattr(api, "overwrite_file"):
@@ -116,6 +139,7 @@ def overwrite(from_path, to_path, **__):
116
139
  print("Login using 'efs-cli auth <base url> <password>' to delete files")
117
140
  sys.exit(1)
118
141
 
142
+ @exception_handler
119
143
  def metadata(path, public, **__):
120
144
  api = init_api()
121
145
  if public and not isinstance(api, EepyFileServerPublic):
@@ -142,7 +166,7 @@ def main():
142
166
 
143
167
  download_parser = subparser.add_parser("download", help="download a file", aliases=["get", "d"])
144
168
  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")
169
+ download_parser.add_argument("to_path", nargs="?", help="the local path to download the file to")
146
170
  download_parser.add_argument("-p", "--public", action="store_true", help="use a public url if set")
147
171
  download_parser.set_defaults(func=download)
148
172
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: efs-cli
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Summary: EepyFileServer API CLI written in Python
5
5
  Author: maxie
6
6
  License-Expression: MIT
@@ -1,2 +0,0 @@
1
- __version__ = "1.0.7"
2
-
File without changes
File without changes
File without changes
File without changes