@classmethod
def from_string(cls, spec):
    """create modulespec from a string.

        A module specification has one of these forms:
          modulename
          modulename:version

        version may be:
          versionname        : exactly this version
          +versionname       : this version or newer
          -versionname       : this version or older

        Here are some examples:

        >>> Spec.from_string("ALARM")
        Spec('ALARM',None,None)
        >>> Spec.from_string("ALARM:R3-2")
        Spec('ALARM','R3-2','eq')
        >>> Spec.from_string("ALARM:+R3-2")
        Spec('ALARM','R3-2','ge')
        >>> Spec.from_string("ALARM:-R3-2")
        Spec('ALARM','R3-2','le')
        """
    mode = 0
    modulename = None
    versionname = None
    versionflag = None
    for l in spec.split(':'):
        if mode == 0:
            modulename = l
            mode += 1
            continue
        if mode == 1:
            if l != '':
                if l[0] == '-':
                    versionname = l[1:]
                    versionflag = 'le'
                elif l[0] == '+':
                    versionname = l[1:]
                    versionflag = 'ge'
                else:
                    versionname = l
                    versionflag = 'eq'
            mode += 1
            continue
        raise ValueError('unexpected spec: %s' % spec)
    return cls(modulename, versionname, versionflag)
