Example #1
0
    def unused_media_files(self):
        """Returns a set of media files which are in the media directory but
        which are not referenced in the cards.

        """

        case_insensitive = is_filesystem_case_insensitive()
        # Files referenced in the database.
        files_in_db = set()
        for result in self.con.execute(\
            "select value from data_for_fact where value like '%src=%'"):
            for match in re_src.finditer(result[0]):
                filename = match.group(2)
                if case_insensitive:
                    filename = filename.lower()
                files_in_db.add(filename)
        # Files in the media dir.
        files_in_media_dir = set()
        for root, dirnames, filenames in os.walk(self.media_dir()):
            root = contract_path(root, self.media_dir())
            if root.startswith("_"):
                continue
            for filename in filenames:
                # Paths are stored using unix convention.
                if root:
                    filename = root + "/" + filename
                if case_insensitive:
                    filename = filename.lower()
                files_in_media_dir.add(filename)
        return files_in_media_dir - files_in_db
Example #2
0
    def unused_media_files(self):

        """Returns a set of media files which are in the media directory but
        which are not referenced in the cards.

        """

        case_insensitive = is_filesystem_case_insensitive()
        # Files referenced in the database.
        files_in_db = set()
        for result in self.con.execute("select value from data_for_fact where value like '%src=%'"):
            for match in re_src.finditer(result[0]):
                filename = match.group(2)
                if case_insensitive:
                    filename = filename.lower()
                files_in_db.add(filename)
        # Files in the media dir.
        files_in_media_dir = set()
        for root, dirnames, filenames in os.walk(self.media_dir()):
            root = contract_path(root, self.media_dir())
            if root.startswith("_"):
                continue
            for filename in filenames:
                # Paths are stored using unix convention.
                if root:
                    filename = root + "/" + filename
                if case_insensitive:
                    filename = filename.lower()
                files_in_media_dir.add(filename)
        return files_in_media_dir - files_in_db