예제 #1
0
    def __loop_insert(self):
        '''
        __loop for insert data into database
        only after Install
        always use Update

        @return: void
        '''

        # init
        cache = {u_dir_parent(self._dir): 0}
        ide = 0

        for root, dirs, files in walk(self._dir):

            # intro
            tail = u_dir_child(root)
            self.__exec('SELECT Id FROM DIR WHERE Name=? AND Parent=?;', \
                        (tail, cache[u_dir_parent(root)]))
            ide = int(self.__one()[0])
            cache[root] = ide    # add id path to cache

            # dir execution
            if(len(dirs) > 0):    # dir execution
                itd = IterDir((self.time, root), ide, dirs)
                self._add_multiple(itd, False)

            # file execution
            if(len(files) > 0):    # file execution
                itd = IterFile((self.time, root), ide, files)
                self._add_multiple(itd)

        self._init_release()
        return
예제 #2
0
    def init_papa(self, dad):
        '''
        change father dir

        @param string dad:    new father dir
        @return: void
        '''

        dad = u_dir_child(dad)
        self.__exec('UPDATE DIR SET Name=? WHERE Id=?;', (str(dad), 1))
        self.__conn.commit()
        return
예제 #3
0
    def _upd_ok(self, data):
        '''
        add info received by source
        data = [pathname, size, atime, mtime, hash, file_counter, same_ash]

        @param list data:    file info
        @return: void
        '''

        name = u_dir_child(data[0])
        parent = self._add_parent(u_str_split(data[0]))
        self._add_single((name, parent), (data[1], data[2], data[3]), True, \
                       ash=data[4])
        self._init_release()
        return
예제 #4
0
    def __init__(self, dirs, file=None, tim=time()):
        # initialize inherit class
        Xml.__init__(self)

        self._dir = dirs
        self._file = file

        self.time = int(tim)
        self.base = u_dir_child(dirs)

        # isolation_level for commit
        # check_same_thread for multithreading
        # cached_statements for cache
        self.__conn = connect(file, timeout=2, isolation_level='IMMEDIATE', \
                              check_same_thread=False, cached_statements=255)
        self.cursor = self.__conn.cursor()
        # avoiding dots optimization
        self.__exec = self.cursor.execute
        self.__exem = self.cursor.executemany
        self.__one = self.cursor.fetchone
        self.__all = self.cursor.fetchall