Skip to content
Snippets Groups Projects
Commit c10415d6 authored by Jeremy M Fee's avatar Jeremy M Fee
Browse files

Update location code argument validation

parent cd9903ab
No related branches found
No related tags found
No related merge requests found
...@@ -566,9 +566,11 @@ def parse_args(args): ...@@ -566,9 +566,11 @@ def parse_args(args):
metavar=('FROM', 'TO'), metavar=('FROM', 'TO'),
nargs=2) nargs=2)
parser.add_argument('--locationcode', parser.add_argument('--locationcode',
choices=['R0', 'R1', 'RM', 'Q0', 'D0', 'C0']) help='EDGE location code, e.g. "R0", "R1"',
type=edge.LocationCode)
parser.add_argument('--outlocationcode', parser.add_argument('--outlocationcode',
choices=['R0', 'R1', 'RM', 'Q0', 'D0', 'C0']) help='EDGE output location code (when different from --locationcode)',
type=edge.LocationCode)
parser.add_argument('--interval', parser.add_argument('--interval',
default='minute', default='minute',
choices=['hourly', 'minute', 'second']) choices=['hourly', 'minute', 'second'])
......
"""EDGE Location Code argument validation."""
import argparse
import re
def LocationCode(code):
"""EDGE Location Code argument validator.
Location Code is the last component in a channel identifier;
SNCL => Station, Network, Channel, Location Code
Parameters
----------
code : str
the code to validate
Returns
-------
str
validated lcoation code.
Raises
------
argparse.ArgumentTypeError
if the location code doesn't match the regular expression.
"""
try:
return re.match('^[A-Z0-9]{2}$', code).group(0)
except:
raise argparse.ArgumentTypeError('Invalid location code, expected /^[A-Z0-9]{2}$/')
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
""" """
from EdgeFactory import EdgeFactory from EdgeFactory import EdgeFactory
from LocationCode import LocationCode
from RawInputClient import RawInputClient from RawInputClient import RawInputClient
__all__ = [ __all__ = [
'EdgeFactory', 'EdgeFactory',
'LocationCode',
'RawInputClient' 'RawInputClient'
] ]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment