def calc_time_remaining(end_time, units="s"): time_diff = end_time - datetime.now() total_time = time_diff.seconds if units == "h": total_time = int(total_time * 3600) elif units == "m": total_time = int(total_time * 60) elif units == 's': total_time = int(total_time) else: raise AttributeError("units argument must be h, m, or s") hours = int(total_time // 3600) minutes = int(total_time % 3600 // 60) seconds = int(total_time % 60) time_remaining = time_class(hours, minutes, seconds) return time_remaining
def parse_time_string(time_str): hour_regex = r"\d+(?=\sHour)" minute_regex = r"\d+(?=\sMinute*)" second_regex = r"\d+(?=\sSecond*)" hour_match = re.findall(hour_regex, time_str) minute_match = re.findall(minute_regex, time_str) second_match = re.findall(second_regex, time_str) if hour_match: hours = int(hour_match[0]) * 3600 else: hours = 0 if minute_match: minutes = int(minute_match[0]) * 60 else: minutes = 0 if second_match: seconds = int(second_match[0]) else: seconds = 0 time_obj = time_class(hours, minutes, seconds) return time_obj
def __bool_convert(x): if type(x) is bool: return x else: if x.lower() in ["y", "yes", "true", "t", "1"]: return True else: return False TYPE_COMPATIBILITY = { PARAM_STRING: ([unicode, str], [str], None), PARAM_PASSWORD: ([unicode, str], [str], None), PARAM_BOOL: ([bool], [bool], __bool_convert), PARAM_DATE: ([unicode, str], [date], lambda x: date(*[int(elem) for elem in x.split("-")])), PARAM_TIME: ([unicode, str], [time_class], lambda x: time_class(*[int(elem) for elem in x.split(":")])), PARAM_NUMBER: ([int, float], [int, float], __numstr_to_num), PARAM_URI: ([unicode, str], [str], None), } class ParameterDef(object): """ This class encapsulates a parameter definition. Parameters are defined by each individual component. Therefore, in its __init__() method each component has to create its dictionary of ParameterDef classes and make it available via the getParams() method. By default, a parameter is 'required'. Note that
"URI_TYPES": [unicode, str], } if PLATFORM == PLATFORM_JYTHON: # Now selectively add some of the Java types from java.math import BigDecimal TYPES_DICT["NUMBER_TYPES"].append(BigDecimal) TYPE_COMPATIBILITY = { PARAM_STRING: (TYPES_DICT["STRING_TYPES"], [str], None), PARAM_PASSWORD: (TYPES_DICT["PASSWORD_TYPES"], [str], None), PARAM_BOOL: (TYPES_DICT["BOOL_TYPES"], [bool], __bool_convert), PARAM_DATE: (TYPES_DICT["DATE_TYPES"], [date], lambda x: date(*[int(elem) for elem in x.split("-")])), PARAM_TIME: (TYPES_DICT["TIME_TYPES"], [time_class], lambda x: time_class(*[int(elem) for elem in x.split(":")])), PARAM_NUMBER: (TYPES_DICT["NUMBER_TYPES"], [int, float], __numstr_to_num), PARAM_URI: (TYPES_DICT["URI_TYPES"], [str], None), } class ParameterDef(object): """ This class encapsulates a parameter definition. Parameters are defined by each individual component. Therefore, in its __init__() method each component has to create its dictionary of ParameterDef classes and make it available via the getParams() method. By default, a parameter is 'required'. Note that
"URI_TYPES": [unicode, str], } if PLATFORM == PLATFORM_JYTHON: # Now selectively add some of the Java types from java.math import BigDecimal TYPES_DICT["NUMBER_TYPES"].append(BigDecimal) TYPE_COMPATIBILITY = { PARAM_STRING: (TYPES_DICT["STRING_TYPES"], [str], None), PARAM_PASSWORD: (TYPES_DICT["PASSWORD_TYPES"], [str], None), PARAM_BOOL: (TYPES_DICT["BOOL_TYPES"], [bool], __bool_convert), PARAM_DATE: (TYPES_DICT["DATE_TYPES"], [date], lambda x: date(*[int(elem) for elem in x.split("-")])), PARAM_TIME: (TYPES_DICT["TIME_TYPES"], [time_class], lambda x: time_class(*[int(elem) for elem in x.split(":")])), PARAM_NUMBER: (TYPES_DICT["NUMBER_TYPES"], [int, float], __numstr_to_num), PARAM_URI: (TYPES_DICT["URI_TYPES"], [str], None) } class ParameterDef(object): """ This class encapsulates a parameter definition. Parameters are defined by each individual component. Therefore, in its __init__() method each component has to create its dictionary of ParameterDef classes and make it available via the getParams() method. By default, a parameter is 'required'. Note that