summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ccfg-merge-debug4
-rwxr-xr-xtools/hacking.py18
-rwxr-xr-xtools/mock-meta.py27
-rwxr-xr-xtools/read-dependencies10
-rwxr-xr-xtools/run-pep851
-rwxr-xr-xtools/run-pyflakes18
-rwxr-xr-xtools/run-pyflakes32
-rwxr-xr-xtools/tox-venv42
-rwxr-xr-xtools/validate-yaml.py5
9 files changed, 115 insertions, 62 deletions
diff --git a/tools/ccfg-merge-debug b/tools/ccfg-merge-debug
index 85227da7..1f08e0cb 100755
--- a/tools/ccfg-merge-debug
+++ b/tools/ccfg-merge-debug
@@ -51,7 +51,7 @@ def main():
c_handlers.register(ccph)
called = []
- for (_ctype, mod) in c_handlers.iteritems():
+ for (_ctype, mod) in c_handlers.items():
if mod in called:
continue
handlers.call_begin(mod, data, frequency)
@@ -76,7 +76,7 @@ def main():
# Give callbacks opportunity to finalize
called = []
- for (_ctype, mod) in c_handlers.iteritems():
+ for (_ctype, mod) in c_handlers.items():
if mod in called:
continue
handlers.call_end(mod, data, frequency)
diff --git a/tools/hacking.py b/tools/hacking.py
index e7797564..716c1154 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -47,10 +47,10 @@ def import_normalize(line):
# handle "from x import y as z" to "import x.y as z"
split_line = line.split()
if (line.startswith("from ") and "," not in line and
- split_line[2] == "import" and split_line[3] != "*" and
- split_line[1] != "__future__" and
- (len(split_line) == 4 or
- (len(split_line) == 6 and split_line[4] == "as"))):
+ split_line[2] == "import" and split_line[3] != "*" and
+ split_line[1] != "__future__" and
+ (len(split_line) == 4 or (len(split_line) == 6 and
+ split_line[4] == "as"))):
return "import %s.%s" % (split_line[1], split_line[3])
else:
return line
@@ -74,7 +74,7 @@ def cloud_import_alphabetical(physical_line, line_number, lines):
split_line[0] == "import" and split_previous[0] == "import"):
if split_line[1] < split_previous[1]:
return (0, "N306: imports not in alphabetical order (%s, %s)"
- % (split_previous[1], split_line[1]))
+ % (split_previous[1], split_line[1]))
def cloud_docstring_start_space(physical_line):
@@ -87,8 +87,8 @@ def cloud_docstring_start_space(physical_line):
pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE]) # start
if (pos != -1 and len(physical_line) > pos + 1):
if (physical_line[pos + 3] == ' '):
- return (pos, "N401: one line docstring should not start with"
- " a space")
+ return (pos,
+ "N401: one line docstring should not start with a space")
def cloud_todo_format(physical_line):
@@ -128,7 +128,7 @@ def cloud_docstring_multiline_end(physical_line):
"""
pos = max([physical_line.find(i) for i in DOCSTRING_TRIPLE]) # start
if (pos != -1 and len(physical_line) == pos):
- print physical_line
+ print(physical_line)
if (physical_line[pos + 3] == ' '):
return (pos, "N403: multi line docstring end on new line")
@@ -167,4 +167,4 @@ if __name__ == "__main__":
finally:
if len(_missingImport) > 0:
print >> sys.stderr, ("%i imports missing in this test environment"
- % len(_missingImport))
+ % len(_missingImport))
diff --git a/tools/mock-meta.py b/tools/mock-meta.py
index dfbc2a71..1c746f17 100755
--- a/tools/mock-meta.py
+++ b/tools/mock-meta.py
@@ -126,11 +126,11 @@ class WebException(Exception):
def yamlify(data):
formatted = yaml.dump(data,
- line_break="\n",
- indent=4,
- explicit_start=True,
- explicit_end=True,
- default_flow_style=False)
+ line_break="\n",
+ indent=4,
+ explicit_start=True,
+ explicit_end=True,
+ default_flow_style=False)
return formatted
@@ -282,7 +282,7 @@ class MetaDataHandler(object):
else:
log.warn(("Did not implement action %s, "
"returning empty response: %r"),
- action, NOT_IMPL_RESPONSE)
+ action, NOT_IMPL_RESPONSE)
return NOT_IMPL_RESPONSE
@@ -404,14 +404,17 @@ def setup_logging(log_level, fmt='%(levelname)s: @%(name)s : %(message)s'):
def extract_opts():
parser = OptionParser()
parser.add_option("-p", "--port", dest="port", action="store", type=int,
- default=80, metavar="PORT",
- help="port from which to serve traffic (default: %default)")
+ default=80, metavar="PORT",
+ help=("port from which to serve traffic"
+ " (default: %default)"))
parser.add_option("-a", "--addr", dest="address", action="store", type=str,
- default='0.0.0.0', metavar="ADDRESS",
- help="address from which to serve traffic (default: %default)")
+ default='0.0.0.0', metavar="ADDRESS",
+ help=("address from which to serve traffic"
+ " (default: %default)"))
parser.add_option("-f", '--user-data-file', dest='user_data_file',
- action='store', metavar='FILE',
- help="user data filename to serve back to incoming requests")
+ action='store', metavar='FILE',
+ help=("user data filename to serve back to"
+ "incoming requests"))
(options, args) = parser.parse_args()
out = dict()
out['extra'] = args
diff --git a/tools/read-dependencies b/tools/read-dependencies
index fee3efcf..6a6f3e12 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
+import re
import sys
if 'CLOUD_INIT_TOP_D' in os.environ:
@@ -14,10 +15,15 @@ for fname in ("setup.py", "requirements.txt"):
"exist in cloud-init root directory." % fname)
sys.exit(1)
-with open(os.path.join(topd, "requirements.txt"), "r") as fp:
+if len(sys.argv) > 1:
+ reqfile = sys.argv[1]
+else:
+ reqfile = "requirements.txt"
+
+with open(os.path.join(topd, reqfile), "r") as fp:
for line in fp:
if not line.strip() or line.startswith("#"):
continue
- sys.stdout.write(line)
+ sys.stdout.write(re.split("[>=.<]*", line)[0].strip() + "\n")
sys.exit(0)
diff --git a/tools/run-pep8 b/tools/run-pep8
index ccd6be5a..086400fc 100755
--- a/tools/run-pep8
+++ b/tools/run-pep8
@@ -1,39 +1,22 @@
#!/bin/bash
-if [ $# -eq 0 ]; then
- files=( bin/cloud-init $(find * -name "*.py" -type f) )
+pycheck_dirs=( "cloudinit/" "bin/" "tests/" "tools/" )
+# FIXME: cloud-init modifies sys module path, pep8 does not like
+# bin_files=( "bin/cloud-init" )
+CR="
+"
+[ "$1" = "-v" ] && { verbose="$1"; shift; } || verbose=""
+
+set -f
+if [ $# -eq 0 ]; then unset IFS
+ IFS="$CR"
+ files=( "${bin_files[@]}" "${pycheck_dirs[@]}" )
+ unset IFS
else
- files=( "$@" );
+ files=( "$@" )
fi
-if [ -f 'hacking.py' ]
-then
- base=`pwd`
-else
- base=`pwd`/tools/
-fi
-
-IGNORE=""
-
-# 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
-IGNORE="${IGNORE#,}" # remove the leading ',' added above
-
-cmd=(
- ${base}/hacking.py
-
- --ignore="$IGNORE"
-
- "${files[@]}"
-)
-
-echo -e "\nRunning 'cloudinit' pep8:"
-echo "${cmd[@]}"
-"${cmd[@]}"
+myname=${0##*/}
+cmd=( "${myname#run-}" $verbose "${files[@]}" )
+echo "Running: " "${cmd[@]}" 1>&2
+exec "${cmd[@]}"
diff --git a/tools/run-pyflakes b/tools/run-pyflakes
new file mode 100755
index 00000000..4bea17f4
--- /dev/null
+++ b/tools/run-pyflakes
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+PYTHON_VERSION=${PYTHON_VERSION:-2}
+CR="
+"
+pycheck_dirs=( "cloudinit/" "bin/" "tests/" "tools/" )
+
+set -f
+if [ $# -eq 0 ]; then
+ files=( "${pycheck_dirs[@]}" )
+else
+ files=( "$@" )
+fi
+
+cmd=( "python${PYTHON_VERSION}" -m "pyflakes" "${files[@]}" )
+
+echo "Running: " "${cmd[@]}" 1>&2
+exec "${cmd[@]}"
diff --git a/tools/run-pyflakes3 b/tools/run-pyflakes3
new file mode 100755
index 00000000..e9f0863d
--- /dev/null
+++ b/tools/run-pyflakes3
@@ -0,0 +1,2 @@
+#!/bin/sh
+PYTHON_VERSION=3 exec "${0%/*}/run-pyflakes" "$@"
diff --git a/tools/tox-venv b/tools/tox-venv
new file mode 100755
index 00000000..76ed5076
--- /dev/null
+++ b/tools/tox-venv
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+error() { echo "$@" 1>&2; }
+fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
+Usage() {
+ cat <<EOF
+Usage: ${0##*/} tox-environment [command [args]]
+ run command with provided arguments in the provided tox environment
+ command defaults to \${SHELL:-/bin/sh}.
+
+ invoke with '--list' to show available environments
+EOF
+}
+list_toxes() {
+ local td="$1" pre="$2" d=""
+ ( cd "$tox_d" &&
+ for d in *; do [ -f "$d/bin/activate" ] && echo "${pre}$d"; done)
+}
+
+[ $# -eq 0 ] && { Usage 1>&2; exit 1; }
+[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
+
+env="$1"
+shift
+tox_d="${0%/*}/../.tox"
+activate="$tox_d/$env/bin/activate"
+
+
+[ -d "$tox_d" ] || fail "$tox_d: not a dir. maybe run 'tox'?"
+
+[ "$env" = "-l" -o "$env" = "--list" ] && { list_toxes ; exit ; }
+
+if [ ! -f "$activate" ]; then
+ error "$env: not a valid tox environment?"
+ error "try one of:"
+ list_toxes "$tox_d" " "
+ fail
+fi
+. "$activate"
+
+[ "$#" -gt 0 ] || set -- ${SHELL:-/bin/bash}
+debian_chroot="tox:$env" exec "$@"
diff --git a/tools/validate-yaml.py b/tools/validate-yaml.py
index eda59cb8..ed9037d9 100755
--- a/tools/validate-yaml.py
+++ b/tools/validate-yaml.py
@@ -1,10 +1,9 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
"""Try to read a YAML file and report any errors.
"""
import sys
-
import yaml
@@ -17,7 +16,7 @@ if __name__ == "__main__":
yaml.safe_load(fh.read())
fh.close()
sys.stdout.write(" - ok\n")
- except Exception, e:
+ except Exception as e:
sys.stdout.write(" - bad (%s)\n" % (e))
bads += 1
if bads > 0: