naeural-client 2.3.0__py3-none-any.whl → 2.3.2__py3-none-any.whl

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.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.3.0"
1
+ __VER__ = "2.3.2"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
naeural_client/bc/ec.py CHANGED
@@ -480,13 +480,17 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
480
480
  message_hash = self.eth_hash_message(types, values, as_hex=False)
481
481
  signable_message = encode_defunct(primitive=message_hash)
482
482
  signed_message = Account.sign_message(signable_message, private_key=self.eth_account.key)
483
+ if hasattr(signed_message, "message_hash"): # backward compatibility
484
+ signed_message_hash = signed_message.message_hash
485
+ else:
486
+ signed_message_hash = signed_message.messageHash
483
487
  return {
484
488
  "message_hash": message_hash.hex(),
485
489
  "r": hex(signed_message.r),
486
490
  "s": hex(signed_message.s),
487
491
  "v": signed_message.v,
488
492
  "signature": signed_message.signature.hex(),
489
- "signed_message": signed_message.message_hash.hex(),
493
+ "signed_message": signed_message_hash.hex(),
490
494
  "sender" : self.eth_address,
491
495
  }
492
496
 
naeural_client/cli/cli.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import argparse
2
2
 
3
- from naeural_client.utils.config import maybe_init_config
3
+ from naeural_client.utils.config import maybe_init_config, log_with_color
4
4
  from naeural_client.cli.cli_commands import CLI_COMMANDS
5
5
 
6
+ from naeural_client import version
7
+
6
8
  def build_parser():
7
9
  """
8
10
  Dynamically builds the argument parser based on CLI_COMMANDS.
@@ -12,32 +14,77 @@ def build_parser():
12
14
  argparse.ArgumentParser
13
15
  Configured argument parser.
14
16
  """
15
- parser = argparse.ArgumentParser(description="nepctl - CLI for Naeural Edge Protocol SDK package")
17
+ descr = f"nepctl v{version} - CLI for Naeural Edge Protocol SDK package"
18
+ parser = argparse.ArgumentParser(description=descr)
16
19
  subparsers = parser.add_subparsers(dest="command", help="Available commands")
17
20
 
18
- # Iterate over top-level commands
19
21
  for command, subcommands in CLI_COMMANDS.items():
20
22
  command_parser = subparsers.add_parser(command, help=f"{command} commands")
21
- if isinstance(subcommands, dict): # Nested subcommands
23
+
24
+ if isinstance(subcommands, dict) and "func" not in subcommands:
25
+ # Nested subcommands
22
26
  command_subparsers = command_parser.add_subparsers(dest="subcommand")
23
- for subcommand, func in subcommands.items():
27
+ for subcommand, subcmd_info in subcommands.items():
24
28
  subcommand_parser = command_subparsers.add_parser(
25
- subcommand, help=f"{subcommand} command"
29
+ subcommand, help=f"{subcommand} command"
26
30
  )
27
- subcommand_parser.set_defaults(func=func)
31
+ if isinstance(subcmd_info, dict) and "params" in subcmd_info:
32
+ for param, description in subcmd_info["params"].items():
33
+ if param.startswith("--"):
34
+ subcommand_parser.add_argument(
35
+ param, action="store_true", help=description
36
+ )
37
+ else:
38
+ subcommand_parser.add_argument(
39
+ param, help=description
40
+ )
41
+ #end if
42
+ #end for
43
+ #end if
44
+ subcommand_parser.set_defaults(func=subcmd_info["func"])
28
45
  else:
29
- command_parser.set_defaults(func=subcommands)
46
+ # Single-level commands with parameters
47
+ if "params" in subcommands:
48
+ for param, description in subcommands["params"].items():
49
+ if param.startswith("--"):
50
+ command_parser.add_argument(
51
+ param, action="store_true", help=description
52
+ )
53
+ else:
54
+ command_parser.add_argument(
55
+ param, help=description
56
+ )
57
+ #end if
58
+ command_parser.set_defaults(func=subcommands["func"])
30
59
 
31
60
  return parser
32
61
 
62
+
63
+
33
64
  def main():
