From 1c2ec9b8cfae0ee06af2fd5d68eae9f148462c79 Mon Sep 17 00:00:00 2001
From: Tom Barron <tpb@dyncloud.net>
Date: Mon, 4 Apr 2016 14:14:07 -0400
Subject: [PATCH] Detect addition of executable files

When running pep8 checks, fail if executable
files have accidentally been added.

Co-Authored-By: Eric Harney <eharney@redhat.com>

Closes-Bug: 1566328
Change-Id: I7280c0403cd473cd4b88cfc021d4f605a7bb35f2
---
 manila/cmd/all.py       |  0
 manila/cmd/api.py       |  0
 manila/cmd/data.py      |  0
 manila/cmd/manage.py    |  0
 manila/cmd/scheduler.py |  0
 manila/cmd/share.py     |  0
 tools/check_exec.py     | 42 +++++++++++++++++++++++++++++++++++++++++
 tox.ini                 |  1 +
 8 files changed, 43 insertions(+)
 mode change 100755 => 100644 manila/cmd/all.py
 mode change 100755 => 100644 manila/cmd/api.py
 mode change 100755 => 100644 manila/cmd/data.py
 mode change 100755 => 100644 manila/cmd/manage.py
 mode change 100755 => 100644 manila/cmd/scheduler.py
 mode change 100755 => 100644 manila/cmd/share.py
 create mode 100755 tools/check_exec.py

diff --git a/manila/cmd/all.py b/manila/cmd/all.py
old mode 100755
new mode 100644
diff --git a/manila/cmd/api.py b/manila/cmd/api.py
old mode 100755
new mode 100644
diff --git a/manila/cmd/data.py b/manila/cmd/data.py
old mode 100755
new mode 100644
diff --git a/manila/cmd/manage.py b/manila/cmd/manage.py
old mode 100755
new mode 100644
diff --git a/manila/cmd/scheduler.py b/manila/cmd/scheduler.py
old mode 100755
new mode 100644
diff --git a/manila/cmd/share.py b/manila/cmd/share.py
old mode 100755
new mode 100644
diff --git a/tools/check_exec.py b/tools/check_exec.py
new file mode 100755
index 0000000000..d423f3d9ae
--- /dev/null
+++ b/tools/check_exec.py
@@ -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 d465c687a4..9c20ee7fad 100644
--- a/tox.ini
+++ b/tox.ini
@@ -42,6 +42,7 @@ commands =
          tools/cover.sh \
          tools/check_logging.sh \
          run_tests.sh
+  {toxinidir}/tools/check_exec.py {toxinidir}/manila
   {toxinidir}/tools/check_logging.sh {toxinidir}/manila
 
 [testenv:genconfig]