From 0c50e8b94c58c68f5a897d43f9857afd984ed1c3 Mon Sep 17 00:00:00 2001 From: William Ting Date: Mon, 30 Dec 2013 15:38:19 -0600 Subject: [PATCH] remove empty custom installation directories --- uninstall.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/uninstall.py b/uninstall.py index 9fc63e4..e928aff 100755 --- a/uninstall.py +++ b/uninstall.py @@ -10,6 +10,16 @@ import shutil import sys +def is_empty_dir(path): + """ + Checks if any files are present within a directory and all sub-directories. + """ + for _, _, files in os.walk(path): + if files: + return False + return True + + def parse_arguments(): parser = ArgumentParser( description='Uninstalls autojump.') @@ -57,6 +67,9 @@ def remove_custom_installation(args, dryrun=False): rmdir(icon_dir, dryrun) rm(os.path.join(doc_dir, 'autojump.1'), dryrun) + if is_empty_dir(args.destdir): + rmdir(args.destdir, dryrun) + def remove_system_installation(dryrun=False): default_destdir = '/'