Example #1
0
    def test_digest_from_file(self):
        test_file_name = "test.txt"
        self.__create_large_file(test_file_name)
        d_str = DigestUtil.digest_from_file(test_file_name)

        # print "Our final str is :",d_str
        # print "The other str is :",self.__run_sha1_sum(test_file_name)

        assert d_str == DigestUtil.run_sha1_sum(test_file_name)
        import os

        os.remove(test_file_name)
Example #2
0
    def test_digest_from_buffer(self):
        digest_str = "digestme"
        d_str = DigestUtil.digest_from_buffer(digest_str)

        # create a tmo file for test purposes
        test_file_name = "test.txt"
        test_file = open(test_file_name, "w")
        test_file.write(digest_str)
        test_file.close()

        # print "Our final str is :",d_str
        # print "The other str is :",self.__run_sha1_sum(test_file_name)
        assert d_str == DigestUtil.run_sha1_sum(test_file_name)
        import os

        os.remove(test_file_name)
Example #3
0
    def run(self):
        """
        The part where computes the sha1 sum
        """
        from imzaci.digest.digest_util import DigestUtil
        import time
        #while we have things to do 
        finish = False
        while 1:
            self.file_pool_lock.acquire()#get the lock
            if len(self.file_pool)>0:
                file_to_process = self.file_pool.pop() #get one
            else:
                finish = True
            self.file_pool_lock.release()
            if finish:
                break

            #print "Digest in thread %d "%(self.t_id)
            #time.sleep(2)

            file_hash = DigestUtil.digest_from_file(file_to_process)
            #it seems you have processed your part you can add it to finished
            self.finished_pool_lock.acquire()
            self.finished_pool[file_to_process] = file_hash
            self.finished_pool_lock.release()
Example #4
0
def test_hash_without_thread():
    """
    Test if our normal implementation works as we expect
    """
    from imzaci.tests.test_digest_util import TestDigestUtil
    test_res = compute_hash_without_thread(TEST_DIR)
    for file,hash in test_res.iteritems():
        #print "For %s Have : %s ,should be %s "%(file,hash,DigestUtil.run_sha1_sum(file))
        assert DigestUtil.run_sha1_sum(file) == hash
Example #5
0
    def get_sign_hash(self,sign_dir,except_list = None):
        """
        That is an util method which gives back the final
        hash of a directory ...
        """
        from imzaci.digest.digest_util import DigestUtil
        from imzaci.digest.file_operations import DirHashHandler
        
        tmp_store_file = "tmp.txt"

        self.dir_hash = DirHashHandler(sign_dir,except_list)
        self.dir_hash.store_final_hash(tmp_store_file)
        #that is the hash of teh hashes ...
        self.file_hash = DigestUtil.digest_from_file(tmp_store_file)
        print "The final hash is ...:",self.file_hash
        #the buffer to be signed
        self.tosign_buffer=self.makebuf(self.file_hash)
        os.remove(tmp_store_file)
Example #6
0
def compute_hash_without_thread(base_dir):
    """
    Because the thread based implementation alway scares me
    i will compare its result with a normal straight implemenattion
    """
    tmp_flist = FileList(base_dir)
    file_list = tmp_flist.walk_through()

    if not file_list:
        return None

    final_dict = {}

    for file_to_process in file_list:
        file_hash = DigestUtil.digest_from_file(file_to_process)
        #if not file_hash:
        #    print "We have None for :",file_to_process
        final_dict[file_to_process] = file_hash

    return final_dict