• Raphael Kubo da Costa's avatar
    presubmit: Add InputApi.CreateTemporaryFile() · f2d1615b
    Raphael Kubo da Costa authored
    Sometimes, InputApi users need to create temporary files, write to them and
    pass them to another process, like this:
    
      with input_api.tempfile.NamedTemporaryFile() as f:
        f.write('foo')
        input_api.subprocess.check_output(['/path/to/script',
            '--reading-from', f.name])
    
    While this works fine on Unix, on Windows subprocess cannot open and read
    the file while we have it open for writing.
    
    To work around this, we now offer a CreateTemporaryFile() that wraps a call
    to tempfile.NamedTemporaryFile(delete=False), and we then take care of
    removing all files created this way at the end of a presubmit run.
    
    The idea is for users to do something like this:
    
      with input_api.CreateTemporaryFile() as f:
        f.write('foo')
        f.close()
        input_api.subprocess.check_output(['/path/to/script',
            '--reading-from', f.name])
    
    with the temporary file being removed automatically in a transparent fashion
    later.
    
    Bug: 780629
    Change-Id: I0d705a5d52928a43f39a51f94a2c48d277bd5ced
    Reviewed-on: https://chromium-review.googlesource.com/758637
    Commit-Queue: Raphael Kubo da Costa (rakuco) <raphael.kubo.da.costa@intel.com>
    Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
    f2d1615b
Name
Last commit
Last update
..
gstools Loading commit data...
bot_update_coverage_test.py Loading commit data...
checkout_test.py Loading commit data...
download_from_google_storage_unittest.py Loading commit data...
fix_encoding_test.py Loading commit data...
gclient_eval_unittest.py Loading commit data...
gclient_scm_test.py Loading commit data...
gclient_smoketest.py Loading commit data...
gclient_test.py Loading commit data...
gclient_utils_test.py Loading commit data...
git_cache_test.py Loading commit data...
git_cl_creds_check_report.txt Loading commit data...
git_cl_test.py Loading commit data...
git_common_test.py Loading commit data...
git_dates_test.py Loading commit data...
git_drover_test.py Loading commit data...
git_footers_test.py Loading commit data...
git_hyper_blame_test.py Loading commit data...
git_number_test.py Loading commit data...
git_rebase_update_test.py Loading commit data...
gsutil_test.py Loading commit data...
owners_finder_test.py Loading commit data...
owners_unittest.py Loading commit data...
patch_test.py Loading commit data...
presubmit_unittest.py Loading commit data...
recipes_test.py Loading commit data...
scm_unittest.py Loading commit data...
subprocess2_test.py Loading commit data...
upload_to_google_storage_unittest.py Loading commit data...
watchlists_unittest.py Loading commit data...