fetch_from_archive.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import print_function
  2. import os
  3. import sys
  4. import logging
  5. import argparse
  6. # Explicitly enable local imports
  7. # Don't forget to add imported scripts to inputs of the calling command!
  8. sys.path.append(os.path.dirname(os.path.abspath(__file__)))
  9. import fetch_from
  10. def parse_args():
  11. parser = argparse.ArgumentParser()
  12. fetch_from.add_common_arguments(parser)
  13. parser.add_argument('--file-name', required=True)
  14. parser.add_argument('--archive', required=True)
  15. return parser.parse_args()
  16. def main(args):
  17. archive = args.archive
  18. file_name = args.file_name.rstrip('-')
  19. fetch_from.process(archive, file_name, args, remove=False)
  20. if __name__ == '__main__':
  21. args = parse_args()
  22. fetch_from.setup_logging(args, os.path.basename(__file__))
  23. try:
  24. main(args)
  25. except Exception as e:
  26. logging.exception(e)
  27. print(open(args.abs_log_path).read(), file=sys.stderr)
  28. sys.stderr.flush()
  29. import error
  30. sys.exit(error.ExitCodes.INFRASTRUCTURE_ERROR if fetch_from.is_temporary(e) else 1)