def _format_and_validate(self, args): # Unpack args, trim and clean, repack # Get action first for clarity of code here # TODO - expunge the magic string! action = OrgmCliController._trim_quotes(args['action']) # Process all the data elements, values for fields in Elem, dynamically for elem in Elem.get_data_elems(): elem_type = Elem.get_elem_type(elem) if elem_type == Elem.LIST_TYPE: # Must split() the two list element types, so the string becomes Py list # Trim single and double quotes from each element # NOTE: _trim_quotes() keeps args not passed as None and empty strings as empty, # which is *crucial* to logic of _run_cli_get_group_elem() below args[elem] = [OrgmCliController._trim_quotes(t).strip() for t in args[elem].split(',')] elif elem_type == Elem.TEXT_TYPE: args[elem] = OrgmCliController._trim_quotes(args[elem]) # Process filename args[ActionArg.FILENAME] = OrgmCliController._trim_quotes(args[ActionArg.FILENAME]) # Validation if action == Action.ADD and not args[Elem.TITLE]: raise OrganizemIllegalUsageException("'--add' action must include '--title' element and a value for title.") elif (action == Action.SETCONF_DATA_FILE or action == Action.SETCONF_BAK_FILE) \ and not args[ActionArg.FILENAME]: raise OrganizemIllegalUsageException("'--setconf_*' actions must include '--filename' element and a value for filename.") return (action, args)
def _get_match(self, action, args): match_elem = None match_val = None if action == Action.FIND or action == Action.REMOVE: for elemkey in Elem.get_data_elems(): if elemkey in args: argval = args[elemkey] if len(argval): match_elem = elemkey match_val = argval break # Validate that we have match_elem and match_val if action requires them if match_elem is None or match_val is None: raise OrganizemIllegalUsageException("'--find and --remove must include an element (e.g. --title) and a value for that element.") return (match_elem, match_val)
def __init__(self): # This line is the whole reason for all this clumsy scaffolding -- build the group by # enums dynamically from Elem fields, so that if we add new Elements to Item # there is nothing to keep in synch here for elem in Elem.get_data_elems(): self.__setattr__(self.PFX + elem.upper(), self.PFX.lower() + elem.lower())