pbesa 2.1__py3-none-any.whl → 4.0.0__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.
Files changed (75) hide show
  1. pbesa/__init__.py +4 -3
  2. pbesa/cognitive.py +475 -0
  3. pbesa/kernel/__init__.py +4 -6
  4. pbesa/kernel/adapter.py +165 -0
  5. pbesa/kernel/agent.py +558 -0
  6. pbesa/kernel/io/__init__.py +2 -2
  7. pbesa/kernel/io/system_file.py +38 -0
  8. pbesa/kernel/io/tcp_server.py +23 -0
  9. pbesa/kernel/util.py +217 -0
  10. pbesa/kernel/world.py +43 -0
  11. pbesa/mas.py +565 -0
  12. pbesa/remote/__init__.py +5 -0
  13. pbesa/remote/adm_listener.py +44 -0
  14. pbesa/{middleware/remote/AdmListenerHandler.py → remote/adm_listener_handler.py} +74 -57
  15. pbesa/remote/exceptions.py +18 -0
  16. pbesa/remote/remote_adm.py +42 -0
  17. pbesa/{middleware/remote/RemoteAdmHandler.py → remote/remote_adm_handler.py} +109 -83
  18. pbesa/social/__init__.py +4 -0
  19. pbesa/social/collaborative_team.py +299 -0
  20. pbesa/social/delegator.py +81 -0
  21. pbesa/social/delegator_team.py +334 -0
  22. pbesa/social/dialog.py +153 -0
  23. pbesa/social/dispatcher_team.py +319 -0
  24. pbesa/social/templates.py +18 -0
  25. pbesa/social/worker.py +188 -0
  26. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE +21 -21
  27. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE.txt +21 -21
  28. pbesa-4.0.0.dist-info/METADATA +8 -0
  29. pbesa-4.0.0.dist-info/RECORD +32 -0
  30. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/WHEEL +5 -5
  31. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/top_level.txt +0 -0
  32. pbesa/engine/__init__.py +0 -2
  33. pbesa/engine/bdi/BDIAg.py +0 -42
  34. pbesa/engine/bdi/BDILevel.py +0 -10
  35. pbesa/engine/bdi/BDIMachine.py +0 -116
  36. pbesa/engine/bdi/Goal.py +0 -28
  37. pbesa/engine/bdi/GoalExe.py +0 -36
  38. pbesa/engine/bdi/__init__.py +0 -5
  39. pbesa/engine/rational/ActionExe.py +0 -35
  40. pbesa/engine/rational/Brain.py +0 -10
  41. pbesa/engine/rational/RationalAg.py +0 -43
  42. pbesa/engine/rational/__init__.py +0 -3
  43. pbesa/kernel/adapter/Adapter.py +0 -26
  44. pbesa/kernel/adapter/FileAdapter.py +0 -23
  45. pbesa/kernel/adapter/__init__.py +0 -2
  46. pbesa/kernel/agent/Action.py +0 -19
  47. pbesa/kernel/agent/Agent.py +0 -91
  48. pbesa/kernel/agent/BehaviorExe.py +0 -33
  49. pbesa/kernel/agent/Channel.py +0 -10
  50. pbesa/kernel/agent/World.py +0 -15
  51. pbesa/kernel/agent/__init__.py +0 -5
  52. pbesa/kernel/io/SystemFile.py +0 -13
  53. pbesa/kernel/io/TCPServer.py +0 -4
  54. pbesa/kernel/system/Adm.py +0 -189
  55. pbesa/kernel/system/Directory.py +0 -36
  56. pbesa/kernel/system/__init__.py +0 -2
  57. pbesa/kernel/util/HashTable.py +0 -62
  58. pbesa/kernel/util/Queue.py +0 -231
  59. pbesa/kernel/util/__init__.py +0 -2
  60. pbesa/middleware/__init__.py +0 -3
  61. pbesa/middleware/adapter/GameAdapter.py +0 -64
  62. pbesa/middleware/adapter/MongoAdapter.py +0 -47
  63. pbesa/middleware/adapter/RESTAdapter.py +0 -52
  64. pbesa/middleware/adapter/SubProcessAdapter.py +0 -30
  65. pbesa/middleware/adapter/WSSAdapter.py +0 -89
  66. pbesa/middleware/adapter/WSSNJAdapter.py +0 -51
  67. pbesa/middleware/adapter/WSSNJHandler.py +0 -23
  68. pbesa/middleware/adapter/__init__.py +0 -7
  69. pbesa/middleware/remote/AdmListener.py +0 -17
  70. pbesa/middleware/remote/RemoteAdm.py +0 -17
  71. pbesa/middleware/remote/__init__.py +0 -4
  72. pbesa/middleware/web/WebAgTK.py +0 -15
  73. pbesa/middleware/web/__init__.py +0 -0
  74. pbesa-2.1.dist-info/METADATA +0 -25
  75. pbesa-2.1.dist-info/RECORD +0 -54
