Désormais, "quota2" est un peu plus propre.
This commit is contained in:
parent
5ef0534167
commit
407c1e4799
2 changed files with 56 additions and 52 deletions
56
utils/quota.py
Normal file
56
utils/quota.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
# -*- coding: utf8 -*-
|
||||
# Reloockage de quota.py, passage à l'intranet 2
|
||||
# On retire le sudo par défaut, l'user execute lui meme quota
|
||||
# Ecrit il y a longtemps, "dépoussiéré" et "enrichi" par
|
||||
# Gabriel Détraz detraz@crans.org
|
||||
|
||||
import subprocess
|
||||
|
||||
def getFloat(chose):
|
||||
chose = chose.replace(',', '.')
|
||||
return float(chose)
|
||||
|
||||
def getUserQuota(user):
|
||||
proc = subprocess.Popen(['sudo', 'quota', user], stdout=subprocess.PIPE)
|
||||
stdoutdata = proc.communicate()[0]
|
||||
string_result = stdoutdata.split("\n")
|
||||
quotas = []
|
||||
for a_line in string_result[2:-1]:
|
||||
usage, quota, limite, percentage, fs = a_line.split("\t")
|
||||
if "mail" in fs:
|
||||
label = u"Quota dans votre boite de réception"
|
||||
elif fs == "/home-adh/%s" % (user[0],):
|
||||
label = u"Quota dans votre home personnel"
|
||||
else:
|
||||
label = u"Quota dans %s" % (fs,)
|
||||
line_dict = {
|
||||
"label" : label,
|
||||
"usage" : getFloat(usage),
|
||||
"quota" : getFloat(quota),
|
||||
"limite" : getFloat(limite),
|
||||
"%" : getFloat(percentage),
|
||||
"filesystem" : fs, # 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
|
||||
}
|
||||
]
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
# -*- coding: utf8 -*-
|
||||
# Reloockage de quota.py, passage à l'intranet 2
|
||||
# On retire le sudo par défaut, l'user execute lui meme quota
|
||||
# Ecrit il y a longtemps, dépoussiéré et enrichi par
|
||||
# Gabriel Détraz detraz@crans.org
|
||||
|
||||
import subprocess
|
||||
|
||||
def getFloat( chose ):
|
||||
chose = chose.replace(',', '.')
|
||||
return float(chose)
|
||||
|
||||
def getUserQuota(user):
|
||||
proc = subprocess.Popen(['sudo','quota',user],stdout=subprocess.PIPE)
|
||||
stdoutdata = proc.communicate()[0]
|
||||
string_result = stdoutdata.split("\n")
|
||||
quotas = []
|
||||
for a_line in string_result[2:-1]:
|
||||
usage, quota, limite, percentage, fs = a_line.split("\t")
|
||||
if "mail" in fs:
|
||||
label= u"Quota dans votre boite de réception"
|
||||
elif fs=="/home-adh/"+user[0]:
|
||||
label= u"Quota dans votre home personnel"
|
||||
else:
|
||||
label=u"Quota dans " + fs
|
||||
line_dict = {
|
||||
"label":label,
|
||||
"usage":getFloat(usage),
|
||||
"quota":getFloat(quota),
|
||||
"limite":getFloat(limite),
|
||||
"%":getFloat(percentage),
|
||||
"filesystem":fs, # 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