blob: 2b2ca8687a0d679bd50078c435e5535e851c0eb0 [file] [log] [blame]
#!/usr/bin/env python3
import sys
import os
def main():
# Typically the target file argument is the last arg. gsutil invokes:
# `file -b --mime /path/to/file`. Rathter than depending on it, just pick
# the right-most argument which points to a valid file.
fname = None
for arg in reversed(sys.argv[1:]):
if os.path.exists(arg):
fname = arg
break
if fname is None:
raise 'File not found in ' + ' '.join(sys.argv)
ext = os.path.splitext(fname)[1].lower()
ext_map = {
'.html': 'text/html',
'.css': 'text/css',
'.js': 'text/javascript',
'.jpg': 'image/jpeg',
'.png': 'image/png',
'.svg': 'image/svg+xml',
}
print(ext_map.get(ext, 'text/html'))
return 0
if __name__ == '__main__':
sys.exit(main())