minor changes in functionality for parsing scripts
authorMariana Marasoiu <mariana.marasoiu@gmail.com>
Fri, 5 Aug 2011 17:26:10 +0000 (20:26 +0300)
committerroot p2p-next-02 <root@p2p-next-02.grid.pub.ro>
Fri, 5 Aug 2011 17:26:10 +0000 (20:26 +0300)
ppf/db-mysql/DatabaseAccess.py
ppf/db-mysql/db_init
ppf/log-parser-mysql/libtorrent/log_parser
ppf/log-parser-mysql/libtorrent/parse_log_file
ppf/log-parser-mysql/tribler/LogParser.py
ppf/log-parser-mysql/tribler/log_parser [new file with mode: 0755]
ppf/log-parser-mysql/tribler/parse_log_file [new file with mode: 0755]

index 6b31b9b..2e10578 100644 (file)
@@ -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())
index 0f542e7..fedcfcd 100755 (executable)
@@ -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
index 35bcc3d..f25b9f0 100755 (executable)
@@ -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"
index 5cc13bf..09c43b6 100755 (executable)
@@ -5,7 +5,7 @@ DIR_LOCAL="$(cd "$(dirname "$0")" && pwd)"
 FILE=$1
 
 if [ $# -lt 2 ]; then
-    echo -e "Usage: $0 <file_name> <database_name>\n"
+    echo -e "Usage: $0 <log_filename> <database_name>\n"
     exit 1
 fi
 
index 0d6db4c..53215eb 100644 (file)
@@ -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 (executable)
index 0000000..f25b9f0
--- /dev/null
@@ -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 <archive_file> <db_name>\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 (executable)
index 0000000..90b2644
--- /dev/null
@@ -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 <log_filename> <database_name>\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