tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

write_build_date_header.py (1121B)


      1 #!/usr/bin/env python3
      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."""
      6 
      7 import argparse
      8 import datetime
      9 import os
     10 import sys
     11 
     12 
     13 def main():
     14  argument_parser = argparse.ArgumentParser()
     15  argument_parser.add_argument('output_file', help='The file to write to')
     16  argument_parser.add_argument('timestamp')
     17  args = argument_parser.parse_args()
     18 
     19  date = datetime.datetime.utcfromtimestamp(int(args.timestamp))
     20  output = ('// Generated by //build/write_build_date_header.py\n'
     21           '#ifndef BUILD_DATE\n'
     22           '#define BUILD_DATE "{:%b %d %Y %H:%M:%S}"\n'
     23           '#endif // BUILD_DATE\n'.format(date))
     24 
     25  current_contents = ''
     26  if os.path.isfile(args.output_file):
     27    with open(args.output_file, 'r') as current_file:
     28      current_contents = current_file.read()
     29 
     30  if current_contents != output:
     31    with open(args.output_file, 'w') as output_file:
     32      output_file.write(output)
     33  return 0
     34 
     35 
     36 if __name__ == '__main__':
     37  sys.exit(main())