Home | History | Annotate | Download | only in standalone
      1 #!/usr/bin/env python
      2 # Copyright (C) 2018 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 
     16 """ Script to check whether a given buildtool folder exists.
     17 
     18 Prints a user-friendly message if it doesn't.
     19 """
     20 
     21 import os
     22 import sys
     23 import argparse
     24 
     25 def main():
     26   parser = argparse.ArgumentParser(description='Test path for existence')
     27   parser.add_argument('path', help='Path to test for existence')
     28   parser.add_argument('--touch', help='Touch this path on success')
     29   args = parser.parse_args()
     30 
     31   if not os.path.exists(args.path):
     32     err = '\x1b[31mCannot find %s/%s\nRun tools/install-build-deps --ui\x1b[0m'
     33     print >>sys.stderr,  err % (os.path.abspath('.'), sys.argv[1])
     34     return 127
     35 
     36   if args.touch:
     37     with open(args.touch, 'a'):
     38       os.utime(args.touch, None)
     39 
     40   return 0
     41 
     42 if __name__ == '__main__':
     43   sys.exit(main())
     44