summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.mdown14
-rwxr-xr-xdupekill102
2 files changed, 116 insertions, 0 deletions
diff --git a/README.mdown b/README.mdown
new file mode 100644
index 0000000..88c2356
--- /dev/null
+++ b/README.mdown
@@ -0,0 +1,14 @@
+# dupekill -- deletes duplicates of existing data
+
+dupekill is a simple dupe finder (and deleter). It comes with a few nifty flags:
+
+* `-d | --dry`: Provides a preview of what you will do if the `-d` flag is
+ removed.
+* `-r | --recursive`: Descends into all subdirectories below the starting
+ point.
+* `-v | --verbose`: Provide more detail.
+
+# Roadmap
+
+* Create options for file preference, e.g. "if two files are the same, prefer
+ the older one".
diff --git a/dupekill b/dupekill
new file mode 100755
index 0000000..91a059b
--- /dev/null
+++ b/dupekill
@@ -0,0 +1,102 @@
+#!/usr/bin/env python3
+import os
+import hashlib
+import sys
+import stat
+from optparse import OptionParser
+
+# dupekill - deletes duplicates of existing data
+# version 1.2
+# written by zlg <zlg@zlg.space>
+# and NF <radicalmori@gmail.com>
+#
+# licensed under the...
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# Copyright (C) 2004 Sam Hocevar
+# 14 rue de Plaisance, 75014 Paris, France
+# Everyone is permitted to copy and distribute verbatim or modified
+# copies of this license document, and changing it is allowed as long
+# as the name is changed.
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#
+# This program is free software. It comes without any warranty, to
+# the extent permitted by applicable law.
+#
+# You have been warned. >:3
+
+def dupekill():
+ usage = "Usage: %prog [options] {path}"
+ parser = OptionParser(usage=usage)
+ parser.add_option("-d", "--dry", dest='dry_run', action='store_true', default=False, help="displays a list of files dupekill will delete if you run it again without this flag")
+ parser.add_option("-r", "--recursive", dest='recursive', action='store_true', default=False, help="Recurses into all directories below the starting point")
+ parser.add_option("-v", "--verbose", dest='verbose', action='store_true', default=False, help="Provide more detailed output")
+ (options, args) = parser.parse_args()
+ if args and os.path.isdir(args[0]):
+ path = os.path.abspath(args[0])
+ else:
+ path = os.getcwd()
+
+ if not os.path.isdir(path):
+ print("Error: Unable to fetch directory to work with.")
+ sys.exit(1)
+ else:
+ # Create the generator, create the hash list and the counters.
+ file_list = os.walk(path)
+ hashList = []
+ processed_files = 0
+ deleted_files = 0
+
+ for root, dirs, file in file_list:
+ ignore_dirs = ['.git', '.config']
+ for dir in ignore_dirs:
+ if options.recursive == True:
+ # Recursion still needs to ignore certain dirs
+ if dir in dirs:
+ dirs.remove(dir)
+
+ else:
+ # While no recursion doesn't need _any_ dirs!
+ while dirs:
+ dirs.pop()
+
+ for item in file:
+ checkedFile = open(os.path.join(root, item), "rb").read()
+ hash = hashlib.sha256(checkedFile).hexdigest()
+ processed_files += 1
+
+ if len(hashList) > 0 and hash in hashList:
+ # We want to count these, even if it's a dry run.
+ deleted_files += 1
+
+ if not options.dry_run:
+ os.remove(os.path.join(root, item))
+
+ if options.verbose:
+ print("Dupe", os.path.join(root, item), "found.")
+
+ else:
+ hashList.append(hash)
+
+ if options.verbose:
+ print("New file", os.path.join(root, item))
+
+ # Print a summary
+ print()
+
+ if options.dry_run:
+ print("THIS IS A DRY RUN! NO FILES WILL BE ALTERED!")
+
+ print(processed_files, "files processed,", deleted_files, "deleted.\n")
+
+if __name__ == '__main__':
+ try:
+ dupekill()
+ except KeyboardInterrupt:
+ print("Aborted")
=v0.3b8&id=eee8ed0c7b4de40f3568bdc08ad4af4837b54341&follow=1'>Update LICENSE to match setup.pyzlg1-80/+67 Whoops. 2018-09-03Branch off from master with pytest, tox, clickzlg16-778/+779 This commit is huge, but contains everything needed for a "proper" build system built on pytest + tox and a CLI built with click. For now, this branch will contain all new vgstash development activity until it reaches feature parity with master. The CLI is installed to pip's PATH. Only the 'init', 'add', and 'list' commands work, with only two filters. This is pre-alpha software, and is therefore not stable yet. 2018-03-18Flesh out filter types and ownership statuszlg3-82/+144 It's time for a refactor to a module; the functionality and interface are clashing. 2018-03-18README.mdown: break line correctlyzlg1-1/+1 2018-03-18add 'playlog' list filterzlg2-2/+9 This filter is used to get an idea of which games you're currently playing through, so you can prioritize games to play when you're bored and detect it when you've beaten a game but haven't marked it as such. 2018-03-13Update helpers a bitzlg1-2/+9 At present, user modification is needed to make these seamless. vgup() may need to be axed in favor of telling the user to make an alias. 2018-03-13Make VGSTASH_DB_LOCATION point to a filezlg2-21/+20 It used to point to a directory, which would then look for .vgstash.db. This behavior was kind of backwards and I don't remember why I did it that way. This change gives users more control over where they put their DB. Be sure to update your environment variable if you have it set! 2016-11-18Remove settings from helpers.shZe Libertine Gamer1-5/+0 Sourcing them in .bash_profile screws up login if they're set. 2016-11-15Correct phrasing in README.Ze Libertine Gamer1-4/+4 2016-11-13DerpZe Libertine Gamer1-0/+1 2016-11-03Improve error handling in shell scriptsZe Libertine Gamer4-3/+23 2016-10-24Correct run_again, add recursionZe Libertine Gamer1-0/+4 Loops and functions -- oh my, what a useful combination. :) 2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1 2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101 2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9 2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5 Also correct a typo.