summaryrefslogtreecommitdiff
path: root/tools/make-mime.py
diff options
context:
space:
mode:
authorzdc <zdc@users.noreply.github.com>2020-09-15 21:35:20 +0300
committerGitHub <noreply@github.com>2020-09-15 21:35:20 +0300
commit76adf82b8a4dbcf636151d292175b7d1ac182fcf (patch)
treef57f3db085a724df237ffa64b589c6bb6dd3b28f /tools/make-mime.py
parent1a790ee102fd405e5c3a20a17a69ba0c118ed874 (diff)
parent7cd260b313267dc7123cb99a75d4555e24909cca (diff)
downloadvyos-cloud-init-76adf82b8a4dbcf636151d292175b7d1ac182fcf.tar.gz
vyos-cloud-init-76adf82b8a4dbcf636151d292175b7d1ac182fcf.zip
Merge pull request #18 from zdc/T2117-equuleus-20.3
T2117: Cloud-init updated to 20.3
Diffstat (limited to 'tools/make-mime.py')
-rwxr-xr-xtools/make-mime.py62
1 files changed, 0 insertions, 62 deletions
diff --git a/tools/make-mime.py b/tools/make-mime.py
deleted file mode 100755
index d321479b..00000000
--- a/tools/make-mime.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/python
-
-import argparse
-import sys
-
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-
-KNOWN_CONTENT_TYPES = [
- 'text/x-include-once-url',
- 'text/x-include-url',
- 'text/cloud-config-archive',
- 'text/upstart-job',
- 'text/cloud-config',
- 'text/part-handler',
- 'text/x-shellscript',
- 'text/cloud-boothook',
-]
-
-
-def file_content_type(text):
- try:
- filename, content_type = text.split(":", 1)
- return (open(filename, 'r'), filename, content_type.strip())
- except ValueError:
- raise argparse.ArgumentError(text, "Invalid value for %r" % (text))
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument("-a", "--attach",
- dest="files",
- type=file_content_type,
- action='append',
- default=[],
- required=True,
- metavar="<file>:<content-type>",
- help="attach the given file in the specified "
- "content type")
- args = parser.parse_args()
- sub_messages = []
- for i, (fh, filename, format_type) in enumerate(args.files):
- contents = fh.read()
- sub_message = MIMEText(contents, format_type, sys.getdefaultencoding())
- sub_message.add_header('Content-Disposition',
- 'attachment; filename="%s"' % (filename))
- content_type = sub_message.get_content_type().lower()
- if content_type not in KNOWN_CONTENT_TYPES:
- sys.stderr.write(("WARNING: content type %r for attachment %s "
- "may be incorrect!\n") % (content_type, i + 1))
- sub_messages.append(sub_message)
- combined_message = MIMEMultipart()
- for msg in sub_messages:
- combined_message.attach(msg)
- print(combined_message)
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main())
-
-# vi: ts=4 expandtab