Mise en forme.

darcs-hash:20060406030222-68412-0dbc2a0cc3d34c3e5de5ee2607f35ad0a5cf3fd7.gz
This commit is contained in:
glondu 2006-04-06 05:02:22 +02:00
parent 8d76992b10
commit cd8bafd791

View file

@ -10,42 +10,48 @@ from affich_tools import cprint, anim, OK, WARNING, ERREUR
import config import config
from time import strftime from time import strftime
class del_user : class del_user:
""" Suppression des fichiers d'un compte utilisateur """
debug = True debug = True
def __init__(self,args) :
self.args=args def __init__(self,args):
def reconfigure(self) : self.args = args
def reconfigure(self):
cprint(u'Archivage fichiers utilisateur', 'gras') cprint(u'Archivage fichiers utilisateur', 'gras')
for args in self.args : for args in self.args:
anim('\t' + args) anim('\t' + args)
try: try:
login, home = args.split(',') login, home = args.split(',')
if not login or not home : if not login or not home:
raise ValueError('Argument invalide') raise ValueError('Argument invalide')
warn = '' warn = ''
f = config.cimetiere + '/files/' + strftime('%Y-%m-%d-%Hh%Mm_') + login + '.tar.bz2' f = '%s/files/%s_%s.tar.bz2' % (config.cimetiere,
status, output = commands.getstatusoutput("tar cjf '%s' '%s' /var/spool/mail/%s" % ( f,home,login) ) strftime('%Y-%m-%d-%Hh%Mm'),
if ( status != 512 and status!=0 ) or not os.path.isfile(f) : login)
status, output = commands.getstatusoutput("tar cjf '%s' '%s' /var/spool/mail/%s" % (f, home, login))
if (status != 512 and status != 0) or not os.path.isfile(f):
# La 512 est si un des paths n'exite pas. # La 512 est si un des paths n'exite pas.
raise OSError(output) raise OSError(output)
if os.path.isdir(home) and os.stat(home)[4] >= 500 : if os.path.isdir(home) and os.stat(home)[4] >= 500:
shutil.rmtree(home) shutil.rmtree(home)
else : else:
warn += '%s incorrect\n' % home warn += '%s incorrect\n' % home
if os.path.isdir('/var/spool/mail/' + login ) : if os.path.isdir('/var/spool/mail/' + login):
shutil.rmtree('/var/spool/mail/' + login) shutil.rmtree('/var/spool/mail/' + login)
else : else:
warn += '/var/spool/mail/%s incorrect\n' % login warn += '/var/spool/mail/%s incorrect\n' % login
if warn : if warn:
print WARNING print WARNING
if self.debug : if self.debug:
sys.stderr.write(warn) sys.stderr.write(warn)
else : else:
print OK print OK
except : except:
print ERREUR print ERREUR
if self.debug : if self.debug:
import traceback import traceback
traceback.print_exc() traceback.print_exc()
@ -65,11 +71,11 @@ class home:
os.mkdir(home, 0755) os.mkdir(home, 0755)
os.chown(home, int(uid) ,config.gid) os.chown(home, int(uid) ,config.gid)
elif os.path.isdir(home) : elif os.path.isdir(home) :
# Il y un r-bépertoire existant-A # Il y un répertoire existant
# Bon UID ? # Bon UID ?
stat = os.stat(home) stat = os.stat(home)
if stat[4] != int(uid) or stat[5] != config.gid : if stat[4] != int(uid) or stat[5] != config.gid :
# Le home n'est pas -bà la bonne personne-A # Le home n'est pas à la bonne personne
raise OSError('home existant') raise OSError('home existant')
### Quota ### Quota