tor-browser

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

validate_inputs.py (827B)


      1 #!/usr/bin/env python3
      2 #
      3 # Copyright 2023 The Chromium Authors
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 """Ensures inputs exist and writes a stamp file."""
      7 
      8 import argparse
      9 import pathlib
     10 import sys
     11 
     12 
     13 def main():
     14  parser = argparse.ArgumentParser()
     15  parser.add_argument('--stamp', help='Path to touch on success.')
     16  parser.add_argument('inputs', nargs='+', help='Files to check.')
     17 
     18  args = parser.parse_args()
     19 
     20  for path in args.inputs:
     21    path_obj = pathlib.Path(path)
     22    if not path_obj.is_file():
     23      if not path_obj.exists():
     24        sys.stderr.write(f'File not found: {path}\n')
     25      else:
     26        sys.stderr.write(f'Not a file: {path}\n')
     27      sys.exit(1)
     28 
     29  if args.stamp:
     30    pathlib.Path(args.stamp).touch()
     31 
     32 
     33 if __name__ == '__main__':
     34  main()