From b288dc1ee852764d05a79c6b15261ad8fdda791b Mon Sep 17 00:00:00 2001 From: vonavi Date: Mon, 15 Dec 2014 20:39:07 +0300 Subject: [PATCH] Script 'game-add': check for duplicate game. --- game-add | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/game-add b/game-add index 1421e90..8b1a01b 100755 --- a/game-add +++ b/game-add @@ -30,9 +30,11 @@ Usage: The first form fills the results of chess games and stores their PGN files, assuming that all the games were played by the same pair of - players on tour of the tournament. The PGN files are sorted by - their timestamps, unless '-u' is set. Each game should be available - at the corresponding (lichess.org). + players on tour of the tournament. Each game should be + available at the corresponding (lichess.org). The PGN files + are sorted by their timestamps, unless '-u' is set. The date of + games is assigned to that of the game closing the tour, i.e., the + last one. The second form shows this help output. The third form shows version information. @@ -50,6 +52,16 @@ function version { exec echo "${argv0}-${VERSION}" } +function game_check_args { + # For now, tour number should be given explicitly + [[ -z $TOUR || $# == 0 ]] && usage 1 + # Don't add and clean up games simultaneously + $ADD_GAMES && $CLEANUP_GAMES && usage 1 + # Check for duplicate URL + local url_uniq=$(xargs -n1 <<< "$@" | sort -u | wc -l) + (( $# == $url_uniq )) || die "Game URLs not unique." +} + function game_setup { date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}" : ${REPO_DIR:=`dirname "$0"`} @@ -327,7 +339,7 @@ function die { exit 1 } -function checkargs { +function game_tour { [[ $OPTARG =~ ^[0-9]+$ ]] || die "Incorrect tour number." TOUR=$(printf "%02g" $OPTARG) } @@ -339,20 +351,16 @@ while getopts act:uhv opt; do case $opt in a) ADD_GAMES=true ;; c) CLEANUP_GAMES=true ;; - t) checkargs ;; + t) game_tour ;; u) SORT_GAMES=false ;; h) usage ;; v) version ;; *) usage 1 ;; esac done - shift $(($OPTIND - 1)) -# For now, tour number should be given explicitly -[[ -z $TOUR || $# == 0 ]] && usage 1 -# Don't add and clean up games simultaneously -$ADD_GAMES && $CLEANUP_GAMES && usage 1 +game_check_args $@ game_setup declare -a TMP_PGN_FILES game_tmp_pgns $@