[crans_utils, lc_ldap] Pretty-printing de la date dans l'historique

This commit is contained in:
Olivier Iffrig 2010-10-18 00:46:37 +02:00
parent ae7d33c267
commit e239973d60
2 changed files with 21 additions and 10 deletions

View file

@ -29,7 +29,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import netaddr, re, time, smtplib, sys
import calendar, netaddr, re, time, smtplib, sys
sys.path.append('/usr/scripts/gestion')
import config
from unicodedata import normalize
@ -68,6 +68,15 @@ def mailexist(mail):
return r
def format_ldap_time(tm):
u"""Formatage des dates provenant de la base LDAP
Transforme la date YYYYMMDDHHMMSS.XXXXXXZ (UTC)
en date DD/MM/YY HH:MM (local)"""
tm_st = time.strptime(tm.split('.')[0], "%Y%m%d%H%M%S") # struct_time UTC
timestamp = calendar.timegm(tm_st)
tm_st = time.localtime(timestamp) # struct_time locale
return time.strftime("%d/%m/%Y %H:%M", tm_st)
def format_mac(mac):
u""" Formatage des adresses mac
Transforme une adresse pour obtenir la forme xx:xx:xx:xx:xx:xx