You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
925 B
Python
33 lines
925 B
Python
#!/usr/bin/python3
|
|
from __future__ import division, print_function
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description='Check that the directories given are empty')
|
|
parser.add_argument(
|
|
'directories', metavar='dir', nargs='+', type=str,
|
|
help='directory to be checked')
|
|
parser.add_argument(
|
|
'--no-count-empty', dest='count_empty', action='store_false',
|
|
help='do not count empty files (useful to check /var/mail)')
|
|
args = parser.parse_args()
|
|
|
|
|
|
for directory in args.directories:
|
|
listdir = os.listdir(directory)
|
|
|
|
if not args.count_empty:
|
|
listdir = [fn for fn in listdir
|
|
if os.path.getsize(os.path.join(directory, fn)) > 0]
|
|
|
|
if len(listdir) != 0:
|
|
print('WARNING: Directory {} is not empty ({} entries)'
|
|
.format(directory, len(listdir)))
|
|
sys.exit(1)
|
|
|
|
print('OK: All given directories are empty')
|
|
sys.exit(0)
|