gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r24274 - monkey/trunk/seaspider


From: gnunet
Subject: [GNUnet-SVN] r24274 - monkey/trunk/seaspider
Date: Thu, 11 Oct 2012 18:28:01 +0200

Author: teichm
Date: 2012-10-11 18:28:00 +0200 (Thu, 11 Oct 2012)
New Revision: 24274

Added:
   monkey/trunk/seaspider/db_convert
Log:
added db_convert

Added: monkey/trunk/seaspider/db_convert
===================================================================
--- monkey/trunk/seaspider/db_convert                           (rev 0)
+++ monkey/trunk/seaspider/db_convert   2012-10-11 16:28:00 UTC (rev 24274)
@@ -0,0 +1,72 @@
+#! /usr/bin/env python
+
+import sqlite3
+import argparse
+import os
+
+parser = argparse.ArgumentParser(description="converts .sea files generated by 
cparser to a seaspider sqlite database")
+
+parser.add_argument('--version', action='version', version='db_convert 1.0')
+parser.add_argument("-o", "--output", metavar="FILENAME", 
type=argparse.FileType('w'), dest="outfile", help="filename for the resulting 
sqlite database. defaulting to infile.sqlite")
+parser.add_argument('infile', type=argparse.FileType('r'), help='input file')
+args = parser.parse_args()
+
+if args.outfile== None:
+       (outfilename, ext) = os.path.splitext(args.infile.name)
+       outfilename += '.sqlite'
+else:
+       outfilename = args.outfile.name
+       args.outfile.close()
+
+# remove old db
+try:
+       os.remove(outfilename)
+except OSError:
+       pass
+
+
+# connect to db
+conn = sqlite3.connect(outfilename)
+c = conn.cursor()
+
+# create table
+c.execute('''CREATE TABLE Expression (
+                       expr_ID INTEGER PRIMARY KEY AUTOINCREMENT,
+                       file_name TEXT NOT NULL,
+                       expr_syntax TEXT,
+                       start_lineno INT,
+                       end_lineno INT,
+                       is_call INT)''')
+
+# commit changes
+conn.commit()
+
+lines = args.infile.readlines(10000)
+while lines:
+       for line in lines:
+               (rowtype, remainder) = line.split(': ', 1)
+               if rowtype == 'Function':
+                       pass
+               elif rowtype == 'Parameter':
+                       pass
+               elif rowtype == 'Scope':
+                       (rowfile, scoperange) = remainder.split(':', 1)
+                       (scope_begin, scope_end) = scoperange.split(' ', 1)
+                       scope_begin = int(scope_begin)
+                       scope_end = int(scope_end) + 1
+                       print 'entered new scope: ', scope_begin, '-', scope_end
+               elif rowtype == 'Expression':
+                       (rowfile, rowexpr) = remainder.split(':', 1)
+                       (lineno, iscall, expression) = rowexpr.split(' ', 2)
+                       lineno = int(lineno)
+                       iscall = int(iscall)
+                       vals = (rowfile, expression, lineno, scope_end, iscall)
+                       c.execute('INSERT INTO Expression VALUES 
(NULL,?,?,?,?,?)', vals)
+               else:
+                       print 'unknown entry type: ' + rowtype
+       conn.commit()
+       lines = args.infile.readlines(10000)
+
+
+# close db
+conn.close()


Property changes on: monkey/trunk/seaspider/db_convert
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property



reply via email to

[Prev in Thread] Current Thread [Next in Thread]