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

Source Code for Module zephir.monitor.agents.aaf

 1  # -*- coding: UTF-8 -*- 
 2  ########################################################################### 
 3  # Eole NG - 2010 
 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  """ 
10  Agent zephir pour vérification de la synchronisation AAF 
11  """ 
12   
13  from os.path import join, isfile, basename 
14  from os import stat 
15  from glob import glob 
16  import time 
17  from zephir.monitor.agentmanager.agent import Agent 
18  from zephir.monitor.agentmanager.data import TableData 
19  from zephir.monitor.agentmanager.util import status_to_img 
20  from zephir.monitor.agentmanager import status 
21  from scribe.importation.config import AAF_LIST_AGENT, AAF_IMPORT_DIR 
22   
23 -class AAF(Agent):
24
25 - def __init__(self, name, 26 **params):
27 Agent.__init__(self, name, **params) 28 self.status = status.Unknown() 29 self.table = TableData([ 30 ('name', "Identifiant", {'align':'left'}, None), 31 ('date_err', "Date de l'erreur", {'align':'left'}, None), 32 ('status', "Etat", {'align':'center'}, status_to_img), 33 ]) 34 self.data = [self.table] 35 self.measure_data = {}
36
37 - def measure(self):
38 self.status = status.Unknown("Synchronisation non active") 39 # liste de tous les fichiers associés 40 if isfile(AAF_LIST_AGENT): 41 file_list = open(AAF_LIST_AGENT).read().strip().split('\n') 42 else: 43 file_list = [] 44 # recherche des fichiers indiquant une erreur de prise en compte 45 search_string = join(AAF_IMPORT_DIR, ".*.tar.gz.lock") 46 list_lock = glob(search_string) 47 if file_list == []: 48 return {'statistics':None} 49 self.status = status.OK() 50 err_stats = [] 51 for fic in file_list: 52 fic_err = join(AAF_IMPORT_DIR, '.%s.lock' % fic) 53 if fic_err in list_lock: 54 status_fic = 'Off' 55 stats = stat(fic_err) 56 date_err = time.ctime(stats.st_mtime) 57 self.status = status.Error("Echec de prise en compte d'un fichier") 58 else: 59 status_fic = 'On' 60 date_err = "" 61 # récupération de la date 62 err_stats.append({'name':fic, 'date_err':date_err, 'status':status_fic}) 63 self.measure_data[fic] = (status_fic, date_err) 64 return {'statistics':err_stats}
65
66 - def errback_tunnels(self, err):
67 self.status = status.Error("Erreur d'execution : erreur lors de la recherche des fichiers d'information") 68 return {'statistics':None}
69
70 - def write_data(self):
71 Agent.write_data(self) 72 if self.last_measure is not None: 73 self.table.table_data = self.last_measure.value['statistics']
74
75 - def check_status(self):
76 return self.status
77