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/timezone | |
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/timezone')
-rwxr-xr-x | src/validators/timezone | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/validators/timezone b/src/validators/timezone index ec845e755..7e4534b57 100755 --- a/src/validators/timezone +++ b/src/validators/timezone @@ -15,25 +15,19 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import argparse - -from sys import exit +import sys from vyos.util import cmd -parser = argparse.ArgumentParser() -parser.add_argument("--validate", action="store", help="Check if timezone is valid") if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--validate", action="store", required=True, help="Check if timezone is valid") args = parser.parse_args() - if args.validate: - tz_data = cmd('find /usr/share/zoneinfo/posix -type f -or -type l | sed -e s:/usr/share/zoneinfo/posix/::') - tz_data = tz_data.split('\n') - # if timezone can't be found in list it's invalid - if args.validate not in tz_data: - exit(1) - else: - parser.print_help() - exit(1) + tz_data = cmd('find /usr/share/zoneinfo/posix -type f -or -type l | sed -e s:/usr/share/zoneinfo/posix/::') + tz_data = tz_data.split('\n') - exit(0) + if args.validate not in tz_data: + sys.exit("the timezone can't be found in the timezone list') + sys.exit() |