Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 9ce315213f5e50dc30e2dbd4853b792fd92309a8 [file] [log] [blame]
Takuto Ikuta3dab32e02023-01-12 18:52:001#!/usr/bin/env python3
Avi Drissman73a09d12022-09-08 20:33:382# Copyright 2016 The Chromium Authors
zforman08d91b72016-02-12 06:23:423# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
Nico Weber967d1f12018-08-17 02:42:025"""Takes a timestamp and writes it in as readable text to a .h file."""
zforman08d91b72016-02-12 06:23:426
7import argparse
zforman08d91b72016-02-12 06:23:428import datetime
9import os
10import sys
11
zforman08d91b72016-02-12 06:23:4212def main():
Ho Cheung1775adf2023-10-26 16:01:4513 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()
zforman08d91b72016-02-12 06:23:4217
Ho Cheung1775adf2023-10-26 16:01:4518 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')
zforman08d91b72016-02-12 06:23:4225
Ho Cheung1775adf2023-10-26 16:01:4526 current_contents = ''
27 if os.path.isfile(args.output_file):
28 with open(args.output_file, 'r') as current_file:
29 current_contents = current_file.read()
zforman08d91b72016-02-12 06:23:4230
Ho Cheung1775adf2023-10-26 16:01:4531 if current_contents != output:
32 with open(args.output_file, 'w') as output_file:
33 output_file.write(output)
34 return 0
zforman08d91b72016-02-12 06:23:4235
36if __name__ == '__main__':
Ho Cheung1775adf2023-10-26 16:01:4537 sys.exit(main())