[lib] ajout des fichiers non suivis
darcs-hash:20090609134320-bd074-f4df3e57ff2a6e60f07e25cda773524c8e20de3c.gz
This commit is contained in:
parent
dce8ccb6da
commit
c2535c1f04
17 changed files with 2346 additions and 0 deletions
36
lib/utils/logs.py
Normal file
36
lib/utils/logs.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf8 -*-
|
||||
""" Cr@ns logging : logging utilities for cr@ns scripts
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
LOG_FOLDER = "/var/log/crans/"
|
||||
__version__ = "0.1"
|
||||
|
||||
def getFileLogger(name):
|
||||
LOGGER.warning("getFileLogger is deprecated, use CransFileHandler instead.")
|
||||
logger = logging.getLogger(name)
|
||||
hdlr = CransFileHandler(name)
|
||||
logger.addHandler(hdlr)
|
||||
logger.setLevel(logging.INFO)
|
||||
return logger
|
||||
|
||||
class CransFileHandler(logging.FileHandler):
|
||||
def __init__(self, name):
|
||||
filepath = os.path.join(LOG_FOLDER, name + ".log")
|
||||
logging.FileHandler.__init__(self, filepath)
|
||||
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
|
||||
self.setFormatter(formatter)
|
||||
|
||||
### Un peu de configuration
|
||||
# On log systematiquement les warning, error, exception sous "crans"
|
||||
# sur l'ecran.
|
||||
CRANSLOGGER = logging.getLogger("crans")
|
||||
CRANSLOGGER.setLevel(logging.WARNING)
|
||||
streamhdlr = logging.StreamHandler()
|
||||
streamhdlr.setLevel(logging.ERROR)
|
||||
streamhdlr.setFormatter(logging.Formatter('%(levelname)s: %(message)s'))
|
||||
CRANSLOGGER.addHandler(streamhdlr)
|
||||
CRANSLOGGER.addHandler(CransFileHandler("crans"))
|
||||
|
||||
LOGGER = logging.getLogger("crans.logging")
|
50
lib/utils/quota.py
Normal file
50
lib/utils/quota.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
|
||||
# -*- coding: utf8 -*-
|
||||
import os
|
||||
|
||||
LABELS = {
|
||||
"/home":u"Dossier personnel",
|
||||
"/var/mail":u"Boite de réception"
|
||||
}
|
||||
|
||||
def getFloat( chose ):
|
||||
chose = chose.replace(',', '.')
|
||||
return float(chose)
|
||||
|
||||
def getUserQuota( userLogin ):
|
||||
pipe = os.popen("sudo quota %s" % userLogin)
|
||||
string_result = pipe.read()
|
||||
pipe.close()
|
||||
string_result = string_result.split("\n")
|
||||
quotas = []
|
||||
for a_line in string_result[2:3]:
|
||||
usage, quota, limite, percentage = a_line.split("\t")
|
||||
line_dict = {
|
||||
"label": "Quota personnel",
|
||||
"usage":getFloat(usage),
|
||||
"quota":getFloat(quota),
|
||||
"limite":getFloat(limite),
|
||||
"%":getFloat(percentage),
|
||||
"filesystem":"rda", # pourquoi pas ?
|
||||
}
|
||||
quotas.append(line_dict)
|
||||
return quotas
|
||||
|
||||
|
||||
|
||||
def fake_getUserQuota( userLogin ):
|
||||
return [
|
||||
{'%': 33.9,
|
||||
'quota': 390.62,
|
||||
'label': u'Dossier personnel (fake)',
|
||||
'limite': 585.94,
|
||||
'filesystem': '/home',
|
||||
'usage': 420.32},
|
||||
{'%': 0.1,
|
||||
'quota': 100.00,
|
||||
'label': u'Boite de r\xe9ception (fake)',
|
||||
'limite': 150.00,
|
||||
'filesystem': '/var/mail',
|
||||
'usage': 0.06}
|
||||
]
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue