From 59bbcf66c85b7dc12d0b8cbdbbcbc9acfbb09343 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 21 Jun 2008 14:29:15 -0500 Subject: [PATCH] Cleanup and update remove-unused-soruces script. --- remove-unused-sources | 66 +++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/remove-unused-sources b/remove-unused-sources index dc883b0..42737fd 100755 --- a/remove-unused-sources +++ b/remove-unused-sources @@ -1,10 +1,26 @@ #!/bin/sh +# Copyright (C) 2008 Jonathan Moore Liles # +# # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the # +# Free Software Foundation; either version 2 of the License, or (at your # +# option) any later version. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with This program; see the file COPYING. If not,write to the Free Software # +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # + ## remove-unused-sources # # April 2008, Jonathan Moore Liles # -# Simple script to scan a compacted Non-DAW session and remove all +# Simple script to scan a compacted Non-DAW project and remove all # unused sources from disk. # # USAGE: @@ -17,7 +33,8 @@ # delete all unused sources! You have been warned. # -SESSION="$1" +DRY_RUN=no +ONLY_COMPACTED=no fatal () { @@ -27,9 +44,14 @@ fatal () exit 1 } +cleanup () +{ + rm -f "${TEMP}/all-sources" "${TEMP}/used-sources" +} + set_diff () { - diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2" + diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2" } remove_sources () @@ -37,26 +59,40 @@ remove_sources () local FILE while read FILE do - echo "Removing source \"${FILE}\"..." - - rm -f ./"${FILE}" ./"${FILE}-"*.peak + if [ $DRY_RUN = yes ] + then + echo "Would remove: ${FILE}" + else + echo "Removing unused source \"${FILE}\"..." + rm -f ./"${FILE}" ./"${FILE}-"*.peak + fi done } -cleanup () -{ - rm -f "${TEMP}/all-sources" "${TEMP}/used-sources" -} +[ $# -gt 0 ] || fatal "Usage: $0 [--dry-run] path/to/project" -cd "$SESSION" || fatal "No such session" +if [ "$1" = --dry-run ] +then + DRY_RUN=yes + shift 1 +fi -[ -f history ] || fatal "Not a Non-DAW session?" +PROJECT="$1" -grep -qv 'create' history && fatal "Not a compacted session" +cd "$PROJECT" || fatal "No such project" -echo "Scanning \"${SESSION}\"..." +[ -f history ] && [ -f info ] || fatal "Not a Non-DAW project?" -sed -n 's/^Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources" +[ -f .lock ] && fatal "Project appears to be in use" + +if [ $ONLY_COMPACTED = yes ] +then + grep -v '\(^\{\|\}$\)\|create' history && fatal "Not a compacted project" +fi + +echo "Scanning \"${PROJECT}\"..." + +sed -n 's/^\s\+Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources" cd sources || fatal "Can't change to source directory"