def get_target_ids(targetcount, targetspec):
    """Get target ids from target spec:
    * a - individual item
    * a:b - range a to b (non-inclusive), step 1
    * a:b:c - range a to b (includes a, not b), step c (where c is
    positive or negative)
    """
    targetranges = []

    for el in targetspec.split(","):
        a, b, c = 0, 1, 1
        abc = el.split(":")
        if len(abc) > 3:
            raise Exception("bad targetspec")
        if abc[0]:
            a = int(abc[0])
        if len(abc) == 1:
            b = a+1
        else:
            b = int(abc[1] or targetcount)
            if len(abc) == 3:
                c = int(abc[2])
        targetranges.append(range(a, b, c))
    return targetranges