]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Detect addition of executable files
authorEric Harney <eharney@redhat.com>
Fri, 28 Aug 2015 18:32:30 +0000 (14:32 -0400)
committerEric Harney <eharney@redhat.com>
Mon, 31 Aug 2015 16:19:51 +0000 (12:19 -0400)
When running pep8 checks, fail if executable
files have accidentally been added.

Change-Id: Ia0efa629acf794f8e0e9b78de24b5385776c1e66

run_tests.sh
tools/check_exec.py [new file with mode: 0755]
tox.ini

index 7d5a324480b5742429f707417fbc08b5896ca8b0..db32c57eb1efc561c76e0111da7f00d37d467459 100755 (executable)
@@ -185,6 +185,7 @@ function run_pep8 {
   warn_on_flake8_without_venv
   bash -c "${wrapper} flake8"
   ${wrapper} bash tools/config/check_uptodate.sh --checkonly
+  ${wrapper} tools/check_exec.py cinder || exit 1
 }
 
 
diff --git a/tools/check_exec.py b/tools/check_exec.py
new file mode 100755 (executable)
index 0000000..d423f3d
--- /dev/null
@@ -0,0 +1,42 @@
+#!/usr/bin/python
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+# Print a list and return with error if any executable files are found.
+# Compatible with both python 2 and 3.
+
+import os.path
+import stat
+import sys
+
+if len(sys.argv) < 2:
+    print("Usage: %s <directory>" % sys.argv[0])
+    sys.exit(1)
+
+directory = sys.argv[1]
+
+executable = []
+
+for root, mydir, myfile in os.walk(directory):
+    for f in myfile:
+        path = os.path.join(root, f)
+        mode = os.lstat(path).st_mode
+        if stat.S_IXUSR & mode:
+            executable.append(path)
+
+if executable:
+    print("Executable files found:")
+    for f in executable:
+        print(f)
+
+    sys.exit(1)
diff --git a/tox.ini b/tox.ini
index b026e036b0fd36e9a9b33de493d0add14df9ff55..4eea5df4c4fe30a68f18220bbe5e837a30fff3e0 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -112,6 +112,7 @@ commands =
   # Check that .po and .pot files are valid:
   bash -c "find cinder -type f -regex '.*\.pot?' -print0|xargs -0 -n 1 msgfmt --check-format -o /dev/null"
   {toxinidir}/tools/config/check_uptodate.sh --checkonly
+  {toxinidir}/tools/check_exec.py {toxinidir}/cinder
 
 [testenv:pylint]
 deps = -r{toxinidir}/requirements.txt