1
2
3
4
5
6
7
8 """
9 Agent zephir testant l'application des patches présents sur le serveur
10 """
11 import os
12 from glob import glob
13 from cgi import escape
14 from creole.config import templatedir, distrib_dir, eoleroot
15 from zephir.monitor.agentmanager.agent import Agent
16 from zephir.monitor.agentmanager import status
17 from zephir.monitor.agentmanager.util import status_to_img
18 from zephir.monitor.agentmanager.data import TableData
19
20 COMMENTS = ['#', ';']
21
23 """vérifie qu'un patch est bien appliqué"""
24 bad_patches = {}
25 patch_lines = open(filename).read().split('\n')
26 fic_dest = ""
27 for line in patch_lines:
28 if line.startswith('+++'):
29 dest_not_found = False
30 if os.path.exists(templatedir):
31 fic_dest = os.path.join(templatedir, os.path.basename(line.split()[1]))
32 else:
33 fic_dest = os.path.join(distrib_dir, os.path.basename(line.split()[1]))
34
35 if not os.path.exists(fic_dest):
36
37 fic_dest = line.split()[1]
38 if not os.path.exists(fic_dest):
39
40 dest_not_found = True
41 bad_patches[fic_dest] = []
42 if dest_not_found:
43 bad_patches[fic_dest].append("Fichier de destination non trouvé !")
44 elif line.startswith('+') and len(line) > 1 and not dest_not_found:
45 pattern = line[1:]
46 if pattern[0] in COMMENTS:
47
48 continue
49
50 f_dest = open(fic_dest)
51 data = f_dest.read().split('\n')
52 f_dest.close()
53 if not pattern in data:
54 if len(pattern) > 40:
55 pattern = pattern[:40]
56 if bad_patches[fic_dest] == []:
57 bad_patches[fic_dest].append(pattern)
58 return bad_patches
59
61
64 Agent.__init__(self, name, **params)
65 self.status = status.OK()
66 self.table = TableData([
67 ('patch', 'Nom du patch', {'align':'left'}, None),
68 ('dest', 'Fichier modifié', {'align':'left'}, None),
69 ('etat', 'Etat', {'align':'center'}, status_to_img),
70 ('pattern', 'Chaine non trouvée', {'align':'left'}, None)])
71 self.data = [self.table]
72
74 patchs = glob('%s/patch/*.patch' % eoleroot)
75 patchs.extend(glob('%s/patch/variante/*.patch' % eoleroot))
76 results = []
77 meas_data = {}
78 self.status = status.OK()
79 for patch in patchs:
80 patch_name = patch
81 bad_patches = verify_patch(patch)
82 for dest, pattern in bad_patches.items():
83 if pattern == []:
84 etat = 'On'
85 else:
86 etat = 'Off'
87 self.status = status.Error()
88 results.append({'patch':patch_name, 'dest':dest, 'etat':etat,
89 'pattern':escape('<br>'.join(pattern))})
90 patch_name = ''
91 meas_data[patch] = bad_patches
92 self.measure_data = meas_data
93 return {'statistics':results}
94
97
99 Agent.write_data(self)
100 if self.last_measure is not None:
101 self.table.table_data = self.last_measure.value['statistics']
102