@@ -1,57 +1,74 @@
1
- import os
2
- import sys
3
- import json
4
- import inspect
5
- import socketserver
6
- from time import sleep
7
- from importlib.machinery import SourceFileLoader
8
- from ...kernel.system.Directory import Directory
9
-
10
- import types
11
-
12
- class AdmListenerHandler(socketserver.StreamRequestHandler):
13
-
14
- def handle(self):
15
- self.data = self.rfile.readline().strip()
16
- print("{} wrote:".format(self.client_address[0]))
17
- print(self.data)
18
- msg = str(self.data, "utf-8")
19
- info = json.loads(msg)
20
- if info['command'] == 'UPDATE':
21
- agents = info['agents']
22
- directory = Directory()
23
- for agent in agents:
24
- directory.resetAgentList()
25
- directory.addAgent(agent)
26
- if info['command'] == 'MOVE':
27
- appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
28
- appPathSplit = appPath.split(os.sep)
29
-
30
- classPath = info['path']
31
- classPathSplit = classPath.split('.')
32
-
33
- path = appPathSplit[0]
34
- findFlag = False
35
-
36
- for x in range(1, len(appPathSplit) ):
37
- if appPathSplit[x] == classPathSplit[0]:
38
- path = path + os.sep + appPathSplit[x]
39
- for y in range(1, len(classPathSplit) ):
40
- path = path + os.sep + classPathSplit[y]
41
- break
42
- else:
43
- path = path + os.sep + appPathSplit[x]
44
- path = path + '.py'
45
-
46
- module = SourceFileLoader(info['class'], path).load_module()
47
- agType = getattr(module, info['class'])
48
- ag = agType(info['id'])
49
- ag.state = info['state']
50
- ag.start()
51
-
52
-
53
- if info['command'] == 'SENDEVENT':
54
- from ...KernelTK.SystemTK.Adm import Adm
55
- Adm().sendEvent(info['alias'], info['event'], info['data'])
56
- rsp = 'ACK'
57
- self.wfile.write(bytes(rsp + "\n", "utf-8"))
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 08/08/24
10
+ """
11
+
12
+ # --------------------------------------------------------
13
+ # Define resources
14
+ # --------------------------------------------------------
15
+
16
+ import os
17
+ import sys
18
+ import json
19
+ import base64
20
+ import socketserver
21
+ from importlib.machinery import SourceFileLoader
22
+
23
+ # --------------------------------------------------------
24
+ # Define component
25
+ # --------------------------------------------------------
26
+
27
+ class AdmListenerHandler(socketserver.StreamRequestHandler):
28
+ """ ADM Listener Handler class """
29
+
30
+ def handle(self):
31
+ """ Handle """
32
+ from ..mas import Directory
33
+ self.data = self.rfile.readline().strip()
34
+ print("{} wrote:".format(self.client_address[0]))
35
+ print(self.data)
36
+ msg = str(self.data, "utf-8")
37
+ info = json.loads(msg)
38
+ if info['command'] == 'UPDATE':
39
+ agents = info['agents']
40
+ directory = Directory()
41
+ directory.set_agent_list(agents)
42
+ if info['command'] == 'MOVE':
43
+ appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
44
+ appPathSplit = appPath.split(os.sep)
45
+ classPath = info['path']
46
+ classPathSplit = classPath.split('.')
47
+ path = appPathSplit[0]
48
+ findFlag = False
49
+ for x in range(1, len(appPathSplit) ):
50
+ if appPathSplit[x] == classPathSplit[0]:
51
+ path = path + os.sep + appPathSplit[x]
52
+ for y in range(1, len(classPathSplit) ):
53
+ path = path + os.sep + classPathSplit[y]
54
+ break
55
+ else:
56
+ path = path + os.sep + appPathSplit[x]
57
+ path = path + '.py'
58
+ module = SourceFileLoader(info['class'], path).load_module()
59
+ agType = getattr(module, info['class'])
60
+ ag = agType(info['id'])
61
+ ag.state = info['state']
62
+ ag.start()
63
+ if info['command'] == 'SENDEVENT':
64
+ from ..mas import Adm
65
+ data = info['data']
66
+ aux = None
67
+ if data and not data == 'None':
68
+ data = data.encode('utf-8')
69
+ data = base64.b64decode(data)
70
+ data = data.decode('utf-8')
71
+ aux = json.loads(data)
72
+ Adm().send_event(info['id'], info['event'], aux)
73
+ rsp = 'ACK'
74
+ self.wfile.write(bytes(rsp + "\n", "utf-8"))
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ------------------------------------------------------------
4
+ -------------------------- PBESA ---------------------------
5
+ ------------------------------------------------------------
6
+
7
+ @autor AKEN & SIDRE
8
+ @version 3.0.1
9
+ @date 27/07/20
10
+ """
11
+
12
+ # ----------------------------------------------------------
13
+ # Defines system component exceptions
14
+ # ----------------------------------------------------------
15
+
16
+ class RemoteException(Exception):
17
+ """ Base class for exceptions of system """
18
+ pass
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 09/08/24
10
+ """
11
+
12
+ import traceback
13
+ import socketserver
14
+ from threading import Thread
15
+ from .exceptions import RemoteException
16
+ from .remote_adm_handler import RemoteAdmHandler
17
+
18
+ class RemoteAdm(Thread):
19
+ """ RemoteAdm class """
20
+
21
+ # IP
22
+ __IP = None
23
+ # PORT
24
+ __PORT = None
25
+
26
+ def __init__(self, ip:str, port:str) -> None:
27
+ """ Constructor
28
+ @param ip: IP
29
+ @param port: PORT
30
+ """
31
+ self.__IP = ip
32
+ self.__PORT = port
33
+ super().__init__()
34
+
35
+ def run(self) -> None:
36
+ """ Run method """
37
+ try:
38
+ server = socketserver.TCPServer((self.__IP, self.__PORT), RemoteAdmHandler)
39
+ server.serve_forever()
40
+ except:
41
+ traceback.print_exc()
42
+ raise RemoteException("Could not initialize master container on %s host and %d port" % (self.__IP, self.__PORT))
@@ -1,83 +1,109 @@
1
- import os
2
- import json
3
- import socket
4
- import socketserver
5
- from time import sleep
6
- from importlib.machinery import SourceFileLoader
7
- from ...kernel.system.Directory import Directory
8
-
9
- class RemoteAdmHandler(socketserver.StreamRequestHandler):
10
-
11
- def handle(self):
12
- self.data = self.rfile.readline().strip()
13
- print("{} wrote:".format(self.client_address[0]))
14
- print(self.data)
15
- msg = str(self.data, "utf-8")
16
- info = json.loads(msg)
17
- if info['command'] == 'REGISTER':
18
- directory = Directory()
19
- directory.addContainer({'alias': info['alias'], 'ip': info['ip'], 'port': info['port']})
20
- data = 'ACK'
21
- self.wfile.write(bytes(data + "\n", "utf-8"))
22
- sleep(2) # 2 seconds.
23
- containers = directory.getContainers()
24
- agents = directory.getAgents()
25
- dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
26
- for ctn in containers:
27
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
28
- try:
29
- sock.connect( (ctn['ip'], int(ctn['port'])) )
30
- sock.sendall(bytes(dto + "\n", "utf-8"))
31
- except:
32
- pass
33
-
34
- finally:
35
- sock.close()
36
-
37
- if info['command'] == 'MOVE':
38
- appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
39
- appPathSplit = appPath.split(os.sep)
40
-
41
- classPath = info['path']
42
- classPathSplit = classPath.split('.')
43
-
44
- path = appPathSplit[0]
45
- findFlag = False
46
-
47
- for x in range(1, len(appPathSplit) ):
48
- if appPathSplit[x] == classPathSplit[0]:
49
- path = path + os.sep + appPathSplit[x]
50
- for y in range(1, len(classPathSplit) ):
51
- path = path + os.sep + classPathSplit[y]
52
- break
53
- else:
54
- path = path + os.sep + appPathSplit[x]
55
- path = path + '.py'
56
-
57
- module = SourceFileLoader(info['class'], path).load_module()
58
- agType = getattr(module, info['class'])
59
- ag = agType(info['id'])
60
- ag.state = info['state']
61
- ag.start()
62
-
63
-
64
- if info['command'] == 'UPDATE':
65
- agents = info['agents']
66
- directory = Directory()
67
- for agent in agents:
68
- directory.resetAgentList()
69
- directory.addAgent(agent)
70
-
71
- containers = directory.getContainers()
72
- agents = directory.getAgents()
73
- dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
74
- for ctn in containers:
75
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
76
- try:
77
- sock.connect( (ctn['ip'], int(ctn['port'])) )
78
- sock.sendall(bytes(dto + "\n", "utf-8"))
79
- except:
80
- pass
81
-
82
- finally:
83
- sock.close()
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 08/08/24
10
+ """
11
+
12
+ # --------------------------------------------------------
13
+ # Define resources
14
+ # --------------------------------------------------------
15
+
16
+ import os
17
+ import json
18
+ import base64
19
+ import socket
20
+ import socketserver
21
+ from time import sleep
22
+ from importlib.machinery import SourceFileLoader
23
+
24
+ # --------------------------------------------------------
25
+ # Define component
26
+ # --------------------------------------------------------
27
+
28
+ class RemoteAdmHandler(socketserver.StreamRequestHandler):
29
+ """ Remote ADM Handler class """
30
+
31
+ def handle(self):
32
+ """ Handle """
33
+ from ..mas import Directory
34
+ self.data = self.rfile.readline().strip()
35
+ print("{} wrote:".format(self.client_address[0]))
36
+ print(self.data)
37
+ msg = str(self.data, "utf-8")
38
+ info = json.loads(msg)
39
+ if info['command'] == 'REGISTER':
40
+ directory = Directory()
41
+ directory.add_container({'name': info['name'], 'host': info['host'], 'port': info['port']})
42
+ data = 'ACK'
43
+ self.wfile.write(bytes(data + "\n", "utf-8"))
44
+ sleep(2) # 2 seconds.
45
+ containers = directory.get_containers()
46
+ agents = directory.get_agents()
47
+ dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
48
+ for ctn in containers:
49
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
50
+ try:
51
+ sock.connect( (ctn['host'], int(ctn['port'])) )
52
+ sock.sendall(bytes(dto + "\n", "utf-8"))
53
+ except:
54
+ pass
55
+
56
+ finally:
57
+ sock.close()
58
+ directory.check_full(info['name'])
59
+ if info['command'] == 'MOVE':
60
+ appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
61
+ appPathSplit = appPath.split(os.sep)
62
+ classPath = info['path']
63
+ classPathSplit = classPath.split('.')
64
+ path = appPathSplit[0]
65
+ findFlag = False
66
+ for x in range(1, len(appPathSplit) ):
67
+ if appPathSplit[x] == classPathSplit[0]:
68
+ path = path + os.sep + appPathSplit[x]
69
+ for y in range(1, len(classPathSplit) ):
70
+ path = path + os.sep + classPathSplit[y]
71
+ break
72
+ else:
73
+ path = path + os.sep + appPathSplit[x]
74
+ path = path + '.py'
75
+ module = SourceFileLoader(info['class'], path).load_module()
76
+ agType = getattr(module, info['class'])
77
+ ag = agType(info['id'])
78
+ ag.state = info['state']
79
+ ag.start()
80
+ if info['command'] == 'ADD':
81
+ agent = info['agent']
82
+ host = agent['host']
83
+ directory = Directory()
84
+ directory.add_agent(agent)
85
+ containers = directory.get_containers()
86
+ agents = directory.get_agents()
87
+ dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
88
+ for ctn in containers:
89
+ if not ctn['host'] == host:
90
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
91
+ try:
92
+ sock.connect( (ctn['host'], int(ctn['port'])) )
93
+ sock.sendall(bytes(dto + "\n", "utf-8"))
94
+ except:
95
+ pass
96
+ finally:
97
+ sock.close()
98
+ if info['command'] == 'SENDEVENT':
99
+ from ..mas import Adm
100
+ data = info['data']
101
+ aux = None
102
+ if data and not data == 'None':
103
+ data = data.encode('utf-8')
104
+ data = base64.b64decode(data)
105
+ data = data.decode('utf-8')
106
+ aux = json.loads(data)
107
+ Adm().send_event(info['id'], info['event'], data)
108
+ rsp = 'ACK'
109
+ self.wfile.write(bytes(rsp + "\n", "utf-8"))
@@ -0,0 +1,4 @@
1
+ from .worker import *
2
+ from .delegator import *
3
+ from .dispatcher_team import *
4
+ from .collaborative_team import *