From 2e212a2d4cd19d607aa729a369d08f0d1d48d990 Mon Sep 17 00:00:00 2001 From: Mariana Marasoiu Date: Fri, 5 Aug 2011 20:26:10 +0300 Subject: [PATCH] minor changes in functionality for parsing scripts --- ppf/db-mysql/DatabaseAccess.py | 12 +++- ppf/db-mysql/db_init | 6 +- ppf/log-parser-mysql/libtorrent/log_parser | 2 +- .../libtorrent/parse_log_file | 2 +- ppf/log-parser-mysql/tribler/LogParser.py | 2 +- ppf/log-parser-mysql/tribler/log_parser | 63 +++++++++++++++++++ ppf/log-parser-mysql/tribler/parse_log_file | 22 +++++++ 7 files changed, 103 insertions(+), 6 deletions(-) create mode 100755 ppf/log-parser-mysql/tribler/log_parser create mode 100755 ppf/log-parser-mysql/tribler/parse_log_file diff --git a/ppf/db-mysql/DatabaseAccess.py b/ppf/db-mysql/DatabaseAccess.py index 6b31b9b..2e10578 100644 --- a/ppf/db-mysql/DatabaseAccess.py +++ b/ppf/db-mysql/DatabaseAccess.py @@ -310,6 +310,16 @@ def main(): dba.connect() + dba.insert_swarms_row(('dbex-fedora-i686-live-KDE', 100000, 'test', 'local')) + +# dba.insert_btclients_row(('libtorrent', 'C++', '1', '0')) + + dba.insert_client_sessions_row(('1', '2', 'Linux', '2.6.26', '512', '1500', '141.85.224.205', '50500', '512', '64', '2011-05-17 13:23:54')) + + dba.get_status() + + dba.disconnect() + """ for t in [('DarkKnight', '123000', 'experiment', 'TVTorrents'), ('Fedora', '1024', 'experiment', 'local'), ('Pulp Fiction', '102400', 'streaming', 'isohunt'), @@ -342,7 +352,7 @@ def main(): dba.select_btclient_by_name("Tribler") dba.disconnect() - + """ if __name__ == "__main__": sys.exit(main()) diff --git a/ppf/db-mysql/db_init b/ppf/db-mysql/db_init index 0f542e7..fedcfcd 100755 --- a/ppf/db-mysql/db_init +++ b/ppf/db-mysql/db_init @@ -1,6 +1,7 @@ #!/bin/bash -SQL_INIT_SCRIPT=../sql/p2p-log-mysql.sql +DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" +SQL_INIT_SCRIPT=$DIR_LOCAL/../sql/p2p-log-mysql.sql if test $# -ne 1; then echo "Usage: $0 db_name" @@ -9,6 +10,7 @@ fi DB_NAME=$1 -mysql --user=root --password=p2p4th3m42232 $DB_NAME <../sql/p2p-log-mysql.sql +mysql --user=root --password=p2p4th3m42232 -e "create database if not exists $DB_NAME" +mysql --user=root --password=p2p4th3m42232 $DB_NAME <$SQL_INIT_SCRIPT exit 0 diff --git a/ppf/log-parser-mysql/libtorrent/log_parser b/ppf/log-parser-mysql/libtorrent/log_parser index 35bcc3d..f25b9f0 100755 --- a/ppf/log-parser-mysql/libtorrent/log_parser +++ b/ppf/log-parser-mysql/libtorrent/log_parser @@ -53,7 +53,7 @@ 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 $SWARM_ID -f $DIR_ARCHIVE/temp/status.log $DB_NAME +yes y | 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" diff --git a/ppf/log-parser-mysql/libtorrent/parse_log_file b/ppf/log-parser-mysql/libtorrent/parse_log_file index 5cc13bf..09c43b6 100755 --- a/ppf/log-parser-mysql/libtorrent/parse_log_file +++ b/ppf/log-parser-mysql/libtorrent/parse_log_file @@ -5,7 +5,7 @@ DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" FILE=$1 if [ $# -lt 2 ]; then - echo -e "Usage: $0 \n" + echo -e "Usage: $0 \n" exit 1 fi diff --git a/ppf/log-parser-mysql/tribler/LogParser.py b/ppf/log-parser-mysql/tribler/LogParser.py index 0d6db4c..53215eb 100644 --- a/ppf/log-parser-mysql/tribler/LogParser.py +++ b/ppf/log-parser-mysql/tribler/LogParser.py @@ -34,7 +34,7 @@ def usage(): print "\tstatus_file:" print "\t--file" print "\t-f\t\tstatus_file for tribler" - print "\tdatabase\t\tSQLite database file" + print "\tdatabase\t\tMySQL database name" print "\t--help" print "\t-h\t\t\tprint this help screen" diff --git a/ppf/log-parser-mysql/tribler/log_parser b/ppf/log-parser-mysql/tribler/log_parser new file mode 100755 index 0000000..f25b9f0 --- /dev/null +++ b/ppf/log-parser-mysql/tribler/log_parser @@ -0,0 +1,63 @@ +#!/bin/bash + +ARCHIVE=$1 +DB_NAME=$2 +SWARM_ID=$3 +DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" +DIR_ARCHIVE="$(cd "$(dirname "$1")" && pwd)" + +if [ $# -lt 2 ]; then + echo -e "Usage: $0 \n" + exit 1 +fi + +# if clause to be comented before final use +#if test -d $DIR_ARCHIVE/temp; then +# echo -e "Skipping extraction...\n" +#else + +# remove temp folder in case it exists +rm -Rf $DIR_ARCHIVE/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" +popd +#fi + +# create database +pushd $DIR_LOCAL/../../db-mysql +$DIR_LOCAL/../../db-mysql/db_init $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" + +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 + 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" +yes y | 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 diff --git a/ppf/log-parser-mysql/tribler/parse_log_file b/ppf/log-parser-mysql/tribler/parse_log_file new file mode 100755 index 0000000..90b2644 --- /dev/null +++ b/ppf/log-parser-mysql/tribler/parse_log_file @@ -0,0 +1,22 @@ +#!/bin/bash + +DB_NAME=$2 +DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)" +FILE=$1 + +if [ $# -lt 2 ]; then + echo -e "Usage: $0 \n" + exit 1 +fi + +pushd $DIR_LOCAL/../../db-mysql +#fill database with test data +PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python DatabaseAccess.py $DB_NAME +popd + +# fill logging information +yes y | PYTHONPATH=$DIR_LOCAL/../../db-mysql/ python $DIR_LOCAL/LogParser.py -i 1 -f $FILE $DB_NAME +echo -e "Log file parsed\n" +echo -e "DONE!\n" + +exit 0 -- 2.20.1