summaryrefslogtreecommitdiff
path: root/src/validators/timezone
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/timezone
parent142a6b99f0da5cf474f03572e1e6c2f8772c77c9 (diff)
downloadvyos-1x-3639a5610b590a64d6d56bee81dddd252994cfe5.tar.gz
vyos-1x-3639a5610b590a64d6d56bee81dddd252994cfe5.zip
validator: T2417: try to make the code clearer
Diffstat (limited to 'src/validators/timezone')
-rwxr-xr-xsrc/validators/timezone22
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()