summaryrefslogtreecommitdiffstats
path: root/sse-feed
diff options
context:
space:
mode:
Diffstat (limited to 'sse-feed')
-rwxr-xr-xsse-feed62
1 files changed, 44 insertions, 18 deletions
diff --git a/sse-feed b/sse-feed
index 8290f48..29718ca 100755
--- a/sse-feed
+++ b/sse-feed
@@ -1,36 +1,52 @@
#!/usr/bin/python
-import sys, os, MYSQLdb
+import sys, os, MySQLdb, stat
from popen2 import Popen3
-LEXER_PATH="."
+def last_insert_id(cursor):
+ cursor.execute("SELECT LAST_INSERT_ID()");
+ return cursor.fetchone()[0]
-db = MySQLdb.connect(host = "localhost", user = "sse_web", passwd = "ece6Yoli", db = "sse")
-
-def process_file(root, path):
+def process_file(package_id, root, path):
+ global cursor
print "Processing %s" % path
-
+ cursor.execute("INSERT INTO file (package_id, path, language_id) VALUES (%i, '%s', '0')" % (package_id, path));
- p = Popen3("%s/lex-c %s" % (LEXER_PATH, os.path.join(root, path)))
+ file_id = last_insert_id(cursor);
+
+ p = Popen3("lex-c %s" % (os.path.join(root, path)))
for identifier in p.fromchild:
- print "ID:", identifier.strip()
+ text = identifier.strip()
+
+ cursor.execute("INSERT IGNORE INTO word (text, type, file_id) VALUES ('%s', 'word', '%i')" % (text, file_id))
+ cursor.execute("UPDATE word SET cnt=cnt+1 WHERE text='%s' AND type='word' AND file_id=%i" % (text, file_id))
- if p.wait() != 0:
- print "WARNING: Subprocess failed!"
+ if p.wait() != 0:
+ print "WARNING: Subprocess failed!"
del p
-def handle_file(root, path, filename):
+def handle_file(package_id, root, path, filename):
+
+ t = sys.lstat(os.path.join(path, filename))
- extension = filename.split(".")[-1]
+ if stat.F_ISREG(t.st_mode):
- if extension in ("c", "h"):
- process_file(root, os.path.join(path, filename))
+ extension = filename.split(".")[-1]
+ if extension in ("c", "h"):
+ process_file(package_id, root, os.path.join(path, filename))
+ return
-def handle_tree(path):
+ os.unlink(os.path.join(root, path, filename))
+
+def handle_tree(path, name, url, md):
+ global cursor
+
+ cursor.execute("INSERT INTO package (path, name, url, timestamp, md) VALUES ('%s', '%s', '%s', NOW(), '%s')" % (path + "/%s", name, url, md));
+ package_id = last_insert_id(cursor);
path = os.path.realpath(path)
@@ -38,7 +54,17 @@ def handle_tree(path):
for f in files:
assert path + "/" == (dirpath + "/") [:len(path)+1]
- handle_file(path, dirpath[len(path)+1:], f)
+ handle_file(package_id, path, dirpath[len(path)+1:], f)
+
+db = MySQLdb.connect(host = "localhost", user = "sse_web", passwd = "ece6Yoli", db = "sse")
+cursor = db.cursor();
+cursor.execute("SET AUTOCOMMIT=0")
+cursor.execute("START TRANSACTION")
+
+assert len(sys.argv) == 5
+
+handle_tree(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
-for a in sys.argv[1:]:
- handle_tree(a)
+cursor.execute("COMMIT")
+cursor.close()
+db.close()