Example #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
Example #2
0
    def m_dir(root_dir):
        '''
        type for argparse

        @param string root_dr:    path of file
        @return string
        '''

        roo = u_dir_abs(root_dir)
        if(not u_dir_exists(roo)):
            raise ArgumentTypeError('Directory not found!')
        else:
            return roo