Ejemplo n.º 1
0
    def match_rule(self, rule: Rule) -> bool:
        follow_rule = False

        # checks if file extension match formats
        for f in rule.formats:
            if self.__ext.lower() == f.lower():
                follow_rule = True
                break
        if not follow_rule:
            return False

        # checks if creation/modification file which had triggered event handler
        #  belongs to at least one source in rule object
        # Note: this works only if file is created in the root directory of source
        #   (recursively search might take too long)
        for source in rule.sources:
            try:
                Validation.path_exists(f"{source}/{self.__file}")
                return True
            except FileNotFoundError:
                pass

        return False
Ejemplo n.º 2
0
 def exists(self) -> bool:
     try:
         Validation.path_exists(self.__filename)
         return True
     except FileNotFoundError:
         return False