import re


def InputsToArgs(inputs):
  """Convert repair action input string to an args list and kwargs dict.

  Args:
    inputs: A string. A well formed input string is a comma separated
      list of values and/or equal-sign separated key value pairs.
      A valid input string may be the following:
        'arg1,arg2,...,argN,kwarg1=foo,...,kwargN=bar'

  Returns:
    A list of the positional arguments contained in the |inputs| string and
    a dictionary of the key value pairs that made up the |inputs| string.
    All keys and values will be strings.
  """
  args, kwargs = ([], {})
  if not inputs:
    return args, kwargs

  pattern = '([^,]+,)*([^,]+)$'
  if not re.match(pattern, inputs):
    raise ValueError('Action arguments are not well-formed.'
                     ' Expected: "a1,...,aN,kw1=foo,...,kwN=bar".'
                     ' Given: %s', inputs)

  for kv in inputs.split(','):
    try:
      k, v = kv.split('=')
      kwargs[k] = v
    except ValueError:
      args.append(kv)

  return args, kwargs