def x2cmdlist()

in pystemd/utils.py [0:0]


def x2cmdlist(what_to_convert, cont=False):
    """
    a really overloaded helper to convert most things into a cmd list that can be passed natevly to the Exec* family. it should

    1. for None and [] return []
    2. for a single string like "/bin/foo bar" will return as [(b"/bin/foo", (b"/bin/foo", "bar"), False)]
    3. for a list|set of strings|bytes, it should interpret that as a single command, and it should just return that as [(cmd[0], cmd, False)]
    4. for a list|set of list|set, it should interpret that as multiple command, and it should just return that as [(cmd[0], cmd, False) for each cmd]

    The last argument is what systemd uses to determine if the command can continue if failed.

    """
    if what_to_convert is None:
        return []

    if isinstance(what_to_convert, (str, bytes)):
        return [str2cmd(what_to_convert, cont)]

    if not isinstance(what_to_convert, (list, tuple)):
        return what_to_convert

    # at this point tyhis is either a list or a tuple
    if not len(what_to_convert):
        return []

    # if the first element is a string then we just woll this in a double array
    if isinstance(what_to_convert[0], (str, bytes)):
        return [strlist2cmd(what_to_convert, cont)]

    return [strlist2cmd(_, cont) for _ in what_to_convert]