def run_in_order(l, show_output=True, show_err=True, ignore_err=False,
                 args=(), **kwargs):
    '''
    Processes each element of l in order:
        if it is a string: execute it as a shell command
        elif it is a callable, call it with *args, **kwargs

    l-->list: Each elem is either a string (shell command) or callable
              Any other type is ignored
    show_output-->boolean: Show stdout of shell commands
                           Does not affect callables
    show_err-->Boolean: Show stderr of shell commands
                        Does not affect callables
    ignore_err-->boolean: Continue after exception or shell command
                          wth return code != 0
    Returns-->Nothing

    if ignore_err == False, exceptions are re-raised, hence shown

    ------------------------------------------------------------------
    show_output show_err ignore_err   stdout stderr exception continue
                                                    trace
    ------------------------------------------------------------------
    True        True     False        SHOW   SHOW   SHOW      NO
    True        False    False        SHOW   HIDE   SHOW      NO
    False       True     False        HIDE   SHOW   SHOW      NO
    False       False    False        HIDE   HIDE   SHOW      NO

    True        True     True         SHOW   SHOW   SHOW      YES
    True        False    True         SHOW   HIDE   HIDE      YES
    False       True     True         HIDE   SHOW   SHOW      YES
    False       False    True         HIDE   HIDE   HIDE      YES
    ------------------------------------------------------------------
    ----------- DEFAULT -----------   SHOW   SHOW   SHOW      NO
    ------------------------------------------------------------------
    '''
    # Set defaults
    if show_output is None:
        show_output = True
    if show_err is None:
        show_err = True
    if ignore_err is None:
        ignore_err = False
    if args is None:
        args = ()

    for c in l:
        try:
            if isinstance(c, str):
                devnull = open(os.devnull, 'w')
                if not show_err:
                    stderr = devnull
                else:
                    stderr = None
                if not show_output:
                    stdout = devnull
                else:
                    stdout = None
                retcode = subprocess.call(
                    c, shell=True, stdout=stdout, stderr=stderr)
                if not ignore_err and retcode != 0:
                    break
            elif hasattr(c, '__call__'):
                c(*args, **kwargs)
        except:
            if not ignore_err:
                raise
            if show_err:
                sys.stderr.write(traceback.format_exc())