summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/Z99-cloud-locale-test.sh15
-rwxr-xr-xtools/hacking.py4
-rwxr-xr-xtools/make-mime.py60
-rwxr-xr-xtools/run-pep816
-rwxr-xr-xtools/run-pylint19
-rwxr-xr-xtools/validate-yaml.py26
-rwxr-xr-xtools/write-ssh-key-fingerprints15
7 files changed, 129 insertions, 26 deletions
diff --git a/tools/Z99-cloud-locale-test.sh b/tools/Z99-cloud-locale-test.sh
index 8ad485e8..3c51f22d 100755
--- a/tools/Z99-cloud-locale-test.sh
+++ b/tools/Z99-cloud-locale-test.sh
@@ -10,10 +10,13 @@
#
locale_warn() {
- local cr="
-"
- local bad_names="" bad_lcs="" key="" value="" var=""
+ local bad_names="" bad_lcs="" key="" val="" var="" vars=""
local w1 w2 w3 w4 remain
+
+ # if shell is zsh, act like sh only for this function (-L).
+ # The behavior change will not permenently affect user's shell.
+ [ "${ZSH_NAME+zsh}" = "zsh" ] && emulate -L sh
+
# locale is expected to output either:
# VARIABLE=
# VARIABLE="value"
@@ -32,9 +35,9 @@ locale_warn() {
for bad in $bad_names; do
for var in ${vars}; do
[ "${bad}" = "${var%=*}" ] || continue
- value=${var#*=}
- [ "${bad_lcs#* ${value}}" = "${bad_lcs}" ] &&
- bad_lcs="${bad_lcs} ${value}"
+ val=${var#*=}
+ [ "${bad_lcs#* ${val}}" = "${bad_lcs}" ] &&
+ bad_lcs="${bad_lcs} ${val}"
break
done
done
diff --git a/tools/hacking.py b/tools/hacking.py
index 11163df3..26a07c53 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -66,8 +66,8 @@ def cloud_import_alphabetical(physical_line, line_number, lines):
# handle import x
# use .lower since capitalization shouldn't dictate order
split_line = import_normalize(physical_line.strip()).lower().split()
- split_previous = import_normalize(lines[line_number - 2]
- ).strip().lower().split()
+ split_previous = import_normalize(lines[line_number - 2])
+ split_previous = split_previous.strip().lower().split()
# with or without "as y"
length = [2, 4]
if (len(split_line) in length and len(split_previous) in length and
diff --git a/tools/make-mime.py b/tools/make-mime.py
new file mode 100755
index 00000000..72b29fb9
--- /dev/null
+++ b/tools/make-mime.py
@@ -0,0 +1,60 @@
+#!/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:
+ raise argparse.ArgumentError("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())
diff --git a/tools/run-pep8 b/tools/run-pep8
index ea46c117..20e594bc 100755
--- a/tools/run-pep8
+++ b/tools/run-pep8
@@ -1,6 +1,6 @@
#!/bin/bash
-ci_files='cloud*.py cloudinit/*.py cloudinit/config/*.py'
+ci_files='cloudinit/*.py cloudinit/config/*.py'
test_files=$(find tests -name "*.py")
def_files="$ci_files $test_files"
@@ -21,10 +21,22 @@ else
base=`pwd`/tools/
fi
+IGNORE="E501" # Line too long (these are caught by pylint)
+
+# King Arthur: Be quiet! ... Be Quiet! I Order You to Be Quiet.
+IGNORE="$IGNORE,E121" # Continuation line indentation is not a multiple of four
+IGNORE="$IGNORE,E123" # Closing bracket does not match indentation of opening bracket's line
+IGNORE="$IGNORE,E124" # Closing bracket missing visual indentation
+IGNORE="$IGNORE,E125" # Continuation line does not distinguish itself from next logical line
+IGNORE="$IGNORE,E126" # Continuation line over-indented for hanging indent
+IGNORE="$IGNORE,E127" # Continuation line over-indented for visual indent
+IGNORE="$IGNORE,E128" # Continuation line under-indented for visual indent
+IGNORE="$IGNORE,E502" # The backslash is redundant between brackets
+
cmd=(
${base}/hacking.py
- --ignore=E501 # Line too long (these are caught by pylint)
+ --ignore="$IGNORE"
"${files[@]}"
)
diff --git a/tools/run-pylint b/tools/run-pylint
index 7ef44ac5..b74efda9 100755
--- a/tools/run-pylint
+++ b/tools/run-pylint
@@ -6,23 +6,16 @@ else
files=( "$@" );
fi
+RC_FILE="pylintrc"
+if [ ! -f $RC_FILE ]; then
+ RC_FILE="../pylintrc"
+fi
+
cmd=(
pylint
- --reports=n
- --include-ids=y
- --max-line-length=79
-
+ --rcfile=$RC_FILE
--disable=R
--disable=I
-
- --disable=W0142 # Used * or ** magic
- --disable=W0511 # TODO/FIXME note
- --disable=W0702 # No exception type(s) specified
- --disable=W0703 # Catch "Exception"
-
- --disable=C0103 # Invalid name
- --disable=C0111 # Missing docstring
-
"${files[@]}"
)
diff --git a/tools/validate-yaml.py b/tools/validate-yaml.py
new file mode 100755
index 00000000..eda59cb8
--- /dev/null
+++ b/tools/validate-yaml.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+"""Try to read a YAML file and report any errors.
+"""
+
+import sys
+
+import yaml
+
+
+if __name__ == "__main__":
+ bads = 0
+ for fn in sys.argv[1:]:
+ sys.stdout.write("%s" % (fn))
+ try:
+ fh = open(fn, 'r')
+ yaml.safe_load(fh.read())
+ fh.close()
+ sys.stdout.write(" - ok\n")
+ except Exception, e:
+ sys.stdout.write(" - bad (%s)\n" % (e))
+ bads += 1
+ if bads > 0:
+ sys.exit(1)
+ else:
+ sys.exit(0)
diff --git a/tools/write-ssh-key-fingerprints b/tools/write-ssh-key-fingerprints
index aa1f3c38..6c3451fd 100755
--- a/tools/write-ssh-key-fingerprints
+++ b/tools/write-ssh-key-fingerprints
@@ -1,5 +1,14 @@
#!/bin/sh
+
+logger_opts="-p user.info -t ec2"
+
+# rhels' version of logger_opts does not support long
+# for of -s (--stderr), so use short form.
+logger_opts="$logger_opts -s"
+
+# Redirect stderr to stdout
exec 2>&1
+
fp_blist=",${1},"
key_blist=",${2},"
{
@@ -16,9 +25,9 @@ done
echo "-----END SSH HOST KEY FINGERPRINTS-----"
echo "#############################################################"
-} | logger -p user.info --stderr -t "ec2"
+} | logger $logger_opts
-echo -----BEGIN SSH HOST KEY KEYS-----
+echo "-----BEGIN SSH HOST KEY KEYS-----"
for f in /etc/ssh/ssh_host_*key.pub; do
[ -f "$f" ] || continue
read ktype line < "$f"
@@ -26,4 +35,4 @@ for f in /etc/ssh/ssh_host_*key.pub; do
[ "${key_blist#*,$ktype,}" = "${key_blist}" ] || continue
cat $f
done
-echo -----END SSH HOST KEY KEYS-----
+echo "-----END SSH HOST KEY KEYS-----"