more powerful scrubbing package for getting rid of files with same names: cleanerator
authorChris Koeritz <fred@gruntose.com>
Mon, 16 Jan 2012 16:42:06 +0000 (11:42 -0500)
committerChris Koeritz <fred@gruntose.com>
Mon, 16 Jan 2012 16:42:06 +0000 (11:42 -0500)
will scan across a hierarchy and consider N other hierarchies authoritative versions of
similar code.  if the cleaning directories have any files with the same names as the
authoritative directories, then the files are removed.  be really careful with this!
it's a powerful nuke on all your files, especially if you have a directory in both the
cleaning and authoritative lists!

scripts/files/cleanerator.sh [new file with mode: 0644]
scripts/rev_control/svn_rm_dupes.sh

diff --git a/scripts/files/cleanerator.sh b/scripts/files/cleanerator.sh
new file mode 100644 (file)
index 0000000..45b2679
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+cleaning_dirs=($*)
+
+more_authoritative=( ~/quartz/example_source_code/inova_legacy ~/feisty_meow ~/scavenging_inova/inovasoft )
+###not yet ~/scavenging_inova/lightlink 
+
+if [ -z "$TMP" ]; then TMP=/tmp; fi
+
+# we generate the full directory list for the authoritative places into here.
+zesty_authoritative_dirs=$(mktemp $TMP/cleanerator_authority.XXXXXX)
+# we also make a list of all the directories under our cleaning locations here.
+perky_scrubbing_dirs=$(mktemp $TMP/cleanerator_scrubbinz.XXXXXX)
+
+# dump out the directories found in the authoritative areas.
+for i in "${more_authoritative[@]}"; do
+  real_dir="$(\cd "$i" && \pwd)"
+  find "$real_dir" -type d | grep -v "\.svn" | grep -v "\.git" >>"$zesty_authoritative_dirs"
+done
+
+# now go to all of our places to clean, find all directories under them,
+# and add them to our big list of places to scrub.
+for i in "${cleaning_dirs[@]}"; do
+  real_dir="$(\cd "$i" && \pwd)"
+  find "$real_dir" -depth -type d | grep -v "\.svn" | grep -v "\.git" >>"$perky_scrubbing_dirs"
+done
+
+# load all the names from our files and do a massive N x M size loop.
+while read i; do
+#  echo "cleaning: $i"
+  pushd "$i" &>/dev/null
+#pwd
+  while read j; do 
+#    echo "against authority: $j"
+    # try to clean it out of source control first.
+    bash ~/feisty_meow/scripts/rev_control/svn_rm_dupes.sh "$j" "$i"
+    # if that doesn't work, just whack it.
+    bash ~/feisty_meow/scripts/files/whack_dupes.sh "$j" "$i"
+  done <"$zesty_authoritative_dirs"
+  popd &>/dev/null
+done <"$perky_scrubbing_dirs"
+
+# clean up afterwards.
+rm -f "$zesty_authoritative_dirs"
+rm -f "$perky_scrubbing_dirs"
+
index 404ad073be4aaf19e1c9cc18a7ee7b622d8530f0..70448ddedba832ab2bb0ceb8be63454f52234f37 100644 (file)
@@ -7,6 +7,8 @@
 exemplar_dir="$1"; shift
 whack_dir="$1"; shift
 
+#hmmm: much code here is shared with whack_dupes.  get into a library.
+
 # make sure they gave us a good directory to start with.
 if [ -z "$exemplar_dir" ]; then
   echo "whack_dupes"
@@ -44,6 +46,12 @@ if [ ! -z "$whack_dir" ]; then
   pushd "$whack_dir" &>/dev/null
 fi
 
+# now that we're in the directory to clean, make sure we're good there.
+if [ ! -d ".svn" ]; then
+#  echo "Could not find a subversion directory; operation would be pointless."
+  exit 0
+fi
+
 current_dir="$(pwd)"
 
 #echo "currdir=$current_dir gooddir=$the_good_place"
@@ -54,11 +62,6 @@ if [ "$current_dir" == "$the_good_place" ]; then
   exit 4
 fi
 
-if [ ! -d ".svn" ]; then
-  echo "Could not find a subversion directory; operation would be pointless."
-  exit 1
-fi
-
 # do the real work now...
 for i in *; do
   if [ -f "$exemplar_dir/$i" ]; then