34
- maybe_init_config()
35
- parser = build_parser()
36
- args = parser.parse_args()
37
- if hasattr(args, "func"):
38
- args.func() # Call the dynamically loaded function
39
- else:
40
- parser.print_help()
65
+ """
66
+ Main entry point for the CLI.
67
+ Ensures the configuration is initialized, builds the parser,
68
+ and executes the appropriate command function.
69
+ """
70
+ try:
71
+ # Initialize configuration if necessary
72
+ maybe_init_config()
73
+
74
+ # Build the CLI parser
75
+ parser = build_parser()
76
+ args = parser.parse_args()
77
+
78
+ # Check if a command function is provided
79
+ if hasattr(args, "func"):
80
+ args.func(args) # Pass parsed arguments to the command function
81
+ else:
82
+ parser.print_help()
83
+
84
+ except Exception as e:
85
+ # Handle unexpected errors gracefully
86
+ print(f"Error: {e}")
87
+
41
88
 
42
89
  if __name__ == "__main__":
43
90
  main()
@@ -1,15 +1,42 @@
1
- from naeural_client.cli.nodes import get_nodes, get_supervisors
1
+ from naeural_client.cli.nodes import (
2
+ get_nodes, get_supervisors,
3
+ restart_node, shutdown_node
4
+ )
2
5
  from naeural_client.utils.config import show_config, reset_config
3
6
 
4
7
 
5
8
  # Define the available commands
6
9
  CLI_COMMANDS = {
7
10
  "get": {
8
- "nodes": get_nodes,
9
- "supervisors": get_supervisors,
11
+ "nodes": {
12
+ "func": get_nodes,
13
+ "params": {
14
+ "--all": "Get all nodes",
15
+ "--peered": "Get only peered nodes"
16
+ }
17
+ },
18
+ "supervisors": {
19
+ "func": get_supervisors,
20
+ },
10
21
  },
11
22
  "config": {
12
- "show": show_config,
13
- "reset": reset_config,
23
+ "show": {
24
+ "func": show_config,
25
+ },
26
+ "reset": {
27
+ "func": reset_config,
28
+ },
14
29
  },
15
- }
30
+ "restart": {
31
+ "func": restart_node,
32
+ "params": {
33
+ "node": "The node to restart"
34
+ }
35
+ },
36
+ "shutdown": {
37
+ "func": shutdown_node,
38
+ "params": {
39
+ "node": "The node to shutdown"
40
+ }
41
+ }
42
+ }
@@ -1,7 +1,7 @@
1
+ from naeural_client.utils.config import log_with_color
1
2
 
2
3
 
3
-
4
- def get_nodes():
4
+ def get_nodes(args):
5
5
  """
6
6
  This function is used to get the information about the nodes and it will perform the following:
7
7
 
@@ -10,13 +10,44 @@ def get_nodes():
10
10
  3. Wait for the second net mon message via Session and show progress.
11
11
  4. Get the active nodes union via Session and display the nodes marking those peered vs non-peered.
12
12
  """
13
- print("Getting nodes information")
13
+ if args.all:
14
+ log_with_color("Getting all nodes information", color="b")
15
+ elif args.peered:
16
+ log_with_color("Getting peered nodes information", color="b")
17
+ else:
18
+ log_with_color("Getting default nodes information", color="b")
14
19
  return
15
20
 
16
21
 
17
- def get_supervisors():
22
+ def get_supervisors(args):
18
23
  """
19
24
  This function is used to get the information about the supervisors.
20
25
  """
21
- print("Getting supervisors information")
26
+ log_with_color("Getting supervisors information", color='b')
27
+ return
28
+
29
+
30
+ def restart_node(args):
31
+ """
32
+ This function is used to restart the node.
33
+
34
+ Parameters
35
+ ----------
36
+ args : argparse.Namespace
37
+ Arguments passed to the function.
38
+ """
39
+ log_with_color(f"Restarting node {args.node}", color='b')
40
+ return
41
+
42
+
43
+ def shutdown_node(args):
44
+ """
45
+ This function is used to shutdown the node.
46
+
47
+ Parameters
48
+ ----------
49
+ args : argparse.Namespace
50
+ Arguments passed to the function.
51
+ """
52
+ log_with_color(f"Shutting down node {args.node}", color='b')
22
53
  return
@@ -4,7 +4,7 @@ class COLORS:
4
4
  TIMERS = 'd'
