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
14 def LinkOrCopyFiles(sources
, dest_dir
):
15 def LinkOrCopyOneFile(src
, dst
):
16 if os
.path
.exists(dst
):
23 if not os
.path
.exists(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
)
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 '
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()
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
,
61 LinkOrCopyFiles(files
, options
.dest_dir
)
63 WriteDepfile(options
.depfile
, files
)
66 if __name__
== '__main__':