示例#1
0
    def sta_hash(self, data):
        '''
        return True if already get same file
        and copy it
        data = [pathname, size, atime, mtime, hash, file_counter, same_ash]

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

        self.__exec('SELECT Id FROM FILE WHERE Hash=?;', (data[4],))
        try:
            ide = int(self.__one()[0])    # if not found raise TypeError
            # build with DIR absolute pathname, and relative source pathname
            root = u_dir_join(self._dir, u_dir_abs(data[0]))
            frm = self._add_path(ide, True)    # get pathname of source
            # new transaction. do it rollback if shit happens
            self.__conn.commit()
            self._upd_restore(ide)
            u_file_copy(frm, root)    # copy file with same hash
            u_file_set_info(root, data[2], data[3])
            return True
        except IOError:    # error copy other file
            self.__conn.rollback()    # restore previous value
            return False
        except TypeError:
            return False
示例#2
0
    def _add_path(self, idd, file=False, asb=True):
        '''
        return a path of a directory/file
        RECURSIVE

        @param integer idd:    database id
        @param boolean file:    if database file or not
        @param boolean asb:    if build with absolute root
        @return: string
        '''

        if(file):
            self.__exec('SELECT Name,Parent FROM FILE WHERE Id=?;', (idd,))
            file = not file
        else:
            self.__exec('SELECT Name,Parent FROM DIR WHERE Id=?;', (idd,))
        try:
            f_tuple = self.__one()
            f_parent = int(f_tuple[1])
            if(f_parent == 0):    # mom I'm home
                if(asb):
                    return self._dir
                else:
                    return ''
            else:
                return u_dir_join(self._add_path(f_parent, file, asb), \
                                  f_tuple[0])    # loop
        except TypeError:
            raise IOError
示例#3
0
    def __next__(self):
        '''
        build tuple
        return name, parent's id, atime, gtime    #add
        return time, name, parent's id    #id

        @return: tuple
        '''

        self.count += 1
        if(self.count > self.stop):
            raise StopIteration
        ext = self.list[self.count - 1]
        root = u_dir_join(self.abs, ext)
        return self.std(ext, root)