updated log parser
authorroot p2p-next-02 <root@p2p-next-02.grid.pub.ro>
Fri, 17 Jun 2011 21:39:53 +0000 (00:39 +0300)
committerroot p2p-next-02 <root@p2p-next-02.grid.pub.ro>
Fri, 17 Jun 2011 21:39:53 +0000 (00:39 +0300)
ppf/log-parser-mysql/libtorrent/log_parser

index ca269c9..35bcc3d 100755 (executable)
@@ -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 <archive_file> <db_name>\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