mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Add a check for ASCII control codes in translation files
This commit is contained in:
parent
e0c1de3ef4
commit
0053ee6456
@ -651,6 +651,15 @@ class GetTranslations(Translations): # {{{
|
||||
p.wait()
|
||||
return errs
|
||||
|
||||
def check_for_control_chars(f):
|
||||
raw = open(f, 'rb').read().decode('utf-8')
|
||||
pat = re.compile(ur'[\0-\x08\x0b\x0c\x0e-\x1f\x7f]')
|
||||
errs = []
|
||||
for i, line in enumerate(raw.splitlines()):
|
||||
if pat.search(line) is not None:
|
||||
errs.append('There are ASCII control codes on line number: {}'.format(i + 1))
|
||||
return '\n'.join(errs)
|
||||
|
||||
for f in files:
|
||||
errs = check(f)
|
||||
if errs:
|
||||
@ -659,6 +668,11 @@ class GetTranslations(Translations): # {{{
|
||||
edit_file(f)
|
||||
if check(f):
|
||||
raise SystemExit('Aborting as not all errors were fixed')
|
||||
errs = check_for_control_chars(f)
|
||||
if errs:
|
||||
print(f, 'has ASCII control codes in it')
|
||||
print(errs)
|
||||
raise SystemExit(1)
|
||||
|
||||
def check_website(self):
|
||||
errors = os.path.join(tempfile.gettempdir(), 'calibre-translation-errors')
|
||||
|
Loading…
x
Reference in New Issue
Block a user