mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with function
parent
784808961a
commit
27ce1a8772
|
|
@ -120,9 +120,11 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
|
|||
post_filename = path + '/' + post_filename.strip()
|
||||
if not os.path.isfile(post_filename):
|
||||
continue
|
||||
with open(post_filename, 'r', encoding='utf-8') as fp_post:
|
||||
data = fp_post.read().lower()
|
||||
|
||||
data = load_string(post_filename,
|
||||
'EX: _search_virtual_box_posts ' +
|
||||
'unable to read ' + post_filename)
|
||||
if data is not None:
|
||||
data = data.lower()
|
||||
not_found: bool = False
|
||||
for keyword in search_words:
|
||||
if keyword not in data:
|
||||
|
|
@ -180,9 +182,10 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
|
|||
for root, _, fnames in os.walk(path):
|
||||
for fname in fnames:
|
||||
file_path = os.path.join(root, fname)
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as fp_post:
|
||||
data = fp_post.read()
|
||||
data = load_string(file_path,
|
||||
'EX: search_box_posts unable to read ' +
|
||||
file_path + ' [ex]')
|
||||
if data is not None:
|
||||
data_lower = data.lower()
|
||||
|
||||
not_found: bool = False
|
||||
|
|
@ -226,8 +229,5 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
|
|||
res.append(file_path)
|
||||
if len(res) >= max_results:
|
||||
return res
|
||||
except OSError as exc:
|
||||
print('EX: search_box_posts unable to read ' +
|
||||
file_path + ' ' + str(exc))
|
||||
break
|
||||
return res
|
||||
|
|
|
|||
Loading…
Reference in New Issue