#!/opt/imh-python/bin/python3
"""Fraud Hunter Tool for Chuck H."""
parser = argparse.ArgumentParser(description=__doc__)
'-n', '--name', dest='filenames', nargs='+', required=True,
help='File name(s) to look for',
'-e', '--exclude', dest='exc_user', nargs='+', default=[],
help='User(s) to exclude',
'-x', '--max', type=int, help='Max file size (in bytes)'
'-m', '--min', type=int, help='Min file size (in bytes)'
args = parser.parse_args()
print("The minimum size needs to be larger than the maximum size")
return args.filenames, args.exc_user, args.max, args.min
"""Get a list of users that aren't suspended, sys. users, or excluded"""
for user in rads.all_cpusers()
if user not in rads.OUR_RESELLERS
and not rads.cpuser_suspended(user)
def check_size(filename, maxsize, minsize):
"""Confirm filesize within argument constraints"""
size = os.path.getsize(filename)
"""Print any file that matches the filenames"""
user, filenames, maxsize, minsize = gdtuple
homedir = rads.get_homedir(user)
except rads.CpuserError as exc:
print(exc, file=sys.stderr)
for root, _, files in os.walk(homedir, topdown=False):
fullpath = os.path.join(root, name)
if maxsize is None and minsize is None:
if check_size(fullpath, maxsize, minsize):
def start_the_hunt(target_users, filenames, maxsize, minsize):
"""set up a multiprocessing queue to loop through accounts"""
args = ((user, filenames, maxsize, minsize) for user in target_users)
# shenanigans to deal with keyboard interrupts
original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
with multiprocessing.Pool(multiprocessing.cpu_count()) as pool:
signal.signal(signal.SIGINT, original_sigint_handler)
results = pool.map_async(hunter, args)
# dealing with Python bug https://bugs.python.org/issue8296
except multiprocessing.TimeoutError:
except KeyboardInterrupt:
print("Caught KeyboardInterrupt.")
'''Main function: get args'''
filenames, excluded, maxsize, minsize = get_args()
target_users = targets(excluded)
start_the_hunt(target_users, filenames, maxsize, minsize)
if __name__ == "__main__":