Skip to content

Commit 5ab479c

Browse files
committed
reafctor read file function
1 parent cc81845 commit 5ab479c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lists.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
args = parser.parse_args()
1010

1111

12-
def read_stripped(file: str):
12+
def read_stripped(file: str, strip_lines=True):
13+
"""
14+
This reads the file and strips out any empty and comment lines with `#`
15+
"""
1316
try:
1417
with open(file, "r") as f:
18+
file_contents = f.readlines()
19+
20+
if not strip_lines:
21+
return file_contents
22+
1523
strip_comments = [l.strip()
1624
if not l.startswith("#") else None
17-
for l in f.readlines()]
25+
for l in file_contents]
1826

1927
return list(filter(None, strip_comments))
2028

@@ -34,6 +42,7 @@ def dnsmasq_fmt(*domains):
3442
def main():
3543
hosts_record = read_stripped("hosts")
3644
dnsmasq_record = read_stripped("dnsmasq")
45+
pihole_record = read_stripped("PiHole", False)
3746

3847

3948
if __name__ == "__main__":

0 commit comments

Comments
 (0)