summaryrefslogtreecommitdiffstats
path: root/feed/sse-feed
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-11-21 14:15:24 +0000
committerLennart Poettering <lennart@poettering.net>2005-11-21 14:15:24 +0000
commit60cd2a763756529262ae7bbe58b3272ed51e5598 (patch)
tree02443608eb4a01d1567a057a0ab9727c425aab0a /feed/sse-feed
parent6a9e54615b4da50ad0f288e1bd5f0e3cea4a1fc9 (diff)
move everything down a directory
git-svn-id: file:///home/lennart/svn/public/sse/trunk@6 5fbabb74-0606-0410-a5e4-b5cc6a42724e
Diffstat (limited to 'feed/sse-feed')
-rwxr-xr-xfeed/sse-feed70
1 files changed, 70 insertions, 0 deletions
diff --git a/feed/sse-feed b/feed/sse-feed
new file mode 100755
index 0000000..29718ca
--- /dev/null
+++ b/feed/sse-feed
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+import sys, os, MySQLdb, stat
+from popen2 import Popen3
+
+def last_insert_id(cursor):
+ cursor.execute("SELECT LAST_INSERT_ID()");
+ return cursor.fetchone()[0]
+
+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));
+
+ file_id = last_insert_id(cursor);
+
+ p = Popen3("lex-c %s" % (os.path.join(root, path)))
+
+ for identifier in p.fromchild:
+ 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!"
+
+ del p
+
+def handle_file(package_id, root, path, filename):
+
+ t = sys.lstat(os.path.join(path, filename))
+
+ if stat.F_ISREG(t.st_mode):
+
+ extension = filename.split(".")[-1]
+
+ if extension in ("c", "h"):
+ process_file(package_id, root, os.path.join(path, filename))
+ return
+
+ 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)
+
+ for dirpath, dirs, files in os.walk(path):
+ for f in files:
+ assert path + "/" == (dirpath + "/") [:len(path)+1]
+
+ 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])
+
+cursor.execute("COMMIT")
+cursor.close()
+db.close()