MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / ClearMail

Function ClearMail

tools_en.py:443–470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

441
442# Clean mail logs
443def ClearMail():
444 rpath = '/var/spool'
445 total = count = 0
446 import shutil
447 con = ['cron', 'anacron', 'mail']
448 for d in os.listdir(rpath):
449 if d in con: continue
450 dpath = rpath + '/' + d
451 print('|-Cleaning ' + dpath + ' ...')
452 time.sleep(0.2)
453 num = size = 0
454 for n in os.listdir(dpath):
455 filename = dpath + '/' + n
456 fsize = os.path.getsize(filename)
457 print('|---[' + ToSize(fsize) + '] del ' + filename),
458 size += fsize
459 if os.path.isdir(filename):
460 shutil.rmtree(filename)
461 else:
462 os.remove(filename)
463 print('\t\033[1;32m[OK]\033[0m')
464 num += 1
465 print('|-Cleaned [' + dpath + '], deleted [' + str(num) + '] files, freed disk space [' + ToSize(size) + ']')
466 total += size
467 count += num
468 print('=======================================================================')
469 print('|-Spool cleaning completed, deleted [' + str(count) + '] files, freed disk space [' + ToSize(total) + ']')
470 return total, count
471
472
473# Clean PHP session files

Callers 1

ClearSystemFunction · 0.70

Calls 3

listdirMethod · 0.80
ToSizeFunction · 0.70
removeMethod · 0.45

Tested by

no test coverage detected