-
Notifications
You must be signed in to change notification settings - Fork 16
/
modify_backend.py
31 lines (27 loc) · 933 Bytes
/
modify_backend.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
# encoding: utf8
def main():
f = open('src/calibre/db/backend.py', 'r', encoding="utf-8")
source = f.read()
target = source
target = target.replace(
'# Imports {{{', '# Imports {{{\nimport re\n'
)
target = target.replace(
'author = ascii_filename(author)[:l]',
'author = re.sub(r"[\\/\\\\\\:\\*\\?\\"\\<\\>\\|]", "_", author.strip())[:l]'
)
if(source == target):
return("WARNING: REPLACE AUTHOR FILENAME FAILS")
source = target
target = target.replace(
'title = ascii_filename(title.lstrip())[:l].rstrip()',
'title = re.sub(r"[\\/\\\\\\:\\*\\?\\"\\<\\>\\|]", "_", title.strip())[:l]'
)
if(source == target):
return("WARNING: REPLACE TITLE FILENAME FAILS")
f.close()
f = open('src/calibre/db/backend_utf8.py', 'w', encoding="utf-8")
f.write(target)
return 'done'
if __name__ == "__main__":
print(main())