1. Список говнокодов пользователя ayylmao

    Всего: 1

  2. Python / Говнокод #21798

    −49

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    class ScanFiles:
        DIRECTORY_SEPARATOR = '/'
    
        def __init__(self, rootDir, searchPattern, filesExtension = None):
            self.rootCatalogPath = rootDir # Absolute path to directory to parse
            self.filesExtension = filesExtension # Specified files(if typed)
            self.pattern = searchPattern # Key word's regex pattern
    
        def scan(self, path = '', absPath = ''):
            if (not os.path.exists(self.rootCatalogPath)):
                raise Exception("Directory is not exists.")
    
            if (not absPath):
                absolutePath = self.rootCatalogPath + self.DIRECTORY_SEPARATOR + path
            else:
                absolutePath = absPath + path + self.DIRECTORY_SEPARATOR
            for item in os.listdir(absolutePath):
                if (os.path.isdir(absolutePath + item)):
                    # recursive call
                    self.scan(item, absolutePath)
                elif (os.path.isfile(absolutePath + item)):
                    if (self.filesExtension):
                        if (not re.search('\.%s$' % (self.filesExtension), item)):
                            return 0;
                    self.__parse_file(absolutePath + item)
    
        def __parse_file(self, pathToFile):
            f = open(pathToFile)
            if (re.search(self.pattern, f.read(), re.IGNORECASE)):
                print pathToFile;
            return 1;

    Человек осуществляет поиск подстроки в файлах указанной директории :D

    ayylmao, 07 Декабря 2016

    Комментарии (79)