Ejemplo n.º 1
0
def resolveHierarchicalId(objId):
    """
    Gets an object from its Id (unless it doesn't exist,
    in which case it returns None
    """

    from MaKaC.conference import ConferenceHolder

    m = re.match(r'(\w+)(?:\.(s?)(\w+))?(?:\.(\w+))?', objId)

    # If the expression doesn't match at all, return
    if not m or not m.groups()[0]:
        return None

    try:
        m = m.groups()
        conference = ConferenceHolder().getById(m[0])

        if m[1]:
            # session id specified - session or slot
            session = conference.getSessionById(m[2])

            if m[3]:
                # session slot: 1234.s12.1
                return session.getSlotById(m[3])
            else:
                # session: 1234.s12
                return session
        else:
            if m[2]:
                # second token is not a session id
                # (either contribution or subcontribution)

                contribution = conference.getContributionById(m[2])

                if m[3]:
                    # subcontribution: 1234.12.1
                    return contribution.getSubContributionById(m[3])
                else:
                    # contribution: 1234.12
                    return contribution
            else:
                # there's not second token
                # it's definitely a conference
                return conference

    except errors.MaKaCError:
        return None
Ejemplo n.º 2
0
def resolveHierarchicalId(objId):
    """
    Gets an object from its Id (unless it doesn't exist,
    in which case it returns None
    """

    from MaKaC.conference import ConferenceHolder

    m = re.match(r'(\w+)(?:\.(s?)(\w+))?(?:\.(\w+))?', objId)

    # If the expression doesn't match at all, return
    if not m or not m.groups()[0]:
        return None

    try:
        m = m.groups()
        conference = ConferenceHolder().getById(m[0])

        if m[1]:
            # session id specified - session or slot
            session = conference.getSessionById(m[2])

            if m[3]:
                # session slot: 1234.s12.1
                return session.getSlotById(m[3])
            else:
                # session: 1234.s12
                return session
        else:
            if m[2]:
                # second token is not a session id
                # (either contribution or subcontribution)

                contribution = conference.getContributionById(m[2])

                if m[3]:
                    # subcontribution: 1234.12.1
                    return contribution.getSubContributionById(m[3])
                else:
                    # contribution: 1234.12
                    return contribution
            else:
                # there's not second token
                # it's definitely a conference
                return conference

    except errors.MaKaCError:
        return None
Ejemplo n.º 3
0
def parseIndicoID(IndicoID):
    """Given an "Indico ID" of the form shown above, determine whether it is
    a conference, subcontribution etc, and return that info with the individual IDs."""

    # regular expressions to match IndicoIDs for conference, session, contribution,
    # subcontribution
    # Note: older conferences may be a string like this: a034286 instead of just a
    # number
    pConference      = re.compile('(\w*\d+)$')
    pSession         = re.compile('(\w*\d+)s(\d+)$')
    pContribution    = re.compile('(\w*\d+)c(\d+)$')
    pSubcontribution = re.compile('(\w*\d+)c(\d+)sc(\d+)$')

    # perform the matches (match searches from the beginning of the string,
    # unlike search, which matches anywhere in the string)
    mE  = pConference.match(IndicoID)
    mS  = pSession.match(IndicoID)
    mC  = pContribution.match(IndicoID)
    mSC = pSubcontribution.match(IndicoID)

    # Depending on which talk type it is, populate a dictionary containing the name of
    # the type of talk, the actual object, and the individual conference, session,
    # contribution, subcontribution IDs.
    if mSC:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'subcontribution'))
        conference = ConferenceHolder().getById(mSC.group(1))
        contribution = conference.getContributionById(mSC.group(2))
        return {'type':           'subcontribution',
                'object':         contribution.getSubContributionById(mSC.group(3)),
                'conference':     mSC.group(1),
                'session':        '',
                'contribution':   mSC.group(2),
                'subcontribution':mSC.group(3)}
    elif mS:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'session'))
        conference = ConferenceHolder().getById(mS.group(1))
        return {'type':           'session',
                'object':         conference.getSessionById(mS.group(2)),
                'conference':     mS.group(1),
                'session':        mS.group(2),
                'contribution':   '',
                'subcontribution':''}
    elif mC:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'contribution'))
        conference = ConferenceHolder().getById(mC.group(1))
        return {'type':           'contribution',
                'object':         conference.getContributionById(mC.group(2)),
                'conference':     mC.group(1),
                'session':        '',
                'contribution':   mC.group(2),
                'subcontribution':''}
    elif mE:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'conference'))
        conference = ConferenceHolder().getById(mE.group(1))
        return {'type':           'conference',
                'object':         conference,
                'conference':     mE.group(1),
                'session':        '',
                'contribution':   '',
                'subcontribution':''}
    else:
        return None
Ejemplo n.º 4
0
def parseIndicoID(IndicoID):
    """Given an "Indico ID" of the form shown above, determine whether it is
    a conference, subcontribution etc, and return that info with the individual IDs."""

    # regular expressions to match IndicoIDs for conference, session, contribution,
    # subcontribution
    # Note: older conferences may be a string like this: a034286 instead of just a
    # number
    pConference = re.compile('(\w*\d+)$')
    pSession = re.compile('(\w*\d+)s(\d+)$')
    pContribution = re.compile('(\w*\d+)c(\d+)$')
    pSubcontribution = re.compile('(\w*\d+)c(\d+)sc(\d+)$')

    # perform the matches (match searches from the beginning of the string,
    # unlike search, which matches anywhere in the string)
    mE = pConference.match(IndicoID)
    mS = pSession.match(IndicoID)
    mC = pContribution.match(IndicoID)
    mSC = pSubcontribution.match(IndicoID)

    # Depending on which talk type it is, populate a dictionary containing the name of
    # the type of talk, the actual object, and the individual conference, session,
    # contribution, subcontribution IDs.
    if mSC:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'subcontribution'))
        conference = ConferenceHolder().getById(mSC.group(1))
        contribution = conference.getContributionById(mSC.group(2))
        return {
            'type': 'subcontribution',
            'object': contribution.getSubContributionById(mSC.group(3)),
            'conference': mSC.group(1),
            'session': '',
            'contribution': mSC.group(2),
            'subcontribution': mSC.group(3)
        }
    elif mS:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'session'))
        conference = ConferenceHolder().getById(mS.group(1))
        return {
            'type': 'session',
            'object': conference.getSessionById(mS.group(2)),
            'conference': mS.group(1),
            'session': mS.group(2),
            'contribution': '',
            'subcontribution': ''
        }
    elif mC:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'contribution'))
        conference = ConferenceHolder().getById(mC.group(1))
        return {
            'type': 'contribution',
            'object': conference.getContributionById(mC.group(2)),
            'conference': mC.group(1),
            'session': '',
            'contribution': mC.group(2),
            'subcontribution': ''
        }
    elif mE:
        # Logger.get('RecMan').debug("searched %s, matched %s" % (IndicoID, 'conference'))
        conference = ConferenceHolder().getById(mE.group(1))
        return {
            'type': 'conference',
            'object': conference,
            'conference': mE.group(1),
            'session': '',
            'contribution': '',
            'subcontribution': ''
        }
    else:
        return None