Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2016 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 # Writes a file that contains a define that approximates the build date. | |
|
M-A Ruel
2016/02/01 17:52:28
Convert to docstring.
Zachary Forman
2016/02/02 06:30:38
Done!
| |
| 7 # argv[1] is the location to write the file. | |
| 8 # If argv[2] == "--official", returns the current date in UTC. | |
| 9 # Otherwise, returns the first day of the current month (in UTC). | |
| 10 # If argv[2] == "--override", use argv[3] as the build date. | |
| 11 | |
| 12 import sys | |
| 13 from datetime import datetime | |
| 14 | |
|
M-A Ruel
2016/02/01 17:52:28
2 lines between file level symbols.
Zachary Forman
2016/02/02 06:30:38
Done!
| |
| 15 def BuildDate(build_type): | |
| 16 if build_type == "--official": | |
|
M-A Ruel
2016/02/01 17:52:28
use single quotes everywhere.
Zachary Forman
2016/02/02 06:30:38
Done!
| |
| 17 format = "{:%b %d %Y}" | |
| 18 else: | |
| 19 format = "{:%b 01 %Y}" | |
|
M-A Ruel
2016/02/01 17:52:28
I thought about it more and I'd want a slightly mo
Zachary Forman
2016/02/02 06:30:38
I like this idea. I'd want it to switch on Sunday
| |
| 20 return format.format(datetime.utcnow()) | |
| 21 | |
| 22 def main(arguments): | |
| 23 output_location = arguments[1]; | |
|
M-A Ruel
2016/02/01 17:52:28
No trailing ;
Zachary Forman
2016/02/02 06:30:38
Done
| |
| 24 build_type = arguments[2] if len(arguments) > 2 else "default" | |
|
M-A Ruel
2016/02/01 17:52:28
Please use argparse. It's going to make the script
Zachary Forman
2016/02/02 06:30:38
Done!
| |
| 25 if len(arguments) > 2 and arguments[2] == "--override": | |
| 26 build_date = arguments[3] | |
| 27 else: | |
| 28 build_date = BuildDate(build_type) | |
| 29 with open(output_location, "w") as output_file: | |
| 30 output_file.write("// Generated by //build/write_build_date_header.py\n") | |
| 31 output_file.write("#ifndef BUILD_DATE\n") | |
| 32 output_file.write("#define BUILD_DATE \"{}\"\n".format(build_date)) | |
| 33 output_file.write("#endif // BUILD_DATE\n") | |
| 34 return 0 | |
| 35 | |
| 36 | |
| 37 if __name__ == '__main__': | |
| 38 sys.exit(main(sys.argv)) | |
| OLD | NEW |