Compare commits
No commits in common. "d743baa4d491655b141d7c4c37c89dc5916daead" and "dcbc0b23d6ec7bb7d293f5144398a80608499de8" have entirely different histories.
d743baa4d4
...
dcbc0b23d6
19
tag.sh
19
tag.sh
|
@ -18,14 +18,7 @@ set -ueo pipefail
|
|||
# FIXME: adding tags doesn't work
|
||||
|
||||
SCRIPT_DIR=$(dirname $(readlink "$0"))
|
||||
CURRENT_DIR=$(dirname "$PWD")
|
||||
SCRIPT_NAME=$(basename "$0")
|
||||
|
||||
|
||||
DB_FILE="${CURRENT_DIR}/tags.db"
|
||||
[ "$1" = "--db" ] && DB_FILE="$2" && shift 2
|
||||
|
||||
|
||||
DB_FILE="tags.db"
|
||||
DB_SCHEMA="${SCRIPT_DIR}/database.sql"
|
||||
declare -A FILTERS
|
||||
FILTERS[video]="avi|flv|mkv|mov|mp4|mpg|ogv|webm|wmv"
|
||||
|
@ -41,10 +34,9 @@ log() {
|
|||
}
|
||||
|
||||
init() {
|
||||
# DB_NAME
|
||||
[ -f "$1" ] && fail "Database file \"$1\" already exists. Aborting."
|
||||
cat "$DB_SCHEMA" | sqlite3 "$1"
|
||||
log "Empty database file \"$1\" created."
|
||||
[ -f "$DB_FILE" ] && fail "Database file \"$DB_FILE\" already exists. Aborting."
|
||||
cat "$DB_SCHEMA" | sqlite3 "$DB_FILE"
|
||||
log "Empty database file \"$DB_FILE\" created."
|
||||
}
|
||||
|
||||
enumerate_positional_parameters() {
|
||||
|
@ -134,7 +126,7 @@ add_path_auto() {
|
|||
|
||||
main() {
|
||||
if [[ "$1" = "init" ]]; then
|
||||
init "${2:-$DB_FILE}"
|
||||
init
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
@ -190,7 +182,6 @@ main() {
|
|||
fi
|
||||
|
||||
if [[ "$1" = "listtags" ]]; then
|
||||
[ -z "${2:-}" ] && fail "Usage: $SCRIPT_NAME listtags filename"
|
||||
listtags "$2"
|
||||
exit 0
|
||||
fi
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ueo pipefail
|
||||
|
||||
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
|
||||
DB_FILE="test.db"
|
||||
|
||||
oneTimeSetUp() {
|
||||
tag --db "$DB_FILE" init >/dev/null
|
||||
}
|
||||
|
||||
oneTimeTearDown() {
|
||||
# need to check if file exists
|
||||
# because of bug in shunit2 that
|
||||
# runs one-time teardown two times
|
||||
# see https://github.com/kward/shunit2/issues/112
|
||||
[ -f "$DB_FILE" ] && rm "$DB_FILE"
|
||||
}
|
||||
|
||||
testDbCreated() {
|
||||
assertTrue "[[ -f \"$DB_FILE\" ]]"
|
||||
}
|
||||
|
||||
testTagAdded() {
|
||||
tag --db "$DB_FILE" add tag hello >/dev/null
|
||||
RESULT=$(sqlite3 "$DB_FILE" "SELECT label from tags WHERE label = 'hello'")
|
||||
assertEquals $RESULT "hello"
|
||||
}
|
||||
|
||||
testFilenameAdded() {
|
||||
local FILENAME="test.mp4"
|
||||
tag --db "$DB_FILE" add path "$FILENAME" >/dev/null
|
||||
RESULT=$(sqlite3 "$DB_FILE" "SELECT filename from files WHERE filename = '$FILENAME'")
|
||||
assertEquals "$RESULT" "$FILENAME"
|
||||
}
|
||||
|
||||
testHashAdded() {
|
||||
local HASH="fbe2153ce0614d76a378b2e6fe07cc9e"
|
||||
tag --db "$DB_FILE" add hash "$HASH" >/dev/null
|
||||
RESULT=$(sqlite3 "$DB_FILE" "SELECT md5 from hashes WHERE hash = '$HASH'")
|
||||
assertEquals "$RESULT" "$HASH"
|
||||
}
|
||||
|
||||
. ../shunit2/shunit2
|
Loading…
Reference in New Issue