-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathIO.py
40 lines (34 loc) · 1.11 KB
/
IO.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import os.path
class IO:
def __init__(self, filename):
self.console = sys.stdout
self.file = open(filename, 'a')
def write(self, message):
self.console.write(message)
self.file.write(message)
def flush(self):
pass
@staticmethod
def conditional_print(message, condition):
if condition:
print(message)
@staticmethod
def read_keys_from_file(filename):
if not os.path.isfile(filename):
print(f'Provided file {filename} does not exist. Exiting...')
return
else:
print(f'Starting validation on keys in {filename}')
try:
with open(filename, 'r') as file:
keys_in_file = set()
for line in file:
current_line = line.strip()
if not current_line:
continue
keys_in_file.add(current_line.split()[0].split(",")[0])
return keys_in_file
except Exception as e:
print(f'Unable to read keys from {filename}')
return