Home | History | Annotate | Download | only in presubmit_hooks
      1 #!/usr/bin/python -u
      2 """
      3 Wrapper to run 'suite_scheduler.py --sanity' before uploading a patch.
      4 This script is invoked through PRESUBMIT.cfg from repohooks, and expects a
      5 list of commit files in the environment variable.
      6 """
      7 
      8 import os, re, sys
      9 import common
     10 from autotest_lib.client.common_lib import utils
     11 
     12 
     13 def _commit_contains_ini_or_control():
     14     """
     15     Checks if commit contains suite_scheduler.ini or a control file.
     16 
     17     @return: True if one of the files in the commit is suite_scheduler.ini.
     18     """
     19     file_list = os.environ.get('PRESUBMIT_FILES')
     20     if file_list is None:
     21         print 'Expected a list of presubmit files in the environment variable.'
     22         sys.exit(1)
     23 
     24     pattern = re.compile(r'.*files/suite_scheduler.ini$|.*/control(?:\.\w+)?$')
     25     return any (pattern.search(file_path)
     26                 for file_path in file_list.split('\n'))
     27 
     28 
     29 def main():
     30     """
     31     Main function, invokes suite scheduler's sanity checker if the
     32     commit contains either suite_scheduler.ini or a control file.
     33     """
     34     if _commit_contains_ini_or_control():
     35         site_utils_dir = os.path.dirname(
     36                              os.path.dirname(os.path.abspath(__file__)))
     37         suite_scheduler = os.path.join(site_utils_dir,
     38                                        'suite_scheduler/suite_scheduler.py')
     39         output = utils.system_output(suite_scheduler + ' --sanity')
     40         if output:
     41             print output
     42             sys.exit(1)
     43 
     44 
     45 if __name__ == '__main__':
     46     main()
     47