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:
num_lines¶ (
int
) – Number of lines around the matching line to return/print, defaults to 2recursive¶ (
bool
) – Whether to search folders within passed folder, defaults to Falseprint_lines¶ (
bool
) – Whether to print the results, defaults to Falseignore_paths¶ (
Optional
[Sequence
[str
]]) – Relative paths to ignore. Globs are accepted, defaults to None
- Return type:
- 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:
num_lines¶ (
int
) – Number of lines around the matching line to return/print, defaults to 2recursive¶ (
bool
) – Whether to search folders within passed folder, defaults to Falseprint_lines¶ (
bool
) – Whether to print the results, defaults to Falseignore_paths¶ (
Optional
[Sequence
[str
]]) – Relative paths to ignore. Globs are accepted, defaults to None
- Return type:
- 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:
- Return type:
- 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.
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:
num_lines¶ (
int
) – Number of lines around the matching line to return/print, defaults to 2recursive¶ (
bool
) – Whether to search folders within passed folder, defaults to Falseprint_lines¶ (
bool
) – Whether to print the results, defaults to Falseignore_paths¶ (
Optional
[Sequence
[str
]]) – Relative paths to ignore. Globs are accepted, defaults to None
- Return type:
- 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:
num_lines¶ (
int
) – Number of lines around the matching line to return/print, defaults to 2recursive¶ (
bool
) – Whether to search folders within passed folder, defaults to Falseprint_lines¶ (
bool
) – Whether to print the results, defaults to Falseignore_paths¶ (
Optional
[Sequence
[str
]]) – Relative paths to ignore. Globs are accepted, defaults to None
- Return type:
- 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:
- Return type:
- Returns:
a list where each element is a list containing the lines for one match