mirror of https://github.com/CrowCpp/Crow.git
Updated mime_types script:
Made script generated code format compliant Added option to have the script download the source file directly Added generation date Also updated the header file to the latest nginx mime.types
This commit is contained in:
parent
94a2f942bc
commit
78c88bbbb7
|
@ -1,4 +1,4 @@
|
|||
// This file is generated from nginx/conf/mime.types using nginx_mime2cpp.py
|
||||
// This file is generated from nginx/conf/mime.types using nginx_mime2cpp.py on 2021-12-03.
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
|
@ -21,6 +21,7 @@ namespace crow
|
|||
{"jad", "text/vnd.sun.j2me.app-descriptor"},
|
||||
{"wml", "text/vnd.wap.wml"},
|
||||
{"htc", "text/x-component"},
|
||||
{"avif", "image/avif"},
|
||||
{"png", "image/png"},
|
||||
{"svgz", "image/svg+xml"},
|
||||
{"svg", "image/svg+xml"},
|
||||
|
@ -58,6 +59,7 @@ namespace crow
|
|||
{"xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
|
||||
{"docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
|
||||
{"wmlc", "application/vnd.wap.wmlc"},
|
||||
{"wasm", "application/wasm"},
|
||||
{"7z", "application/x-7z-compressed"},
|
||||
{"cco", "application/x-cocoa"},
|
||||
{"jardiff", "application/x-java-archive-diff"},
|
||||
|
|
|
@ -3,24 +3,33 @@
|
|||
#get mime.types file from the nginx repository at nginx/conf/mime.types
|
||||
#typical output filename: mime_types.h
|
||||
import sys
|
||||
from datetime import date
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: {} <NGINX_MIME_TYPE_FILE_PATH> <CROW_OUTPUT_HEADER_PATH>".format(sys.argv[0]))
|
||||
if (len(sys.argv) != 3) and (len(sys.argv) != 2):
|
||||
print("Usage (local file): {} <NGINX_MIME_TYPE_FILE_PATH> <CROW_OUTPUT_HEADER_PATH>".format(sys.argv[0]))
|
||||
print("(downloads file) : {} <CROW_OUTPUT_HEADER_PATH>".format(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
|
||||
file_path = sys.argv[1]
|
||||
output_path = sys.argv[2]
|
||||
if len(sys.argv) == 3:
|
||||
file_path = sys.argv[1]
|
||||
output_path = sys.argv[2]
|
||||
elif len(sys.argv) == 2:
|
||||
import requests
|
||||
open("mime.types", "wb").write(requests.get("https://hg.nginx.org/nginx/raw-file/tip/conf/mime.types").content)
|
||||
file_path = "mime.types"
|
||||
output_path = sys.argv[1]
|
||||
|
||||
tabspace = " "
|
||||
tabandahalfspace = " "
|
||||
def main():
|
||||
outLines = []
|
||||
outLines.append("//This file is generated from nginx/conf/mime.types using nginx_mime2cpp.py")
|
||||
outLines.append("// This file is generated from nginx/conf/mime.types using nginx_mime2cpp.py on " + date.today().strftime('%Y-%m-%d') + ".")
|
||||
outLines.extend([
|
||||
"#include <unordered_map>",
|
||||
"#include <string>",
|
||||
"",
|
||||
"namespace crow {",
|
||||
tabspace + "const std::unordered_map<std::string, std::string> mime_types {"])
|
||||
"namespace crow",
|
||||
"{",
|
||||
tabspace + "const std::unordered_map<std::string, std::string> mime_types{"])
|
||||
|
||||
with open(file_path, "r") as mtfile:
|
||||
incomplete = ""
|
||||
|
@ -39,11 +48,8 @@ def main():
|
|||
incompleteExists = False
|
||||
outLines.extend(mime_line_to_cpp(splitLine))
|
||||
|
||||
outLines[-1] = outLines[-1][:-1]
|
||||
outLines.extend([
|
||||
tabspace + "};",
|
||||
"}"
|
||||
])
|
||||
outLines[-1] = outLines[-1][:-1] + "};"
|
||||
outLines.append("}")
|
||||
|
||||
with open(output_path, "w") as mtcppfile:
|
||||
mtcppfile.writelines(x + '\n' for x in outLines)
|
||||
|
@ -55,7 +61,7 @@ def mime_line_to_cpp(mlist):
|
|||
if (mlist[i].endswith(";")):
|
||||
mlist[i] = mlist[i][:-1]
|
||||
for i in range (len(mlist)-1, 0, -1):
|
||||
stringReturn.append(tabspace*2 + "{\"" + mlist[i] + "\", \"" + mlist[0] + "\"},")
|
||||
stringReturn.append(tabandahalfspace + "{\"" + mlist[i] + "\", \"" + mlist[0] + "\"},")
|
||||
#print("created: " + stringReturn)
|
||||
return stringReturn
|
||||
|
||||
|
|
Loading…
Reference in New Issue