logic cleanup

This commit is contained in:
Michael James 2018-10-14 15:55:05 -06:00
parent 82ea15b5f1
commit 69aa0a28c7
3 changed files with 19 additions and 13 deletions

View file

@ -1,5 +1,4 @@
## ##
##
# #
# SOFTWARE HISTORY # SOFTWARE HISTORY
# #
@ -18,6 +17,7 @@ from dynamicserialize.dstypes.com.raytheon.uf.common.dataplugin.gfe.db.objects i
TIME_FORMAT = "%Y%m%d_%H%M" TIME_FORMAT = "%Y%m%d_%H%M"
class UsageArgumentParser(argparse.ArgumentParser): class UsageArgumentParser(argparse.ArgumentParser):
""" """
A subclass of ArgumentParser that overrides error() to print the A subclass of ArgumentParser that overrides error() to print the
@ -28,6 +28,7 @@ class UsageArgumentParser(argparse.ArgumentParser):
self.print_help() self.print_help()
sys.exit(2) sys.exit(2)
## Custom actions for ArgumentParser objects ## ## Custom actions for ArgumentParser objects ##
class StoreDatabaseIDAction(argparse.Action): class StoreDatabaseIDAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
@ -37,6 +38,7 @@ class StoreDatabaseIDAction(argparse.Action):
else: else:
parser.error("DatabaseID [" + values + "] not a valid identifier") parser.error("DatabaseID [" + values + "] not a valid identifier")
class AppendParmNameAndLevelAction(argparse.Action): class AppendParmNameAndLevelAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None): def __call__(self, parser, namespace, values, option_string=None):
tx = ParmID.parmNameAndLevel(values) tx = ParmID.parmNameAndLevel(values)
@ -49,6 +51,7 @@ class AppendParmNameAndLevelAction(argparse.Action):
else: else:
setattr(namespace, self.dest, [comp]) setattr(namespace, self.dest, [comp])
class StoreTimeAction(argparse.Action): class StoreTimeAction(argparse.Action):
""" """
argparse.Action subclass to validate GFE formatted time strings argparse.Action subclass to validate GFE formatted time strings

View file

@ -22,12 +22,7 @@ class TimeConstraints(object):
if duration == 0 and repeatInterval == 0 and startTime == 0: if duration == 0 and repeatInterval == 0 and startTime == 0:
self.valid = True; self.valid = True;
else: else:
if repeatInterval <= 0 or repeatInterval > DAY \ if self.isInvalidInterval(repeatInterval, duration, startTime):
or DAY % repeatInterval != 0 \
or repeatInterval < duration \
or startTime < 0 or startTime > DAY \
or duration < 0 or duration > DAY:
logging.warning("Bad init values for TimeConstraints: ", self); logging.warning("Bad init values for TimeConstraints: ", self);
self.valid = False; self.valid = False;
duration = 0; duration = 0;
@ -81,3 +76,14 @@ class TimeConstraints(object):
def getStartTime(self): def getStartTime(self):
return self.startTime return self.startTime
def isInvalidInterval(self, interval, duration, startTime):
if interval <= 0 or interval > DAY or interval < duration:
return False
if startTime < 0 or startTime > DAY:
return False
if duration < 0 or duration > DAY:
return False
if DAY % interval != 0:
return False
return True

View file

@ -1,6 +1,3 @@
# #
# #
# File auto-generated against equivalent DynamicSerialize Java class # File auto-generated against equivalent DynamicSerialize Java class
# and then modified post-generation to add additional features to better # and then modified post-generation to add additional features to better
# match Java implementation. # match Java implementation.
@ -20,6 +17,7 @@
# 05/26/16 2416 rjpeter Added str based constructor. # 05/26/16 2416 rjpeter Added str based constructor.
# 08/02/16 2416 tgurney Forecast time regex bug fix, # 08/02/16 2416 tgurney Forecast time regex bug fix,
# plus misc cleanup # plus misc cleanup
#
import calendar import calendar
@ -43,6 +41,7 @@ FORECAST_PATTERN_STR=r'(?:[ _]\((\d+)(?::(\d{1,2}))?\))?'
VALID_PERIOD_PATTERN_STR=r'(?:\['+ REFTIME_PATTERN_STR + '--' + REFTIME_PATTERN_STR + r'\])?' VALID_PERIOD_PATTERN_STR=r'(?:\['+ REFTIME_PATTERN_STR + '--' + REFTIME_PATTERN_STR + r'\])?'
STR_PATTERN=re.compile(REFTIME_PATTERN_STR + FORECAST_PATTERN_STR + VALID_PERIOD_PATTERN_STR) STR_PATTERN=re.compile(REFTIME_PATTERN_STR + FORECAST_PATTERN_STR + VALID_PERIOD_PATTERN_STR)
class DataTime(object): class DataTime(object):
def __init__(self, refTime=None, fcstTime=None, validPeriod=None): def __init__(self, refTime=None, fcstTime=None, validPeriod=None):
@ -89,14 +88,12 @@ class DataTime(object):
+ str(refTime)) + str(refTime))
groups = match.groups() groups = match.groups()
rDate = groups[0]
rTime = groups[1]
rMillis = groups[2] or 0 rMillis = groups[2] or 0
fcstTimeHr = groups[3] fcstTimeHr = groups[3]
fcstTimeMin = groups[4] fcstTimeMin = groups[4]
periodStart = groups[5], groups[6], (groups[7] or 0) periodStart = groups[5], groups[6], (groups[7] or 0)
periodEnd = groups[8], groups[9], (groups[10] or 0) periodEnd = groups[8], groups[9], (groups[10] or 0)
self.refTime = self._getTimeAsEpochMillis(rDate, rTime, rMillis) self.refTime = self._getTimeAsEpochMillis(groups[0], groups[1], rMillis)
if fcstTimeHr is not None: if fcstTimeHr is not None:
self.fcstTime = int(fcstTimeHr) * 3600 self.fcstTime = int(fcstTimeHr) * 3600