You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.5 KiB

import os
import re
from typing import Dict
from calculate.utils.files import read_file_lines
class ProfileWalker:
'''Объект обходящий все директории профиля через parent файлы.'''
def __init__(self, filename: str, repositories: Dict[str, str]):
self.repositories: Dict[str, str] = repositories
self.filename: str = filename
self.re_reppath: re.Pattern = re.compile("^({0})+:".format(
def interpolate(self, path: str):
def subfunc(m):
return "{0}/profiles/".format(self.repositories.get(
return self.re_reppath.sub(subfunc, path)
def find(self, directory: str):
'''Метод для поиска по профилю всех файлов с именем, указанным в
parent_file_path = os.path.join(directory, "parent")
for line in (parent_line for parent_line in
read_file_lines(parent_file_path) if parent_line.strip()):
parent_directory = os.path.normpath(
os.path.join(directory, self.interpolate(line)))
if os.path.exists(parent_directory):
yield from self.find(parent_directory)
findfile = os.path.normpath(os.path.join(directory, self.filename))
if os.path.exists(findfile):
yield findfile