• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import sys
4import os
5
6def main():
7  # Typically the target file argument is the last arg. gsutil invokes:
8  # `file -b --mime /path/to/file`. Rathter than depending on it, just pick
9  # the right-most argument which points to a valid file.
10  fname = None
11  for arg in reversed(sys.argv[1:]):
12    if os.path.exists(arg):
13      fname = arg
14      break
15  if fname is None:
16    raise 'File not found in ' + ' '.join(sys.argv)
17
18  ext = os.path.splitext(fname)[1].lower()
19  ext_map = {
20    '.html': 'text/html',
21    '.css': 'text/css',
22    '.js': 'text/javascript',
23    '.jpg': 'image/jpeg',
24    '.png': 'image/png',
25    '.svg': 'image/svg+xml',
26  }
27  print(ext_map.get(ext, 'text/html'))
28  return 0
29
30if __name__ == '__main__':
31  sys.exit(main())
32