You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
765 B
32 lines
765 B
#!/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())
|