efs-cli 1.2.1__tar.gz → 1.2.3__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.2.1
3
+ Version: 1.2.3
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.2.3"
2
+
@@ -2,6 +2,7 @@ from . import __version__ as version
2
2
  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
+ from shutil import which
5
6
  import os
6
7
  import pathlib
7
8
  from tempfile import NamedTemporaryFile
@@ -12,6 +13,8 @@ CONFIG_PATH = os.path.expanduser("~/.efs-cli_config.json")
12
13
  if os.path.exists(os.path.expanduser("~/.config/")):
13
14
  CONFIG_PATH = os.path.expanduser("~/.config/efs-cli.json")
14
15
 
16
+ DEFAULT_EDITOR = "nano"
17
+
15
18
  def exception_handler(func):
16
19
  def wrapper(*args, **kwargs):
17
20
  try:
@@ -36,10 +39,14 @@ def get_conf():
36
39
  conf = json.load(file)
37
40
 
38
41
  if conf:
39
- editor = conf.get("editor", "nano")
40
- if "sudo" in editor or "rm" in editor or "rm -rf" in editor:
41
- print("there cannot be 'sudo', 'rm' or 'rm -rf' in the editor command")
42
- sys.exit(1)
42
+ editor = conf.get("editor", DEFAULT_EDITOR)
43
+ editor = editor.split(" ")[0]
44
+ if which(editor):
45
+ conf.update({"editor": editor})
46
+ else:
47
+ print("editor path does not exist")
48
+ print(f"using default editor, {DEFAULT_EDITOR}")
49
+ conf.update({"editor": DEFAULT_EDITOR})
43
50
 
44
51
  return conf
45
52
 
@@ -64,23 +71,23 @@ def config(reset, **__):
64
71
  conf = get_conf()
65
72
  if conf is None or reset:
66
73
  with open(CONFIG_PATH, "w") as file:
67
- json.dump({"base_url": None, "password": None, "custom_api_path": "/api/v1", "editor": "nano"}, file)
74
+ json.dump({"base_url": None, "password": None, "custom_api_path": "/api/v1", "editor": DEFAULT_EDITOR}, file)
68
75
  if reset:
69
76
  print("Config reset")
70
77
  sys.exit(0)
71
- editor = conf.get("editor", "nano")
78
+ editor = conf.get("editor", DEFAULT_EDITOR)
72
79
 
73
80
  status = os.system(f"{editor} {CONFIG_PATH}")
74
81
  if status:
75
- print("using default editor: nano")
76
- os.system(f"nano {CONFIG_PATH}")
82
+ print(f"using default editor: {DEFAULT_EDITOR}")
83
+ os.system(f"{DEFAULT_EDITOR} {CONFIG_PATH}")
77
84
  print("Config saved successfully")
78
85
 
79
86
  @exception_handler
80
87
  def efs_config(verbose, **__):
81
88
  conf = get_conf()
82
89
  api = init_api()
83
- editor = conf.get("editor", "nano")
90
+ editor = conf.get("editor", DEFAULT_EDITOR)
84
91
  if not hasattr(api, "get_config"):
85
92
  print("Login using 'efs-cli auth <base url> <root_password>' to get and change the config")
86
93
  sys.exit(1)
@@ -90,8 +97,8 @@ def efs_config(verbose, **__):
90
97
  tmp.seek(0)
91
98
  status = os.system(f"{editor} {tmp.name}")
92
99
  if status:
93
- print("using default editor: nano")
94
- os.system(f"nano {tmp.name}")
100
+ print(f"using default editor: {DEFAULT_EDITOR}")
101
+ os.system(f"{DEFAULT_EDITOR} {tmp.name}")
95
102
  api.update_config(json.load(tmp), _print_warnings = verbose)
96
103
  print("Config saved successfully")
97
104
 
@@ -105,7 +112,7 @@ def auth(base_url, password, custom_api_path, **__):
105
112
  if base_url.endswith("/"):
106
113
  base_url = base_url[:-1]
107
114
 
108
- data = {"base_url": base_url, "password": password, "custom_api_path": custom_api_path, "editor": "nano"}
115
+ data = {"base_url": base_url, "password": password, "custom_api_path": custom_api_path, "editor": DEFAULT_EDITOR}
109
116
 
110
117
  if conf is not None:
111
118
  conf.update(data)
@@ -147,7 +154,7 @@ def read(file_path, no_less, **__):
147
154
  def edit(file_path, **__):
148
155
  api = init_api()
149
156
  conf = get_conf()
150
- editor = conf.get("editor", "nano")
157
+ editor = conf.get("editor", DEFAULT_EDITOR)
151
158
  if not hasattr(api, "overwrite_file"):
152
159
  print("Login using 'efs-cli auth <base url> <password>' to overwrite files")
153
160
  sys.exit(1)
@@ -158,8 +165,8 @@ def edit(file_path, **__):
158
165
  tmp.seek(0)
159
166
  status = os.system(f"{editor} {tmp.name}")
160
167
  if status:
161
- print("using default editor: nano")
162
- os.system(f"nano {tmp.name}")
168
+ print(f"using default editor: {DEFAULT_EDITOR}")
169
+ os.system(f"{DEFAULT_EDITOR} {tmp.name}")
163
170
  api.overwrite_file(file_path, tmp)
164
171
  print(f"{file_path} overwritten")
165
172
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: efs-cli
3
- Version: 1.2.1
3
+ Version: 1.2.3
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.2.1"
2
-
File without changes
File without changes
File without changes
File without changes