def directory_hashes(directory,
                         filters_in=None,
                         filters_out=None,
                         flags=0):
        """
        Recursively computes the hashes from the file within given directory.

        Parameters
        ----------
        directory : str or unicode
            Directory to compute the file hashes.
        filters_in : array_like
            Included patterns.
        filters_out : array_like
            Excluded patterns.
        flags : int
            Regex flags.

        Returns
        -------
        dict
             Directory file hashes.
        """

        hashes = {}
        for path in files_walker(directory,
                                 filters_in=filters_in,
                                 filters_out=filters_out,
                                 flags=flags):
            with open(path) as file:
                digest = hashlib.md5(
                    re.sub('\s', '', file.read())).hexdigest()
            hashes[path.replace(directory, '')] = digest
        return hashes
예제 #2
0
    def directory_hashes(directory,
                         filters_in=None,
                         filters_out=None,
                         flags=0):
        """
        Recursively computes the hashes from the file within given directory.

        Parameters
        ----------
        directory : str or unicode
            Directory to compute the file hashes.
        filters_in : array_like
            Included patterns.
        filters_out : array_like
            Excluded patterns.
        flags : int
            Regex flags.

        Returns
        -------
        dict
             Directory file hashes.
        """

        hashes = {}
        for path in files_walker(directory,
                                 filters_in=filters_in,
                                 filters_out=filters_out,
                                 flags=flags):
            with open(path) as file:
                digest = hashlib.md5(re.sub('\s', '', file.read())).hexdigest()
            hashes[path.replace(directory, '')] = digest
        return hashes
    def test_ACES_config(self):
        """
        Performs tests on the *ACES* configuration by computing hashes on the
        generated configuration and comparing them to the existing one.
        """

        self.assertTrue(create_ACES_config(self.__aces_ocio_ctl_directory,
                                           self.__temporary_directory))

        reference_hashes = self.directory_hashes(
            REFERENCE_CONFIG_ROOT_DIRECTORY,
            HASH_TEST_PATTERNS)
        test_hashes = self.directory_hashes(
            self.__temporary_directory,
            HASH_TEST_PATTERNS)

        self.assertDictEqual(reference_hashes, test_hashes)

        # Checking that unashable files ('.icc', '.ocio') are generated.
        unashable = lambda x: (
            sorted([file.replace(x, '') for file in
                    files_walker(x, UNHASHABLE_TEST_PATTERNS)]))

        self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
                             unashable(self.__temporary_directory))
예제 #4
0
    def test_ACES_config(self):
        """
        Performs tests on the *ACES* configuration by computing hashes on the
        generated configuration and comparing them to the existing one.
        """

        self.assertTrue(
            generate_config(self.__aces_ocio_ctl_directory,
                            self.__temporary_directory))

        reference_hashes = self.directory_hashes(
            REFERENCE_CONFIG_ROOT_DIRECTORY, HASH_TEST_PATTERNS)
        test_hashes = self.directory_hashes(self.__temporary_directory,
                                            HASH_TEST_PATTERNS)

        self.assertDictEqual(reference_hashes, test_hashes)

        # Checking that unashable files ('.icc', '.ocio') are generated.
        unashable = lambda x: (sorted([
            file.replace(x, '')
            for file in files_walker(x, UNHASHABLE_TEST_PATTERNS)
        ]))

        self.assertListEqual(unashable(REFERENCE_CONFIG_ROOT_DIRECTORY),
                             unashable(self.__temporary_directory))