Просмотр исходного кода

Consolidate the load-checking code, for easier re-use. Interrupt multi-file actions if the load increases while we are running.

Zachary Kotlarek 13 лет назад
Родитель
Сommit
bb8ebee655
5 измененных файлов с 31 добавлено и 24 удалено
  1. 16 0
      checkLoad.sh
  2. 2 2
      checkTorrent
  3. 5 0
      findRecode
  4. 2 9
      folderFixup.sh
  5. 6 13
      folderToMKV.sh

+ 16 - 0
checkLoad.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# Bail if the load average is high
+LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
+CPU_COUNT="`sysctl -n hw.ncpu`"
+if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
+	exit 1
+fi
+
+# Bail if WoW is running
+if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft-64.app/Contents/MacOS/World of Warcraft-64"; then
+	exit 1
+fi
+
+# Otherwise exit cleanly
+exit 0

+ 2 - 2
checkTorrent

@@ -4,8 +4,8 @@
 TORRENT_APP="/Applications/Zach/Internet/Transmission.app"
 TORRENT_BIN="${TORRENT_APP}/Contents/MacOS/Transmission"
 
-# Bail if WoW is running
-if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft-64.app/Contents/MacOS/World of Warcraft-64"; then
+# Bail if the load is high
+if ! ~/bin/video/checkLoad.sh; then
 	exit 0
 fi
 

+ 5 - 0
findRecode

@@ -45,6 +45,11 @@ OLDIFS="${IFS}"
 IFS=$'\n'
 for i in ${FILES}; do
 
+	# Bail if the load is high
+	if ! ~/bin/video/checkLoad.sh; then
+		continue
+	fi
+
 	# Skip invalid files
 	if [ -z "${i}" ] || [ ! -r "${i}" ] || basename "${i}" | grep -q '^\._'; then
 		continue

+ 2 - 9
folderFixup.sh

@@ -18,15 +18,8 @@ if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 2 ]; then
 	exit 0
 fi
 
-# Bail if the load average is high
-LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
-CPU_COUNT="`sysctl -n hw.ncpu`"
-if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
-	exit 0
-fi
-
-# Bail if WoW is running
-if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft-64.app/Contents/MacOS/World of Warcraft-64"; then
+# Bail if the load is high
+if ! ~/bin/video/checkLoad.sh; then
 	exit 0
 fi
 

+ 6 - 13
folderToMKV.sh

@@ -13,18 +13,6 @@ if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 10 ]; then
 	exit 0
 fi
 
-# Bail if the load average is high
-LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
-CPU_COUNT="`sysctl -n hw.ncpu`"
-if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
-	exit 0
-fi
-
-# Bail if WoW is running
-if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft-64.app/Contents/MacOS/World of Warcraft-64"; then
-	exit 0
-fi
-
 # Prefer recoding to rewrapping if the file is overrate
 ~/bin/video/findRecode0 "${inFolder}" | xargs -0 -n1 ~/bin/video/recode
 
@@ -44,7 +32,12 @@ inFolder="`cd "${inFolder}" && pwd`"
 cd "${inFolder}"
 
 # Cycle through the folder looking for certain video files that should be converted to better containers
-for i in *.[aA][vV][iI] *.[wW][mM][vV] *.[dD][iI][vV][xX] *.[fF][lL][vV]; do
+for i in *.[aA][vV][iI] *.[wW][mM][vV] *.[dD][iI][vV][xX] *.[fF][lL][vV] *.[mM][pP]4; do
+	# Bail if the load is high
+	if ! ~/bin/video/checkLoad.sh; then
+		continue
+	fi
+
 	# Construct the full path
 	file="${inFolder}/${i}"