Created
July 18, 2019 04:32
-
-
Save KoStard/66773225826167632be7e0f983130844 to your computer and use it in GitHub Desktop.
Checker is a base class for all checkers - it makes all children classes to have same methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Checker: | |
@staticmethod | |
def is_this_type(expr): | |
raise NotImplementedError() | |
def does_match(self, value): | |
raise NotImplementedError() | |
class NameChecker(Checker): | |
@staticmethod | |
def is_this_type(expr): | |
""" | |
Check if the expr is in a name checker format | |
""" | |
def __init__(self, expr): | |
self.expr = expr | |
def does_match(self, value): | |
"Check if value matches to the expr" | |
class SizeChecker(Checker): | |
@staticmethod | |
def is_this_type(expr): | |
""" | |
Check if the expr is in a size checker format | |
""" | |
def __init__(self, expr): | |
self.expr = expr | |
def does_match(self, value): | |
"Check if value matches to the expr" | |
class TypeChecker(Checker): | |
@staticmethod | |
def is_this_type(expr): | |
""" | |
Check if the expr is in a type checker format | |
""" | |
def __init__(self, expr): | |
self.expr = expr | |
def does_match(self, value): | |
"Check if value matches to the expr" | |
class CreateTimeChecker(Checker): | |
@staticmethod | |
def is_this_type(expr): | |
""" | |
Check if the expr is in a creation time checker format | |
""" | |
def __init__(self, expr): | |
self.expr = expr | |
def does_match(self, value): | |
"Check if value matches to the expr" | |
class Finder: | |
checkers = [NameChecker, SizeChecker, TypeChecker, CreateTimeChecker] | |
def __init__(self, path, expression): | |
self.current_checkers = [] | |
exps = [e.strip() for e in expression.split('|')] | |
for exp in exps: | |
found = False | |
for ch in self.checkers: | |
if ch.is_this_type(exp): | |
found = True | |
self.current_checkers.append(ch(exp)) | |
break | |
if not found: | |
raise ValueError("Invalid pattern '{}'.".format(exp)) | |
def find(self, current_path, results): | |
""" | |
Check if content files match the expressions and check it's inner folders | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment