projectreport.searcher package

Tools to search for regex within files and return lines around the match

projectreport.searcher.read_all_files_in_folder_print_lines_around_regex(file_path, str_pattern, num_lines=2, recursive=False, print_lines=True, ignore_paths=None)[source]

Searches for regex in each line of every file in a folder. When regex is matched, will return num_lines lines around the file

Parameters:
  • file_path (str) – Path of file to search in

  • str_pattern (str) – Pattern to match in a line

  • num_lines (int) – Number of lines around the matching line to return/print, defaults to 2

  • recursive (bool) – Whether to search folders within passed folder, defaults to False

  • print_lines (bool) – Whether to print the results, defaults to False

  • ignore_paths (Optional[Sequence[str]]) – Relative paths to ignore. Globs are accepted, defaults to None

Return type:

Dict[str, List[List[str]]]

Returns:

a dictionary where keys are file paths, and values are lists where each element is a list containing the lines for one match

projectreport.searcher.read_all_files_in_folders_print_lines_around_regex(folders, str_pattern, num_lines=2, recursive=False, print_lines=True, ignore_paths=None)[source]

Searches for regex in each line of every file in multiple folders. When regex is matched, will return num_lines lines around the file

Parameters:
  • folders (Sequence[str]) – Folders to search in

  • str_pattern (str) – Pattern to match in a line

  • num_lines (int) – Number of lines around the matching line to return/print, defaults to 2

  • recursive (bool) – Whether to search folders within passed folder, defaults to False

  • print_lines (bool) – Whether to print the results, defaults to False

  • ignore_paths (Optional[Sequence[str]]) – Relative paths to ignore. Globs are accepted, defaults to None

Return type:

Dict[str, List[List[str]]]

Returns:

a dictionary where keys are file paths, and values are lists where each element is a list containing the lines for one match

projectreport.searcher.read_file_get_lines_around_regex(file_path, str_pattern, num_lines=2, print_lines=False)[source]

Searches for regex in each line of a file. When regex is matched, will return num_lines lines around the file

Parameters:
  • file_path (str) – path of file to search in

  • str_pattern (str) – pattern to match in a line

  • num_lines (int) – number of lines around the matching line to return/print, defaults to 2

  • print_lines (bool) – whether to print the results, defaults to False

Return type:

List[List[str]]

Returns:

a list where each element is a list containing the lines for one match

Submodules

projectreport.searcher.rotating_list module

class projectreport.searcher.rotating_list.RotatingList(items, max_len)[source]

Bases: UserList

A list which will hold only max_len items. Once more items are added then can fit in the list, items will be removed.

When appending or extending items which will make the list larger than max_len, the earliest items in the list will be removed. When inserting an item which will make the list larger than max_len, the last item will be removed.

__init__(items, max_len)[source]
append(item)[source]

S.append(value) – append value to the end of the sequence

extend(items)[source]

S.extend(iterable) – extend sequence by appending elements from the iterable

insert(index, item)[source]

S.insert(index, value) – insert value before index

projectreport.searcher.search module

projectreport.searcher.search.read_all_files_in_folder_print_lines_around_regex(file_path, str_pattern, num_lines=2, recursive=False, print_lines=True, ignore_paths=None)[source]

Searches for regex in each line of every file in a folder. When regex is matched, will return num_lines lines around the file

Parameters:
  • file_path (str) – Path of file to search in

  • str_pattern (str) – Pattern to match in a line

  • num_lines (int) – Number of lines around the matching line to return/print, defaults to 2

  • recursive (bool) – Whether to search folders within passed folder, defaults to False

  • print_lines (bool) – Whether to print the results, defaults to False

  • ignore_paths (Optional[Sequence[str]]) – Relative paths to ignore. Globs are accepted, defaults to None

Return type:

Dict[str, List[List[str]]]

Returns:

a dictionary where keys are file paths, and values are lists where each element is a list containing the lines for one match

projectreport.searcher.search.read_all_files_in_folders_print_lines_around_regex(folders, str_pattern, num_lines=2, recursive=False, print_lines=True, ignore_paths=None)[source]

Searches for regex in each line of every file in multiple folders. When regex is matched, will return num_lines lines around the file

Parameters:
  • folders (Sequence[str]) – Folders to search in

  • str_pattern (str) – Pattern to match in a line

  • num_lines (int) – Number of lines around the matching line to return/print, defaults to 2

  • recursive (bool) – Whether to search folders within passed folder, defaults to False

  • print_lines (bool) – Whether to print the results, defaults to False

  • ignore_paths (Optional[Sequence[str]]) – Relative paths to ignore. Globs are accepted, defaults to None

Return type:

Dict[str, List[List[str]]]

Returns:

a dictionary where keys are file paths, and values are lists where each element is a list containing the lines for one match

projectreport.searcher.search.read_file_get_lines_around_regex(file_path, str_pattern, num_lines=2, print_lines=False)[source]

Searches for regex in each line of a file. When regex is matched, will return num_lines lines around the file

Parameters:
  • file_path (str) – path of file to search in

  • str_pattern (str) – pattern to match in a line

  • num_lines (int) – number of lines around the matching line to return/print, defaults to 2

  • print_lines (bool) – whether to print the results, defaults to False

Return type:

List[List[str]]

Returns:

a list where each element is a list containing the lines for one match