Last active
June 6, 2017 00:58
-
-
Save Yoplitein/b9b7bf4c954788818cec to your computer and use it in GitHub Desktop.
Python script to generate a list of mimetype -> extension mappings for nginx/lighttpd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
mimeList = "" | |
mapping = {} | |
with open("/etc/mime.types", "r") as f: | |
mimeList = f.read().split("\n") | |
for entry in mimeList: | |
entry = entry.split("\t") | |
while '' in entry: | |
entry.remove('') | |
if len(entry) == 2: #entry is ["mime", "extension1 extension2"] | |
mime, extensions = entry | |
for extension in extensions.split(" "): | |
mapping[extension] = mime | |
print("mimetype.assign = (") | |
for extension, mime in mapping.iteritems(): | |
print(''' "{}" => "{}",'''.format(extension, mime)) | |
print(")") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
mimeList = "" | |
types = {} | |
with open("/etc/mime.types", "r") as f: | |
mimeList = f.read().split("\n") | |
for entry in mimeList: | |
entry = entry.split("\t") | |
while '' in entry: | |
entry.remove('') | |
if len(entry) == 2: #entry is ["mime", "extension1 extension2"] | |
mime, extensions = entry | |
for extension in extensions.split(" "): | |
types[mime] = types.get(mime, []) + [extension] | |
print("types {") | |
for mime, extensions in types.iteritems(): | |
print(" {} {};".format(mime, " ".join(extensions))) | |
print("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment