Ejemplo n.º 1
0
    def indexConf(self, conf):
        """Adds an object to the index for the specified starting and ending
            dates.

           Parameters:
            conf - (Conference) Object to be indexed.
        """
        confid   = conf.getId()
        sdate = date2utctimestamp(conf.getStartDate())
        edate = date2utctimestamp(conf.getEndDate())
        #checking if 2038 problem occurs
        if sdate > BTREE_MAX_INT or edate > BTREE_MAX_INT:
            return
        if self._idxSdate.has_key( sdate ):
            res = self._idxSdate[sdate]
        else:
            res = []
        if not confid in res:
            res.append(confid)
            self._idxSdate[sdate] = res
        if self._idxEdate.has_key( edate ):
            res = self._idxEdate[edate]
        else:
            res = []
        if not confid in res:
            res.append(confid)
            self._idxEdate[edate] = res
Ejemplo n.º 2
0
    def indexConf(self, conf):
        """Adds an object to the index for the specified starting and ending
            dates.

           Parameters:
            conf - (Conference) Object to be indexed.
        """
        confid = conf.getId()
        sdate = date2utctimestamp(conf.getStartDate())
        edate = date2utctimestamp(conf.getEndDate())
        #checking if 2038 problem occurs
        if sdate > BTREE_MAX_INT or edate > BTREE_MAX_INT:
            return
        if self._idxSdate.has_key(sdate):
            res = self._idxSdate[sdate]
        else:
            res = []
        if not confid in res:
            res.append(confid)
            self._idxSdate[sdate] = res
        if self._idxEdate.has_key(edate):
            res = self._idxEdate[edate]
        else:
            res = []
        if not confid in res:
            res.append(confid)
            self._idxEdate[edate] = res
Ejemplo n.º 3
0
    def unindexConf(self, conf):
        """Removes the given object from the index for the specified starting
            and ending dates. If the object is not indexed at any of the
            2 values the operation won't be executed.

           Raises:
            Exception - the specified object is not indexed at the specified
                    dates

           Parameters:
            conf - (Conference) Object to be removed from the index.
            sdate - (datetime) Starting date at which the object is indexed.
            edate - (datetime) [optional] Ending date at which the object
                is indexed. If it is not specified the starting date will be
                used as ending one.
        """
        confid = conf.getId()
        sdate = date2utctimestamp(conf.getStartDate())
        edate = date2utctimestamp(conf.getEndDate())
        #checking if 2038 problem occurs
        if sdate > BTREE_MAX_INT or edate > BTREE_MAX_INT:
            return
        if not self._idxSdate.has_key(sdate):
            for key in self._idxSdate.keys():
                res = self._idxSdate[key]
                while confid in res:
                    res.remove(confid)
                    self._idxSdate[key] = res
                    if len(self._idxSdate[key]) == 0:
                        del self._idxSdate[key]
        else:
            while confid in self._idxSdate[sdate]:
                res = self._idxSdate[sdate]
                res.remove(confid)
                self._idxSdate[sdate] = res
            if len(self._idxSdate[sdate]) == 0:
                del self._idxSdate[sdate]
        if not self._idxEdate.has_key(edate):
            for key in self._idxEdate.keys():
                res = self._idxEdate[key]
                while confid in res:
                    res.remove(confid)
                    self._idxEdate[key] = res
                    if len(self._idxEdate[key]) == 0:
                        del self._idxEdate[key]
        else:
            while confid in self._idxEdate[edate]:
                res = self._idxEdate[edate]
                res.remove(confid)
                self._idxEdate[edate] = res
            if len(self._idxEdate[edate]) == 0:
                del self._idxEdate[edate]
Ejemplo n.º 4
0
    def unindexConf( self, conf):
        """Removes the given object from the index for the specified starting
            and ending dates. If the object is not indexed at any of the
            2 values the operation won't be executed.

           Raises:
            Exception - the specified object is not indexed at the specified
                    dates

           Parameters:
            conf - (Conference) Object to be removed from the index.
            sdate - (datetime) Starting date at which the object is indexed.
            edate - (datetime) [optional] Ending date at which the object
                is indexed. If it is not specified the starting date will be
                used as ending one.
        """
        confid = conf.getId()
        sdate = date2utctimestamp(conf.getStartDate())
        edate = date2utctimestamp(conf.getEndDate())
        #checking if 2038 problem occurs
        if sdate > BTREE_MAX_INT or edate > BTREE_MAX_INT:
            return
        if not self._idxSdate.has_key( sdate ):
            for key in self._idxSdate.keys():
                res = self._idxSdate[key]
                while confid in res:
                    res.remove(confid)
                    self._idxSdate[key] = res
                    if len(self._idxSdate[key]) == 0:
                        del self._idxSdate[key]
        else:
            while confid in self._idxSdate[sdate]:
                res = self._idxSdate[sdate]
                res.remove(confid)
                self._idxSdate[sdate] = res
            if len(self._idxSdate[sdate]) == 0:
                del self._idxSdate[sdate]
        if not self._idxEdate.has_key( edate ):
            for key in self._idxEdate.keys():
                res = self._idxEdate[key]
                while confid in res:
                    res.remove(confid)
                    self._idxEdate[key] = res
                    if len(self._idxEdate[key]) == 0:
                        del self._idxEdate[key]
        else:
            while confid in self._idxEdate[edate]:
                res = self._idxEdate[edate]
                res.remove(confid)
                self._idxEdate[edate] = res
            if len(self._idxEdate[edate]) == 0:
                del self._idxEdate[edate]
