From db1dc7ec64f31482b61b1d108fed4a1523731a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Sun, 17 Nov 2013 20:26:43 +0100 Subject: [PATCH] =?UTF-8?q?[binding]=20On=20g=C3=A8re=20aussi=20les=20date?= =?UTF-8?q?s=20avec=20des=20secondes.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/ldap_crans.py | 33 +++++++++++++++++++-------------- gestion/whos.py | 7 ++++--- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 3013b630..9e73a772 100755 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -29,6 +29,7 @@ import secrets_new as secrets import ridtools date_format = '%d/%m/%Y %H:%M' +date_format_new = '%d/%m/%Y %H:%M:%S' hostname = gethostname().split(".")[0] smtpserv = "smtp.crans.org" random.seed() # On initialise le générateur aléatoire @@ -247,12 +248,12 @@ def format_gpg_fingerprint(fpr): Formatage de fingerpring GPG pour les avoir de la forme XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX """ - + # longueur + fpr sans espaces l, fpr = preattr(fpr) fpr = fpr.replace(':', '').replace('-', '').replace(' ', '') - + if len(fpr) != 40: raise ValueError(u"Longueur de la fingerprint GPG incorrecte, merci de respecter le format") @@ -623,7 +624,7 @@ class CransLdap: except TypeError: pass start = map(lambda x:preattr(x)[1], start) - + if new in serv.keys(): modlist = [] @@ -930,7 +931,7 @@ class CransLdap: if uid == "grosminet": proprio = self.search("nom=grosminet", mode)['adherent'][0] return proprio - + __machines = () def all_machines(self, graphic=False): """ @@ -1010,10 +1011,10 @@ class BaseClasseCrans(CransLdap): ex: {'upload': [(1143336210, 1143509010), ...]} """ bl_liste = self._data.get('blacklist', []) - + actifs = {} inactifs = {} - + if isinstance(self, Machine): # Il faut aussi regarder la blackliste du propriétaire p = self.proprietaire() @@ -1541,13 +1542,13 @@ class BaseProprietaire(BaseClasseCrans): return liste else: index = -1 - + new = format_gpg_fingerprint(new) new = new.upper() #if gpgexists(new): # raise ValueError(u"Alias existant ou correspondand à un compte.") - + if index != -1: liste[index] = new else: @@ -1802,7 +1803,7 @@ class BaseProprietaire(BaseClasseCrans): si négatif le supprime """ return self._an('paiement', action) - + def sursis_carte(self): for h in self.historique()[::-1]: x=re.match("(.*),.* : .*(paiement\+%s|inscription).*" % config.ann_scol,h) @@ -1818,7 +1819,7 @@ class BaseProprietaire(BaseClasseCrans): return self.sursis_carte() else: return False - + def delete(self, comment=''): """Destruction du propriétaire""" @@ -2600,7 +2601,11 @@ class Adherent(BaseProprietaire): if self.historique(): h = self.historique()[0] h = h[:h.find(",")] - return time.mktime(time.strptime(h, date_format)) + try: + dateInsc = time.mktime(time.strptime(h, date_format_new)) + except: + dateInsc = time.mktime(time.strptime(h, date_format)) + return dateInsc else: # Lors de l'inscription d'un nouvel adhérent, celui-ci n'a pas # encore d'historique. On retourne alors la date en cours. @@ -3037,7 +3042,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) #if sshexists(new): # raise ValueError(u"FPR existant ou correspondand à un compte.") - + if index != -1: liste[index] = new else: @@ -3215,7 +3220,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) # On vire les doublons dans reconf_ip reconf_ip = list(dict(zip(reconf_ip, [None]*len(reconf_ip)))) - + # Si la configuration ip à changer on met dynamiquement à jour le dhcp if reconf_ip: from gen_confs.dhcpd_new import dydhcp @@ -3291,7 +3296,7 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) self.proprio = self.__proprietaire.Nom() # On met dans un coin le nom du proprio self.__proprietaire = None # On oublie le propriétaire self._delete(self.dn, comment) - + # On supprime la machine du dhcp from gen_confs.dhcpd_new import dydhcp for server in config.dhcp_servers: diff --git a/gestion/whos.py b/gestion/whos.py index edf82c7e..1b55fd31 100755 --- a/gestion/whos.py +++ b/gestion/whos.py @@ -363,7 +363,7 @@ def list_spec(machines) : * nom * adresse IPv4/IPv6 * adresse MAC - + Pour les bornes : * État * puissance @@ -485,7 +485,7 @@ def adher_details(adher) : # État administratif f += coul("Date d'inscription : ", "gras") - f += strftime('%d/%m/%Y %H:%M', localtime(adher.dateInscription())) + f += strftime('%d/%m/%Y %H:%M:%S', localtime(adher.dateInscription())) f += coul(u'\nÉtat administratif : ','gras') jour=1 if ann_scol not in adher.carteEtudiant() : @@ -926,7 +926,7 @@ def __bases_machines(m) : """ Retourne [ type de la machines, blacklist ] """ #Type t = 'inconnu' - t, _ = ridtools.find_rid_plage(int(m.rid())) + t, _ = ridtools.find_rid_plage(int(m.rid())) # Déconnectée ? b = m.blacklist_actif() @@ -1352,6 +1352,7 @@ if __name__ == '__main__' : cprint(u"""Une erreur fatale s'est produite durant l'exécution. Pour l'amélioration de ce programme merci de prévenir nounou en spécifiant la marche à suivre pour reproduire cette erreur.""") + raise if debug : cprint('-'*40) cprint(u'Détails techniques :')