2 # Copyright 2016 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Takes a timestamp and writes it in as readable text to a .h file."""
13 argument_parser = argparse.ArgumentParser()
14 argument_parser.add_argument('output_file', help='The file to write to')
15 argument_parser.add_argument('timestamp')
16 args = argument_parser.parse_args()
18 date_val = int(args.timestamp)
19 date = datetime.datetime.fromtimestamp(date_val, tz=datetime.timezone.utc)
20 output = ('// Generated by //base/write_build_date_header.py\n'
21 '#ifndef BASE_GENERATED_BUILD_DATE_TIMESTAMP \n'
22 f'#define BASE_GENERATED_BUILD_DATE_TIMESTAMP {date_val}'
23 f' // {date:%b %d %Y %H:%M:%S}\n'
24 '#endif // BASE_GENERATED_BUILD_DATE_TIMESTAMP \n')
27 if os.path.isfile(args.output_file):
28 with open(args.output_file, 'r') as current_file:
29 current_contents = current_file.read()
31 if current_contents != output:
32 with open(args.output_file, 'w') as output_file:
33 output_file.write(output)
36 if __name__ == '__main__':