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

Side by Side Diff: mojo/public/tools/prepend.py

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « mojo/public/tools/ls.py ('k') | mojo/public/tools/pylib/gs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """
8 Prepends a given file with a given line. This can be used to add a shebang line
9 to a generated file.
10 """
11
12 import optparse
13 import os
14 import shutil
15 import sys
16
17
18 def main():
19 parser = optparse.OptionParser()
20 parser.add_option('--input', help='The file to prepend the line to.')
21 parser.add_option('--line', help='The line to be prepended.')
22 parser.add_option('--output', help='The output file.')
23
24 options, _ = parser.parse_args()
25 input_path = options.input
26 output_path = options.output
27 line = options.line
28
29 # Warning - this reads all of the input file into memory.
30 with open(output_path, 'w') as output_file:
31 output_file.write(line + '\n')
32 with open(input_path, 'r') as input_file:
33 shutil.copyfileobj(input_file, output_file)
34
35
36 if __name__ == '__main__':
37 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/tools/ls.py ('k') | mojo/public/tools/pylib/gs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698