Ejemplo n.º 5
0
        def _check_index(desc, index, func):
            i = 0
            for ts, confs in index.iteritems():
                for confId in confs:
                    # it has to be in the conference holder
                    if confId not in confIdx:
                        yield "[%s][%s] '%s' not in ConferenceHolder" % (desc, ts, confId)
                    else:

                        conf = ConferenceHolder().getById(confId)
                        try:
                            expectedDate = date2utctimestamp(func(conf))
                        except OverflowError:
                            expectedDate = "overflow"

                        # ts must be ok
                        if ts != expectedDate:
                            yield "[%s][%s] Conference '%s' has bogus date (should be '%s')" % (
                                desc,
                                ts,
                                confId,
                                expectedDate,
                            )
                    if dbi and i % 100 == 99:
                        dbi.sync()
                    i += 1
Ejemplo n.º 6
0
    def _getObjectsEndingAfter(self, date):
        """Returns all the objects ending after the specified day (included).

           Parameters:
            date - (tz aware datetime) Date for which all the indexed objects ending
                after have to be fecthed and returned.
           Returns:
            (Set) - set of objects ending after the specified day
        """
        date = date2utctimestamp(date)
        res = set()
        for val in self._idxEdate.values(date):
            res.update(set(val))
        return res
Ejemplo n.º 7
0
    def _getObjectsStartingBefore(self, date):
        """Returns all the objects starting before the specified day (excluded).

           Parameters:
            date - (tz aware datetime) Date for which all the indexed objects starting
                before have to be fecthed and returned.
           Returns:
            (Set) - set of objects starting before the specified day
        """
        date = date2utctimestamp(date)
        res = set()
        for val in self._idxSdate.values(self._idxSdate.minKey(), date):
            res.update(set(val))
        return res
Ejemplo n.º 8
0
    def _getObjectsEndingAfter( self, date ):
        """Returns all the objects ending after the specified day (included).

           Parameters:
            date - (tz aware datetime) Date for which all the indexed objects ending
                after have to be fecthed and returned.
           Returns:
            (Set) - set of objects ending after the specified day
        """
        date = date2utctimestamp(date)
        res = set()
        for val in self._idxEdate.values(date):
            res.update( set( val ) )
        return res
Ejemplo n.º 9
0
    def _getObjectsStartingBefore( self, date ):
        """Returns all the objects starting before the specified day (excluded).

           Parameters:
            date - (tz aware datetime) Date for which all the indexed objects starting
                before have to be fecthed and returned.
           Returns:
            (Set) - set of objects starting before the specified day
        """
        date = date2utctimestamp(date)
        res = set()
        for val in self._idxSdate.values(self._idxSdate.minKey(), date):
            res.update( set( val ) )
        return res
Ejemplo n.º 10
0
 def indexConf(self, conf):
     """Adds an object to the index for the specified starting and ending 
         dates.
        
        Parameters:
         conf - (Conference) Object to be indexed.
     """
     confid = conf.getId()
     sdate = date2utctimestamp(conf.getStartDate())
     if self._idxSdate.has_key(sdate):
         res = self._idxSdate[sdate]
     else:
         res = []
     if not confid in res:
         res.append(confid)
         self._idxSdate[sdate] = res
     edate = date2utctimestamp(conf.getEndDate())
     if self._idxEdate.has_key(edate):
         res = self._idxEdate[edate]
     else:
         res = []
     if not confid in res:
         res.append(confid)
         self._idxEdate[edate] = res
Ejemplo n.º 11
0
 def indexConf(self, conf):
     """Adds an object to the index for the specified starting and ending 
         dates.
        
        Parameters:
         conf - (Conference) Object to be indexed.
     """
     confid   = conf.getId()
     sdate = date2utctimestamp(conf.getStartDate())
     if self._idxSdate.has_key( sdate ):
         res = self._idxSdate[sdate]
     else:
         res = []
     if not confid in res:
         res.append(confid)
         self._idxSdate[sdate] = res
     edate = date2utctimestamp(conf.getEndDate())
     if self._idxEdate.has_key( edate ):
         res = self._idxEdate[edate]
     else:
         res = []
     if not confid in res:
         res.append(confid)
         self._idxEdate[edate] = res
Ejemplo n.º 12
0
        def _check_index(desc, index, func):
            i = 0
            for ts, confs in index.iteritems():
                for confId in confs:
                    # it has to be in the conference holder
                    if confId not in confIdx:
                        yield "[%s][%s] '%s' not in ConferenceHolder" % (desc, ts, confId)
                    else:

                        conf = ConferenceHolder().getById(confId)
                        try:
                            expectedDate = date2utctimestamp(func(conf))
                        except OverflowError:
                            expectedDate = 'overflow'

                        # ts must be ok
                        if ts != expectedDate:
                            yield "[%s][%s] Conference '%s' has bogus date (should be '%s')" % (desc, ts, confId, expectedDate)
                    if dbi and i % 100 == 99:
                        dbi.sync()
                    i += 1