update_depot_tools_toggle.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  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',
  16. action='store_true',
  17. help='Enable auto-updating.')
  18. group.add_argument('--disable',
  19. action='store_true',
  20. help='Disable auto-updating.')
  21. args = parser.parse_args()
  22. if args.enable:
  23. if os.path.exists(SENTINEL_PATH):
  24. os.unlink(SENTINEL_PATH)
  25. if args.disable:
  26. if not os.path.exists(SENTINEL_PATH):
  27. with open(SENTINEL_PATH, 'w') as fd:
  28. fd.write('Disabled by %s at %s\n' %
  29. (__file__, datetime.datetime.now()))
  30. return 0
  31. if __name__ == '__main__':
  32. sys.exit(main())