Package zephir :: Package monitor :: Package agents :: Module patches
[frames] | no frames]

Source Code for Module zephir.monitor.agents.patches

  1  # -*- coding: UTF-8 -*- 
  2  ########################################################################### 
  3  # Eole NG - 2007 
  4  # Copyright Pole de Competence Eole  (Ministere Education - Academie Dijon) 
  5  # Licence CeCill  cf /root/LicenceEole.txt 
  6  # eole@ac-dijon.fr 
  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   
22 -def verify_patch(filename):
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 # pas de fichier dans /etc/eole: patch sur un fichier quelconque ? 37 fic_dest = line.split()[1] 38 if not os.path.exists(fic_dest): 39 # fichier de destination inexistant 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 #la ligne débute par un commentaire, on l'ignore (#4121) 48 continue 49 # recherche du pattern dans le fichier de destination 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
60 -class Patches(Agent):
61
62 - def __init__(self, name, 63 **params):
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
73 - def measure(self):
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
95 - def check_status(self):
96 return self.status
97
98 - def write_data(self):
99 Agent.write_data(self) 100 if self.last_measure is not None: 101 self.table.table_data = self.last_measure.value['statistics']
102