update_depot_tools_toggle.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python
  2. # Copyright (c) 2017 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Small utility script to enable/disable `depot_tools` automatic updating."""
  6. import argparse
  7. import datetime
  8. import os
  9. import sys
  10. DEPOT_TOOLS_ROOT = os.path.abspath(os.path.dirname(__file__))
  11. SENTINEL_PATH = os.path.join(DEPOT_TOOLS_ROOT, '.disable_auto_update')
  12. def main():
  13. parser = argparse.ArgumentParser()
  14. group = parser.add_mutually_exclusive_group(required=True)
  15. group.add_argument('--enable', action='store_true',
  16. help='Enable auto-updating.')
  17. group.add_argument('--disable', action='store_true',
  18. help='Disable auto-updating.')
  19. args = parser.parse_args()
  20. if args.enable:
  21. if os.path.exists(SENTINEL_PATH):
  22. os.unlink(SENTINEL_PATH)
  23. if args.disable:
  24. if not os.path.exists(SENTINEL_PATH):
  25. with open(SENTINEL_PATH, 'w') as fd:
  26. fd.write('Disabled by %s at %s\n' % (__file__, datetime.datetime.now()))
  27. return 0
  28. if __name__ == '__main__':
  29. sys.exit(main())