Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: third_party/liblouis/copy_tables.py

Issue 1145243006: Port chromevox build to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@externs
Patch Set: Unshare some vars, add TODO for the rest. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
5
6 '''Copies the liblouis braille translation tables to a destination.'''
7
8 import liblouis_list_tables
9 import optparse
10 import os
11 import shutil
12
13
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)
22
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)))
27
28
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)
35
36
37
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()
52
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)
64
65
66 if __name__ == '__main__':
67 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698