Exemplo n.º 1
0
 def search(self, anfrage):
     res = []       
     if self.backend == "pickle":
         if self.open_index == 0: # Wenn Index noch nicht geöffnet,
             try:
                 self.header, self.files, self.keywords = pickle.load(file(config.index_file, "r",-1)) # dann lade Index
                 self.open_index = 1
             except IOError:
                 lyp.cout("Konnte keine Index Datei finden! Suche nun mit der Echtzeitsuche!")
         if self.open_index == 1:
             keywords = self.keywords # -|  o n l y
             files = self.files       # -| t h r 3 3
             speed_len = len          # -| Sp33d H4ck
             filecount = 0
             for e in keywords:
                 for i in e:
                     if speed_len(anfrage.findall(i)) >= 1:
                         hit = files[filecount]
                         res.append(hit)
                 filecount += 1
         else:
             
             rt = rt_searcher()
             res = rt.search(config.root_directory,anfrage)
     
     elif self.backend == "sqlite":
         self.cur.execute("SELECT * FROM pds WHERE keywords = \"%s\"" % anfrage)
         res = self.cur.fetchall()
         print res
         
     return(res)
Exemplo n.º 2
0
        if os.path.exists("index.db") != 1:
            foo = 1
        self.con = sqlite.connect('index.db')
        self.cur = self.con.cursor()
        if foo == 1:
            # Erstellt die Tabelle
            self.cur.execute('CREATE TABLE pds(file VARCHAR(100), keywords VARCHAR(50))')
            self.do()
    def add(self, filename, keywords):
        # Fügt etwas hinzu
        self.cur.execute("INSERT INTO pds(file, keywords) VALUES ('"+filename+"', '"+keywords+"')")
    def showall(self):
        self.cur.execute("SELECT * FROM pds")
        return(self.cur.fetchall())
    def sql(self, befehl, do = 1):
        self.cur.execute(befehl)
        if do == 1:
            self.do()
    def do(self):
        self.con.commit()
        
if __name__ == "__main__":
    # DB
    dbuser = pydsdb()
    while 1:
        try:
            dbuser.sql(raw_input("sql ?> "))
        except:
            lyp.cout(error)
    dbuser.showall()