fetch_from_mds.py 1.4 KB

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