summaryrefslogtreecommitdiff
path: root/src/validators/script
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-05-06 16:45:44 +0100
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-05-06 16:45:44 +0100
commit3639a5610b590a64d6d56bee81dddd252994cfe5 (patch)
treebffd67c3bc929523e99ab3ad3c11097bbffc5d8d /src/validators/script
parent142a6b99f0da5cf474f03572e1e6c2f8772c77c9 (diff)
downloadvyos-1x-3639a5610b590a64d6d56bee81dddd252994cfe5.tar.gz
vyos-1x-3639a5610b590a64d6d56bee81dddd252994cfe5.zip
validator: T2417: try to make the code clearer
Diffstat (limited to 'src/validators/script')
-rwxr-xr-xsrc/validators/script31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/validators/script b/src/validators/script
index 689296a73..2665ec1f6 100755
--- a/src/validators/script
+++ b/src/validators/script
@@ -17,7 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
-import re
import os
import sys
import shlex
@@ -25,22 +24,22 @@ import shlex
import vyos.util
-if len(sys.argv) < 2:
- print("Please specify script file to check")
- sys.exit(1)
+if __name__ == '__main__':
+ if len(sys.argv) < 2:
+ sys.exit('Please specify script file to check')
-#if the "script" is a script+ stowaway arugments, this removes the aguements
-script = shlex.split(sys.argv[1])[0]
+ # if the "script" is a script+ stowaway arguments, this removes the aguements
+ script = shlex.split(sys.argv[1])[0]
-if not os.path.exists(script):
- print("File {0} does not exist".format(script))
- sys.exit(1)
+ if not os.path.exists(script):
+ sys.exit(f'File {script} does not exist')
-if not (os.path.isfile(script) and os.access(script, os.X_OK)):
- print("File {0} is not an executable file".format(script))
- sys.exit(1)
+ if not (os.path.isfile(script) and os.access(script, os.X_OK)):
+ sys.exit('File {script} is not an executable file')
-# File outside the config dir is just a warning
-res, warning = vyos.util.file_is_persistent(script)
-if not res:
- print(warning)
+ # File outside the config dir is just a warning
+ if not vyos.util.file_is_persistent(script):
+ sys.exit(
+ 'Warning: file {path} is outside the / config directory\n'
+ 'It will not be automatically migrated to a new image on system update'
+ )