5
5
  STATUS = 'n'
6
6
  SERVING = 'm'
7
- BIZ = 'b'
7
+ BIZ = 'c'
8
8
  COMM = 'y'
9
9
  TIMERS = 'd'
10
10
 
@@ -35,6 +35,8 @@ COLORS = {
35
35
  'y': "\x1b[1;33m",
36
36
  'b': "\x1b[1;34m",
37
37
  'm': "\x1b[1;35m",
38
+ 'c': "\x1b[1;36m", # bright cyan
39
+ 'v': "\x1b[0;36m", # dim cyan
38
40
  'a': "\x1b[41m",
39
41
  'e': "\x1b[41m",
40
42
  'w': "\x1b[1;31m", # warning == red
@@ -14,6 +14,34 @@ EE_SECURED=true
14
14
  TARGET_NODE=
15
15
  """
16
16
 
17
+ def log_with_color(s, color='n'):
18
+ """
19
+ Prints the string `s` to the console in the specified color.
20
+
21
+ Parameters
22
+ ----------
23
+ s : str
24
+ The string to be logged.
25
+ color : str, optional
26
+ The color code:
27
+ 'r' for red, 'g' for green, 'y' for yellow,
28
+ 'b' for blue, 'w' for light white, 'n' for dark white (default).
29
+ """
30
+ color_codes = {
31
+ 'r': '\033[31m', # Red
32
+ 'g': '\033[32m', # Green
33
+ 'y': '\033[33m', # Yellow
34
+ 'b': "\x1b[1;34m", # bright blue
35
+ 'w': '\033[97m', # Light white
36
+ 'c': "\x1b[1;36m", # bright cyan
37
+ 'n': '\033[37m', # Dark white (default)
38
+ }
39
+
40
+ reset_code = '\033[0m' # Reset color
41
+ color_code = color_codes.get(color, color_codes['n'])
42
+ print(f"{color_code}{s}{reset_code}", flush=True)
43
+
44
+
17
45
  def get_user_folder():
18
46
  """
19
47
  Returns the user folder.
@@ -26,7 +54,7 @@ def get_user_config_file():
26
54
  """
27
55
  return get_user_folder() / "config"
28
56
 
29
- def reset_config():
57
+ def reset_config(args):
30
58
  """
31
59
  Resets the configuration by creating a ~/.naeural folder and populating
32
60
  ~/.naeural/config with values from a local .env file, if it exists.
@@ -43,26 +71,27 @@ def reset_config():
43
71
  if current_env_file.exists():
44
72
  # Copy .env content to ~/.naeural/config
45
73
  shutil.copy(current_env_file, config_file)
46
- print(f"Configuration has been reset using {current_env_file} into {config_file}")
74
+ log_with_color(f"Configuration has been reset using {current_env_file} into {config_file}", color='y')
47
75
  else:
48
76
  # Create an empty config file
49
77
  with config_file.open("wt") as file:
50
78
  file.write(ENV_TEMPLATE)
51
- print(f"Configuration has been reset to default in {config_file}:\n{ENV_TEMPLATE}")
79
+ log_with_color(f"Configuration has been reset to default in {config_file}:\n{ENV_TEMPLATE}", color='y')
52
80
 
53
81
 
54
- def show_config():
82
+ def show_config(args):
55
83
  """
56
84
  Displays the current configuration from ~/.naeural/config.
57
85
  """
58
86
  config_file = get_user_config_file()
59
87
 
60
88
  if config_file.exists():
61
- print(f"Current configuration ({config_file}):")
89
+ log_with_color(f"Current configuration ({config_file}):")
62
90
  with config_file.open("r") as file:
63
- print(file.read())
91
+ log_with_color(file.read())
64
92
  else:
65
- print(f"No configuration found at {config_file}. Please run `reset_config` first.")
93
+ log_with_color(f"No configuration found at {config_file}. Please run `reset_config` first.", color="r")
94
+ return
66
95
 
67
96
 
68
97
  def load_user_defined_config(verbose=False):
@@ -84,10 +113,10 @@ def load_user_defined_config(verbose=False):
84
113
  result = True
85
114
  os.environ[key.strip()] = value
86
115
  if verbose:
87
- print(f"Configuration from {config_file} has been loaded into the environment.")
116
+ log_with_color(f"Configuration from {config_file} has been loaded into the environment.", color='b')
88
117
  else:
89
118
  if verbose:
90
- print(f"No configuration file found at {config_file}. Please run `reset_config` first.")
119
+ log_with_color(f"No configuration file found at {config_file}. Please run `reset_config` first.", color="r")
91
120
  return result
92
121
 
93
122
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: naeural_client
3
- Version: 2.3.0
3
+ Version: 2.3.2
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,5 +1,5 @@
1
1
  naeural_client/__init__.py,sha256=UKEDGS0wFYyxwmhEAKJGecO2vYbIfRYUP4SQgnK10IE,578
2
- naeural_client/_ver.py,sha256=zb8Hzmn-gdMpHg77kLusI381BxnNJ0u_wIk_OIVA5jQ,330
2
+ naeural_client/_ver.py,sha256=CQFz97cZD3BHPUwaDADidkQTqRJjpmc10HSuppTZLKA,330
3
3
  naeural_client/base_decentra_object.py,sha256=wXjl65gWxxkhV6Tq48wFfNGITvdYdkKPT-wLurGB5vc,4287
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
@@ -15,13 +15,13 @@ naeural_client/base/payload/payload.py,sha256=v50D7mBBD2WwWzvpbRGMSr-X6vv5ie21IY
15
15
  naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
16
16
  naeural_client/bc/base.py,sha256=GI9CbI2RVgIBXpOoRjrhXt45tONlBDMrybX_BcL3_Os,29513
17
17
  naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- naeural_client/bc/ec.py,sha256=eUkdHUDZ-OgmbwjbYx1wmTOJVWLmjvP4Svduocj69Uk,13841
18
+ naeural_client/bc/ec.py,sha256=raIGI7BpSH8xU_Bg7RpKv9KEW3F6PuAdL5miZfvw7iI,14027
19
19
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt,sha256=y-6io0tseyx9-a4Pmde1z1gPULtJNSYUpG_YFkYaMKU,1337
21
21
  naeural_client/cli/README.md,sha256=WPdI_EjzAbUW1aPyj1sSR8rLydcJKZtoiaEtklQrjHo,74
22
- naeural_client/cli/cli.py,sha256=KlPb6ExUMrrFxBl2j7XRnOQhtH-1s-jFtsca5zcz5qI,1342
23
- naeural_client/cli/cli_commands.py,sha256=NluWqnsyuabu0EKNM6MDUBtnfloH7oqCOrkfJs8Ajjk,353
24
- naeural_client/cli/nodes.py,sha256=tOgWGzsCqGhznne1-FRbiYdmIALSXljYz2C8Eub25Ks,619
22
+ naeural_client/cli/cli.py,sha256=puxQ_5acL6tD2YOt8PdO5idiuKT2VUt7YzMigO3IY50,2752
23
+ naeural_client/cli/cli_commands.py,sha256=Sm7_Ig3jxs0P7S9X_vsTrv4jthWfzo9Meb05ufI4pxQ,911
24
+ naeural_client/cli/nodes.py,sha256=0aS9d26DtzEJHcNHiprBxlPPOdEX7B1DXDFyzL9mXVU,1406
25
25
  naeural_client/code_cheker/__init__.py,sha256=pwkdeZGVL16ZA4Qf2mRahEhoOvKhL7FyuQbMFLr1E5M,33
26
26
  naeural_client/code_cheker/base.py,sha256=lT5DRIFO5rqzsMNCmdMRfkAeevmezozehyfgmhnKpuI,19074
27
27
  naeural_client/code_cheker/checker.py,sha256=QWupeM7ToancVIq1tRUxRNUrI8B5l5eoY0kDU4-O5aE,7365
@@ -36,7 +36,7 @@ naeural_client/const/comms.py,sha256=La6JXWHexH8CfcBCKyT4fCIoeaoZlcm7KtZ57ab4ZgU
36
36
  naeural_client/const/environment.py,sha256=iytmTDgbOjvORPwHQmc0K0r-xJx7dnnzNnqAJJiFCDA,870
37
37
  naeural_client/const/formatter.py,sha256=AW3bWlqf39uaqV4BBUuW95qKYfF2OkkU4f9hy3kSVhM,200
38
38
  naeural_client/const/heartbeat.py,sha256=jGHmKfeHTFOXJaKUT3o_ocnQyF-EpcLeunW-ifkYKfU,2534
39
- naeural_client/const/misc.py,sha256=1ypROmZsOyp_8zG2LARwPeo-YfXuyYqZnml0elTP4kw,211
39
+ naeural_client/const/misc.py,sha256=Y6x00YDtY1_nAk4OvikCLlfp8ggn11WQYTBGYzFlJPk,211
40
40
  naeural_client/const/payload.py,sha256=jBzXQZ-jQ1Ft6eRsb8WvT-OPpQd1j4Y-uu_V26-EY0Y,5763
41
41
  naeural_client/default/__init__.py,sha256=ozU6CMMuWl0LhG8Ae3LrZ65a6tLrptfscVYGf83zjxM,46
42
42
  naeural_client/default/instance/__init__.py,sha256=Itb4l6_DR6CCw8KAxyQKlCmALyzDasNHIfM9VB-Umak,548
@@ -56,7 +56,7 @@ naeural_client/io_formatter/default/a_dummy.py,sha256=qr9eUizQ-NN5jdXVzkaZKMaf9K
56
56
  naeural_client/io_formatter/default/aixp1.py,sha256=MX0TeUR4APA-qN3vUC6uzcz8Pssz5lgrQWo7td5Ri1A,3052
57
57
  naeural_client/io_formatter/default/default.py,sha256=gEy78cP2D5s0y8vQh4aHuxqz7D10gGfuiKF311QhrpE,494
58
58
  naeural_client/logging/__init__.py,sha256=b79X45VC6c37u32flKB2GAK9f-RR0ocwP0JDCy0t7QQ,33
59
- naeural_client/logging/base_logger.py,sha256=IEhDnR6vn_nMBE4OwzUHO_71wuvAtCXjHHx4yeRxm6s,65880
59
+ naeural_client/logging/base_logger.py,sha256=uyR4rxXQGd9UrdIdRRhS6T7UmnzyEfFooVXikxOsfw4,65951
60
60
  naeural_client/logging/small_logger.py,sha256=m12hCb_H4XifJYYfgCAOUDkcXm-h4pSODnFf277OFVI,2937
61
61
  naeural_client/logging/logger_mixins/__init__.py,sha256=yQO7umlRvz63FeWpi-F9GRmC_MOHcNW6R6pwvZZBy3A,600
62
62
  naeural_client/logging/logger_mixins/class_instance_mixin.py,sha256=xUXE2VZgmrlrSrvw0f6GF1jlTnVLeVkIiG0bhlBfq3o,2741
@@ -78,10 +78,10 @@ naeural_client/logging/tzlocal/win32.py,sha256=zBoj0vFVrGhnCm_f7xmYzGym4-fV-4Ij2
78
78
  naeural_client/logging/tzlocal/windows_tz.py,sha256=Sv9okktjZJfRGGUOOppsvQuX_eXyXUxkSKCAFmWT9Hw,34203
79
79
  naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uwpmI,77
80
80
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
81
- naeural_client/utils/config.py,sha256=eqVhrSte94nC1eJOkRzuUAdIgJUOLoqcV3CZEFS2O6g,2767
81
+ naeural_client/utils/config.py,sha256=t_VzyBnRHJa-Kt71HUu9gXxeDOri1Aqf_-gjO04gAYs,3681
82
82
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
83
- naeural_client-2.3.0.dist-info/METADATA,sha256=7X1taqH_efSawHEHyKlLCRjwh5CLamWnnmW5hDc6Ays,14449
84
- naeural_client-2.3.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
85
- naeural_client-2.3.0.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
86
- naeural_client-2.3.0.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
87
- naeural_client-2.3.0.dist-info/RECORD,,
83
+ naeural_client-2.3.2.dist-info/METADATA,sha256=Nt9IRuxQmbjZt3OgMZdbyqXIwo5FDx6rIyzYNsu0czU,14449
84
+ naeural_client-2.3.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
85
+ naeural_client-2.3.2.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
86
+ naeural_client-2.3.2.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
87
+ naeural_client-2.3.2.dist-info/RECORD,,