| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 import sys | 8 import sys |
| 9 | 9 |
| 10 import json | 10 import json |
| 11 import optparse | 11 import optparse |
| 12 | 12 |
| 13 # Matches the include statement in the braille table files. | 13 # Matches the include statement in the braille table files. |
| 14 INCLUDE_RE = re.compile(r"^\s*include\s+([^#\s]+)") | 14 INCLUDE_RE = re.compile(r"^\s*include\s+([^#\s]+)") |
| 15 | 15 |
| 16 | 16 |
| 17 def Error(msg): | 17 def Error(msg): |
| 18 print >> sys.stderr, 'liblouis_list_tables: %s' % msg | 18 print >> sys.stderr, 'liblouis_list_tables: %s' % msg |
| 19 sys.exit(1) | 19 sys.exit(1) |
| 20 | 20 |
| 21 | 21 |
| 22 def ToNativePath(pathname): | 22 def ToNativePath(pathname): |
| 23 return os.path.sep.join(pathname.split('/')) | 23 return os.path.sep.join(pathname.split('/')) |
| 24 | 24 |
| 25 | 25 |
| 26 def LoadTablesFile(filename): | 26 def LoadTablesFile(filename): |
| 27 with open(ToNativePath(filename), 'r') as fh: | 27 with open(ToNativePath(filename), 'r') as fh: |
| 28 return json.load(fh) | 28 try: |
| 29 return json.load(fh) |
| 30 except ValueError, e: |
| 31 raise ValueError('Error parsing braille table file %s: %s' % |
| 32 (filename, e.message)) |
| 29 | 33 |
| 30 | 34 |
| 31 def FindFile(filename, directories): | 35 def FindFile(filename, directories): |
| 32 for d in directories: | 36 for d in directories: |
| 33 fullname = '/'.join([d, filename]) | 37 fullname = '/'.join([d, filename]) |
| 34 if os.path.isfile(ToNativePath(fullname)): | 38 if os.path.isfile(ToNativePath(fullname)): |
| 35 return fullname | 39 return fullname |
| 36 Error('File not found: %s' % filename) | 40 Error('File not found: %s' % filename) |
| 37 | 41 |
| 38 | 42 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 83 |
| 80 def main(argv): | 84 def main(argv): |
| 81 print DoMain(argv[1:]) | 85 print DoMain(argv[1:]) |
| 82 | 86 |
| 83 | 87 |
| 84 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 85 try: | 89 try: |
| 86 sys.exit(main(sys.argv)) | 90 sys.exit(main(sys.argv)) |
| 87 except KeyboardInterrupt: | 91 except KeyboardInterrupt: |
| 88 Error('interrupted') | 92 Error('interrupted') |
| OLD | NEW |