fetch_from_mds.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import sys
  3. import logging
  4. import argparse
  5. import fetch_from
  6. MDS_PREFIX = "https://storage.yandex-team.ru/get-devtools/"
  7. def parse_args():
  8. parser = argparse.ArgumentParser()
  9. fetch_from.add_common_arguments(parser)
  10. parser.add_argument('--key', required=True)
  11. return parser.parse_args()
  12. def fetch(key):
  13. parts = key.split("/")
  14. if len(parts) != 3:
  15. raise ValueError("Invalid MDS key '{}'".format(key))
  16. _, sha1, file_name = parts
  17. fetched_file = fetch_from.fetch_url(MDS_PREFIX + key, False, file_name, expected_sha1=sha1)
  18. return fetched_file, file_name
  19. def main(args):
  20. fetched_file, resource_file_name = fetch(args.key)
  21. fetch_from.process(fetched_file, resource_file_name, args)
  22. if __name__ == '__main__':
  23. args = parse_args()
  24. fetch_from.setup_logging(args, os.path.basename(__file__))
  25. try:
  26. main(args)
  27. except Exception as e:
  28. logging.exception(e)
  29. print >>sys.stderr, open(args.abs_log_path).read()
  30. sys.stderr.flush()
  31. import error
  32. sys.exit(error.ExitCodes.INFRASTRUCTURE_ERROR if fetch_from.is_temporary(e) else 1)