efs-cli 1.1.2__tar.gz → 1.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: efs-cli
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: EepyFileServer API CLI written in Python
5
5
  Author: maxie
6
6
  License-Expression: MIT
@@ -17,7 +17,7 @@ Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: requests>=2.30
20
- Requires-Dist: efs-wrapper>=1.0.6
20
+ Requires-Dist: efs-wrapper>=1.1.0
21
21
  Dynamic: license-file
22
22
 
23
23
  # efs-cli (formerly eepyfileserver-cli)
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools >= 77.0.3", "requests >= 2.30", "efs-wrapper >= 1.0.6"]
2
+ requires = ["setuptools >= 77.0.3", "requests >= 2.30", "efs-wrapper >= 1.1.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
@@ -12,7 +12,7 @@ readme = "README.md"
12
12
  requires-python = ">=3.10"
13
13
  dependencies = [
14
14
  "requests >= 2.30",
15
- "efs-wrapper >= 1.0.6"
15
+ "efs-wrapper >= 1.1.0"
16
16
  ]
17
17
  classifiers = [
18
18
  "Programming Language :: Python :: 3",
@@ -0,0 +1,2 @@
1
+ __version__ = "1.2.0"
2
+
@@ -16,6 +16,9 @@ def exception_handler(func):
16
16
  def wrapper(*args, **kwargs):
17
17
  try:
18
18
  func(*args, **kwargs)
19
+ except KeyError:
20
+ print("Error: no such file or directory")
21
+ sys.exit(1)
19
22
  except Exception as exc:
20
23
  if len(exc.args) == 2:
21
24
  if isinstance(exc.args[1], int):
@@ -70,7 +73,7 @@ def efs_config(verbose, **__):
70
73
  api = init_api()
71
74
  editor = conf.get("editor", "nano")
72
75
  if not hasattr(api, "get_config"):
73
- print("Login using 'efs-cli auth <base url> <password>' to get the config")
76
+ print("Login using 'efs-cli auth <base url> <root_password>' to get and change the config")
74
77
  sys.exit(1)
75
78
  data = api.get_config()
76
79
  with NamedTemporaryFile(suffix = ".json", mode="w+") as tmp:
@@ -229,15 +232,51 @@ def metadata(path, public, **__):
229
232
  api = api.public
230
233
  if path.startswith("/public"):
231
234
  path = path.removeprefix("/public")
232
- if api.is_file(path):
235
+ if api.is_file(path, check_if_exists = True):
233
236
  print(api.get_file(path).metadata.to_dict())
234
- return
235
- if api.is_directory(path):
237
+ sys.exit(0)
238
+ if api.is_directory(path, check_if_exists = True):
236
239
  print(api.get_tree(path))
237
- return
240
+ sys.exit(0)
238
241
  print(f"{path} does not exist or is not a file or a directory")
239
242
  sys.exit(1)
240
243
 
244
+ def list_users(**__):
245
+ api = init_api()
246
+ if not hasattr(api, "get_users"):
247
+ print("Login using efs-cli auth <base url> <password> to list users")
248
+ sys.exit(1)
249
+ for password, values in api.get_users().items():
250
+ dir, perms = values["directory"], values["permissions"]
251
+ print(f"[{dir}] {password}:")
252
+ print(f" Directory: {dir}")
253
+ print(f" Permissions: {perms}")
254
+
255
+ def add_user(directory, permissions, **__):
256
+ api = init_api()
257
+ if not hasattr(api, "add_user"):
258
+ print("Login using efs-cli auth <base url> <root_password> to add users")
259
+ sys.exit(1)
260
+ out = api.add_user(directory, permissions)
261
+ print(f"Added user with directory of '{directory}' and permissions '{permissions}'")
262
+ print(f"User password: {out['password']}")
263
+
264
+ def change_user(password, directory, permissions, **__):
265
+ api = init_api()
266
+ if not hasattr(api, "change_user"):
267
+ print("Login using efs-cli auth <base url> <root_password> to change users")
268
+ sys.exit(1)
269
+ api.change_user(password, directory, permissions)
270
+ print("Changed user directory or/and permissions")
271
+
272
+ def remove_user(password, remove_dir, **__):
273
+ api = init_api()
274
+ if not hasattr(api, "remove_user"):
275
+ print("Login using efs-cli auth <base url> <root_password> to remove users")
276
+ sys.exit(1)
277
+ api.remove_user(password, remove_dir)
278
+ print("User deleted")
279
+
241
280
  def main():
242
281
  parser = ArgumentParser("efs-cli", description="eepyfileserver cli tool for downloading and uploading files")
243
282
  subparser = parser.add_subparsers()
@@ -306,6 +345,25 @@ def main():
306
345
  edit_parser.add_argument("file_path", help="the efs file path to edit")
307
346
  edit_parser.set_defaults(func=edit)
308
347
 
348
+ list_users_parser = subparser.add_parser("users", help="view current users on your eepyfileserver instance", aliases=["listusers", "lsu"])
349
+ list_users_parser.set_defaults(func=list_users)
350
+
351
+ add_user_parser = subparser.add_parser("adduser", help="add a user to your eepyfileserver instance", aliases=["auser", "au"])
352
+ add_user_parser.add_argument("directory", help="the name of their directory on eepyfileserver")
353
+ add_user_parser.add_argument("permissions", help="permissions they will have on their directory" , choices=["rw", "ro"])
354
+ add_user_parser.set_defaults(func=add_user)
355
+
356
+ change_user_parser = subparser.add_parser("changeuser", help="change a user directory or permissions on your eepyfileserver instance", aliases=["chuser", "chu"])
357
+ change_user_parser.add_argument("password", help="a password of a user on eepyfileserver")
358
+ change_user_parser.add_argument("directory", help="the name of their directory on eepyfileserver")
359
+ change_user_parser.add_argument("permissions", help="permissions they will have on their directory" , choices=["rw", "ro"])
360
+ change_user_parser.set_defaults(func=change_user)
361
+
362
+ remove_user_parser = subparser.add_parser("removeuser", help="remove a user from your eepyfileserver instance", aliases=["ru", "rmuser"])
363
+ remove_user_parser.add_argument("password", help="a password of a user on eepyfileserver")
364
+ remove_user_parser.add_argument("-r", "--remove-dir", action="store_true", help="deletes the user directory entirely if set")
365
+ remove_user_parser.set_defaults(func=remove_user)
366
+
309
367
  args = parser.parse_args()
310
368
  if args == Namespace():
311
369
  args = parser.parse_args(["-h"])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: efs-cli
3
- Version: 1.1.2
3
+ Version: 1.2.0
4
4
  Summary: EepyFileServer API CLI written in Python
5
5
  Author: maxie
6
6
  License-Expression: MIT
@@ -17,7 +17,7 @@ Requires-Python: >=3.10
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: requests>=2.30
20
- Requires-Dist: efs-wrapper>=1.0.6
20
+ Requires-Dist: efs-wrapper>=1.1.0
21
21
  Dynamic: license-file
22
22
 
23
23
  # efs-cli (formerly eepyfileserver-cli)
@@ -0,0 +1,2 @@
1
+ requests>=2.30
2
+ efs-wrapper>=1.1.0
@@ -1,2 +0,0 @@
1
- __version__ = "1.1.2"
2
-
@@ -1,2 +0,0 @@
1
- requests>=2.30
2
- efs-wrapper>=1.0.6
File without changes
File without changes
File without changes