Rewrite in Python

master
neingeist 9 years ago
parent 8d51bda0cc
commit e9ce95e511

@ -1,18 +1,24 @@
#!/bin/sh #!/usr/bin/python
from __future__ import division, print_function
import argparse
import os
import sys
dir=$1
if [ "$dir" = "" ]; then parser = argparse.ArgumentParser(
echo "Usage: $0 <dir>" >&2 description='Check that the directories given are empty')
exit 1 parser.add_argument(
fi 'directories', metavar='dir', nargs='+', type=str,
help='directory to be checked')
args = parser.parse_args()
count=`find "$dir" -mindepth 1 -maxdepth 1 | wc -l`
if [ "$count" = "0" ]; then for directory in args.directories:
echo "OK: '$dir' is empty." listdir = os.listdir(directory)
exit 0 if len(listdir) != 0:
else print('WARNING: Directory {} is not empty ({} entries)'
echo "WARNING: '$dir' is NOT empty ($count entries)." .format(directory, len(listdir)))
exit 1 sys.exit(1)
fi
print('OK: All given directories are empty')
sys.exit(0)

Loading…
Cancel
Save