1
2
3
4
5
6
7
8
9 """
10
11 """
12
13 try: _
14 except NameError: _ = str
15
16 import os, dircache
17
18 from zephir.monitor.agentmanager import config as cfg
19 from zephir.monitor.agentmanager.agentdatamanager import AgentDataManager, LiveAgentsManager
20
21
22
24 """Structure d'accès aux postes clients.
25
26 Se comporte comme un dictionnaire C{{'nom client': AgentManager}}.
27
28 TODO: utiliser UserDict.DictMixin
29 """
30
31 - def __init__(self, config, live_agents=None):
32 """
33 @param live_agents: dictionnaire C{{client_name:
34 L{LiveAgentsManager}}} pour les éventuels agents chargés en
35 local.
36 """
37 self.config = config
38 self.live_agents = {}
39 if live_agents is not None:
40 for client_name, agents in live_agents.items():
41 self.live_agents[client_name] = LiveAgentsManager(self.config, client_name, agents)
42 self.cache = {}
43
60
62 """
63 @return: C{True} si C{client_name} est le nom d'un agent local
64 """
65 return self.live_agents.has_key(client_name)
66
68 """
69 @return: C{True} si C{client_name} est le nom d'un agent
70 archivé
71 """
72 d = cfg.client_data_dir(self.config, client_name)
73 client_data_dir_exists = os.path.isdir(d)
74 client_structure_exists = os.path.isfile(os.path.join(d, 'site.cfg'))
75 return client_data_dir_exists and client_structure_exists
76
80
82 d = self.config['state_dir']
83 archives = []
84 for k in dircache.listdir(d):
85 if self.has_archive_key(k) and not self.has_live_key(k):
86 archives.append(k)
87 return self.live_agents.keys() + archives
88
90 result = []
91 for k in self.keys():
92 result.append([k, self[k]])
93 return result
94
95
96
97
98
99
100