diff options
Diffstat (limited to 'monitor')
-rwxr-xr-x | monitor/josef_experimental.py | 12 | ||||
-rwxr-xr-x | monitor/josef_leveldb.py | 55 |
2 files changed, 53 insertions, 14 deletions
diff --git a/monitor/josef_experimental.py b/monitor/josef_experimental.py index 80b4d13..f1a38b9 100755 --- a/monitor/josef_experimental.py +++ b/monitor/josef_experimental.py @@ -29,13 +29,13 @@ monitored_domains = [ db = db_open("./tmpdatabase") -# db_add_domain(db, "www.cox.a.com", "{dummydata}") -# print db_lookup_domain(db, "www.cox.a.com") -db_add_domain(db, "www.cox.b.com", "{dummydata}") -print db_lookup_domain(db, "www.cox.b.com") -print db.Get("www.cox.b.com") -# db_add_domain(db, "www.cox.a.com", "{dummydata3}") +# db_add_domain_2(db, "www.cox.a.com", "{dummydata}") # print db_lookup_domain(db, "www.cox.a.com") +# db_add_domain_2(db, "www.cox.b.com", "{dummydata}") +# print db_lookup_domain(db, "www.cox.b.com") +# print db.Get("www.cox.b.com") +# db_add_domain_2(db, "www.cox.a.com", "{dummydata3}") +print db_lookup_domain(db, "www.cox.a.com") # print db.Get("com") # print db.Get("a.com") # print db.Get("cox.a.com") diff --git a/monitor/josef_leveldb.py b/monitor/josef_leveldb.py index 23ca90f..e1c402e 100755 --- a/monitor/josef_leveldb.py +++ b/monitor/josef_leveldb.py @@ -55,6 +55,41 @@ def db_append(db, key, val): db.Put(key,SEP.join(tmpl)) # print "Storing " + SEP.join(tmpl) +def db_add_domain_2(db, key, val): + # print "Calling: key:",key," val:",val + # print "Appending " + val + if db is None: + print "ERROR: NO DATABASE SET!" + return + + try: + tmp = db.Get(key) + tmpl = tmp.split(SEP) + if val in tmpl: + return + else: + tmpl.append(val) + # print "Putting key:",key," val:",SEP.join(tmpl) + db.Put(key,SEP.join(tmpl)) + except KeyError: + # print "Putting key:",key," val:",SEP.join([val]) + db.Put(key,SEP.join([val])) + new_key = key.split('.',1)[-1] + if new_key != key: + db_add_domain_2(db,new_key,key) + + + # tmpl = tmp.split(SEP) + # if val in tmpl: + # pass + # else: + # # print tmpl + # tmpl.append(val) + # # print tmpl + # db.Put(key,SEP.join(tmpl)) + # print "Storing " + SEP.join(tmpl) + + def db_add_domain(db, domain, data): if db is None: print "ERROR: NO DATABASE SET!" @@ -99,6 +134,8 @@ def db_lookup_domain(db, domain): cur_domain = domain_list.pop() intermediate = db.Get(cur_domain).split(SEP) + last = False + one_more = False while True: try: intermediate.remove("") @@ -111,24 +148,26 @@ def db_lookup_domain(db, domain): return res # Prune next_level = [] - print intermediate + # print intermediate for item in intermediate: - print cur_domain, item + # print item + # if item[0] == '{': + # res.append(item) if match_domain(cur_domain, item): - print item + # print item try: tmp = db.Get(item) - if tmp[1] == '{': - res.append(tmp[1:]) + # print tmp + if tmp[0] == '{': + res.append(tmp) next_level += tmp.split(SEP) except KeyError: # print "Could not find " + item pass - # else: - # intermediate.remove(item) intermediate = next_level - + # if last: + # return res return res |