From 3d38c14e35685856a37539f2eb7cf3aa81b0e15f Mon Sep 17 00:00:00 2001 From: Mariana Marasoiu Date: Sat, 18 Jun 2011 00:39:53 +0300 Subject: [PATCH] updated log parser --- ppf/log-parser-mysql/libtorrent/log_parser | 39 +++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/ppf/log-parser-mysql/libtorrent/log_parser b/ppf/log-parser-mysql/libtorrent/log_parser index ca269c9..35bcc3d 100755 --- a/ppf/log-parser-mysql/libtorrent/log_parser +++ b/ppf/log-parser-mysql/libtorrent/log_parser @@ -1,8 +1,10 @@ #!/bin/bash +ARCHIVE=$1 DB_NAME=$2 +SWARM_ID=$3 DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" -ARCHIVE=$1 +DIR_ARCHIVE="$(cd "$(dirname "$1")" && pwd)" if [ $# -lt 2 ]; then echo -e "Usage: $0 \n" @@ -10,45 +12,52 @@ if [ $# -lt 2 ]; then fi # if clause to be comented before final use -if test -d temp; then - echo -e "Skipping extraction...\n" -else +#if test -d $DIR_ARCHIVE/temp; then +# echo -e "Skipping extraction...\n" +#else # remove temp folder in case it exists -rm -Rf temp +rm -Rf $DIR_ARCHIVE/temp -# extract archive in folder ./temp +# extract archive in folder $DIR_ARCHIVE/temp +pushd $DIR_ARCHIVE mkdir temp echo -e "Extracting archive...\n" tar --transform='s,^,temp/,' -xzf "$ARCHIVE" echo -e "Archive extracted successfully.\n" -fi +popd +#fi # create database -pushd $DIR_LOCAL/../../db-mysql/ +pushd $DIR_LOCAL/../../db-mysql $DIR_LOCAL/../../db-mysql/db_init $DB_NAME -echo -e "Database created.\n" -# fill database with test data -PYTHONPATH=$DIR/../../db-mysql/ python DatabaseAccess.py $DB_NAME +#fill database with test data +PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python DatabaseAccess.py $DB_NAME popd # fill logging information echo -e "Parsing log files. \n" -echo $DIR_LOCAL -for folder in $( find $DIR_LOCAL/temp -type d -name 'libtorrent_logs*' | sort ); do + +pushd $DIR_LOCAL + +for folder in $( find $DIR_ARCHIVE/temp -type d -name 'libtorrent_logs*' | sort ); do for log_file in $(find $folder -type f | sort); do - yes y | PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python $DIR_LOCAL/LogParser.py -i 1 -f $log_file $DB_NAME + if [[ "$log_file" =~ [[:digit:]]*.log ]]; then + echo "$log_file" + yes y | PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python $DIR_LOCAL/LogParser.py -i $SWARM_ID -f $log_file $DB_NAME + fi done done echo -e "Log files parsed.\n" # fill status information echo -e "Parsing status file.\n" -PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python $DIR_LOCAL/StatusParser.py -i 1 -f $DIR_LOCAL/temp/status.log $DB_NAME +PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python $DIR_LOCAL/StatusParser.py -i $SWARM_ID -f $DIR_ARCHIVE/temp/status.log $DB_NAME echo -e "Status file parsed.\n" echo -e "DONE!\n" rm -Rf temp +popd exit 0 -- 2.20.1