From 129ae970e19dbeeeb0b9beb01ecd927e16d261ce Mon Sep 17 00:00:00 2001 From: p2p p2p-next-02 Date: Wed, 13 Apr 2011 17:40:38 +0300 Subject: [PATCH] ppf/log-parser: script to parse an archive --- ppf/log-parser/libtorrent/README | 4 +++ ppf/log-parser/libtorrent/log_parser | 45 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 ppf/log-parser/libtorrent/log_parser diff --git a/ppf/log-parser/libtorrent/README b/ppf/log-parser/libtorrent/README index 3780f4e..a4f9f79 100644 --- a/ppf/log-parser/libtorrent/README +++ b/ppf/log-parser/libtorrent/README @@ -14,6 +14,10 @@ Basename must have ${IP_ADDRESS}_${LISTEN_PORT}.log syntax. The parser recognizes the message types as defined in the BitTorrent specification[1]. +== log_parser == + +libtorrent log files script parser. Receives a .tar.gz archive as argument. + == sample run == In order to see the above modules at work, use the run_sample script. Just diff --git a/ppf/log-parser/libtorrent/log_parser b/ppf/log-parser/libtorrent/log_parser new file mode 100755 index 0000000..627e4c4 --- /dev/null +++ b/ppf/log-parser/libtorrent/log_parser @@ -0,0 +1,45 @@ +#!/bin/bash + +DB_NAME=test.db +DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" +ARCHIVE=$1 + +# remove temp folder in case it exists +rm -Rf temp + +# extract archive in folder ./temp +mkdir temp +echo -e "Extracting archive..." +tar --transform='s,^,temp/,' -xzf "$ARCHIVE" +echo -e "Archive extracted successfully." + +# remove database in case it exists +rm -f $DIR_LOCAL/$DB_NAME + +# create database +pushd $DIR_LOCAL/../../db/ +./db_init $DIR_LOCAL/$DB_NAME +echo -e "Database created." + +# fill database with test data +PYTHONPATH=$DIR/../../db/ python DatabaseAccess.py $DIR_LOCAL/$DB_NAME +popd + +# fill logging information +echo -e "Parsing log files" +for folder in $(find $DIR_LOCAL/temp -type d -name 'libtorrent_logs*' | sort ); do + for log_file in $(find $folder -type f | sort); do + yes y | PYTHONPATH=$DIR_LOCAL/../../db/ python $DIR_LOCAL/LogParser.py -i 1 -f $log_file $DIR_LOCAL/$DB_NAME + done +done +echo -e "Log files parsed." + +# fill status information +echo -e "Parsing status file." +PYTHONPATH=$DIR_LOCAL/../../db/ python $DIR_LOCAL/StatusParser.py -i 1 -f $DIR_LOCAL/temp/status.log $DIR_LOCAL/$DB_NAME +echo -e "Status file parsed." + +echo -e "DONE!" + +rm -Rf temp +exit 0 -- 2.20.1