Fix translation extraction failure.
[chromium-blink-merge.git] / third_party / liblouis / copy_tables.py
blob8cab92e3b65b518844070c4affd32adef9b4c6b0
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 '''Copies the liblouis braille translation tables to a destination.'''
8 import liblouis_list_tables
9 import optparse
10 import os
11 import shutil
14 def LinkOrCopyFiles(sources, dest_dir):
15 def LinkOrCopyOneFile(src, dst):
16 if os.path.exists(dst):
17 os.unlink(dst)
18 try:
19 os.link(src, dst)
20 except:
21 shutil.copy(src, dst)
23 if not os.path.exists(dest_dir):
24 os.makedirs(dest_dir)
25 for source in sources:
26 LinkOrCopyOneFile(source, os.path.join(dest_dir, os.path.basename(source)))
29 def WriteDepfile(depfile, infiles):
30 stampfile = depfile + '.stamp'
31 with open(stampfile, 'w'):
32 os.utime(stampfile, None)
33 content = '%s: %s' % (stampfile, ' '.join(infiles))
34 open(depfile, 'w').write(content)
38 def main():
39 parser = optparse.OptionParser(description=__doc__)
40 parser.add_option('-D', '--directory', dest='directories',
41 action='append', help='Where to search for table files')
42 parser.add_option('-e', '--extra_file', dest='extra_files', action='append',
43 default=[], help='Extra liblouis table file to process')
44 parser.add_option('-d', '--dest_dir', action='store', metavar='DIR',
45 help=('Destination directory. Used when translating ' +
46 'input paths to output paths and when copying '
47 'files.'))
48 parser.add_option('--depfile', metavar='FILENAME',
49 help=('Store .d style dependencies in FILENAME and touch '
50 'FILENAME.stamp after copying the files'))
51 options, args = parser.parse_args()
53 if len(args) != 1:
54 parser.error('Expecting exactly one argument')
55 if not options.directories:
56 parser.error('At least one --directory option must be specified')
57 if not options.dest_dir:
58 parser.error('At least one --dest_dir option must be specified')
59 files = liblouis_list_tables.GetTableFiles(args[0], options.directories,
60 options.extra_files)
61 LinkOrCopyFiles(files, options.dest_dir)
62 if options.depfile:
63 WriteDepfile(options.depfile, files)
66 if __name__ == '__main__':
67 main()