Example #1
0
    def update_database(self):
        '''Add new files to the database'''
        if self.update_running:
            return None
        self.update_running = True
        res = dict()
        res['inserted_bytes'] = 0
        res['inserted_files'] = 0
        for d in self.dir_list:
            print('Updating from "{0}"'.format(d))
            dw = DirWalker(d, self.file_regex)
            dw.walk()

            for i, e in enumerate(dw.get_path_list()):
                commit = False
                if i == len(dw.get_path_list())-1:
                    commit = True
                res_q = self.run_sql('INSERT INTO File Values(NULL, ?, ?, datetime(?))', (e[0], e[1], e[2]), commit)
                if res_q != None:
                    self.run_sql('''INSERT OR IGNORE INTO Viewcount (file_id, views)
                            SELECT id, 0 FROM File WHERE File.name=?''', (e[0],),
                            False)
                    res['inserted_bytes'] += e[1]
                    res['inserted_files'] += 1
        self.update_running = False
        return res
Example #2
0
 def get_disk_files2(self):
     '''Recursively get all files from directories specified in the list
     self.dir_list. Returns a list of tuples in the format:
     [(path1,size1), (path2,size2), ... ]'''
     print(self.dir_list)
     for d in self.dir_list:
         dw = DirWalker(d, self.file_regex)
         dw.walk()
     return dw.get_path_list()
Example #3
0
 def get_disk_files(self):
     '''Recursively get all files from directories specified in the list
     self.dir_list returns a dictionary in the format:
     {file_name:file_size_bytes}'''
     path_entries = dict()
     for d in self.dir_list:
         print('Scanning files from directory "{}"'.format(d))
         dw = DirWalker(d, self.file_regex)
         dw.walk()
         path_entries.update({ x[0]:x[1] for x in dw.get_path_list()})
     return path_entries