def populate_cmdsets(job, cmdsets, depth):
    """Create list of jobsets at different depths of dependency tree.

    :param job:  Job object
    :param cmdsets:  sets of command-lines, one at each depth
    :param depth:  depth of dependencies to begin at

    This is a recursive function (is there something quicker in the itertools
    module?) that descends each 'root' job in turn, populating each
    """
    if len(cmdsets) < depth:
        cmdsets.append(set())
    if isinstance(job.command, list):  # Typical command representation
        cmdsets[depth - 1].add(" ".join(job.command))
    else:  # Command object
        cmdsets[depth - 1].add(str(job.command))
    if not job.dependencies:
        return cmdsets
    for j in job.dependencies:
        cmdsets = populate_cmdsets(j, cmdsets, depth + 1)
    return cmdsets