diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-05-08 20:27:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-08 20:27:31 +0200 |
commit | 2f2b28347b9a90953ff2419c03e8e02eab533f45 (patch) | |
tree | a5169f3fe6b53386ab93e8fefd5d4b920028506e /src/validators/script | |
parent | 2c69daf94cbe9caf177af8959936917bdc645876 (diff) | |
parent | ff58182904882278a004f4d3d8082ec11adbe1ea (diff) | |
download | vyos-1x-2f2b28347b9a90953ff2419c03e8e02eab533f45.tar.gz vyos-1x-2f2b28347b9a90953ff2419c03e8e02eab533f45.zip |
Merge pull request #395 from thomas-mangin/T2417
validator: T2417: try to make the code clearer
Diffstat (limited to 'src/validators/script')
-rwxr-xr-x | src/validators/script | 31 |
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' + ) |