forked from Huelse/SEAL-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
50 lines (43 loc) · 1.79 KB
/
helper.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
41
42
43
44
45
46
47
48
49
50
import os
root_path = './SEAL/native/src/seal/'
files = ['plaintext.h', 'ciphertext.h', 'kswitchkeys.h', 'secretkey.h', 'publickey.h']
keyword = 'private:'
new_line = 'EncryptionParameters parms;'
def add_parms_to_header():
for file_name in files:
file_path = root_path + file_name
if os.path.exists(file_path):
new_line_exists = True
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
if new_line in line:
new_line_exists = False
if new_line_exists:
with open(file_path, 'w', encoding='utf-8') as fs:
for line in lines:
if keyword in line:
line = line.replace(line, '\t\t{}\n\n\t{}\n'.format(new_line, keyword))
fs.write(line)
print('Add parms to {} success.'. format(file_path))
else:
print('Can not find the {}, please check the file integrity.'.format(file_path))
def switch_wrapper():
ifswitch = False
with open('./setup.py', 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
if "wrapper_file = 'src/wrapper.cpp'" in line:
ifswitch = True
if ifswitch:
with open('./setup.py', 'w', encoding='utf-8') as fs:
for line in lines:
if "wrapper_file = 'src/wrapper.cpp'" in line:
line = line.replace(line, "wrapper_file = 'src/wrapper_with_pickle.cpp'\n")
fs.write(line)
print("Switch wrapper success.")
else:
print('Already switch to wrapper with pickle.')
if __name__ == '__main__':
add_parms_to_header()
switch_wrapper()