Esempio n. 1
0
class EventLog(Persistent):
    """An EventLog encapsulates a collection of log entries."""

    def __init__(self):
        self._data = IOBTree()

    security = ClassSecurityInfo()

    security.declarePrivate('addEntry')
    def addEntry(self, entry):
        """Add a new log entry."""
        if len(self._data):
            key = self._data.minKey() - 1
        else:
            key = MAX32
        self._data[key] = entry

    security.declarePrivate('getEntries')
    def getEntries(self):
        """Return a sequence of log entries."""
        return self._data.values()

    def __len__(self):
        return len(self._data)

    def __nonzero__(self):
        return len(self._data) > 0
Esempio n. 2
0
 def clear(self):
     """ See IPluggableIndex.
     """
     self._depth = 0
     self._index = OOBTree()
     self._unindex = IOBTree()
     self._length = Length(0)
Esempio n. 3
0
    def addEdge(self, start, end, edgetype, **kwargs):
        _id = self.edgeid()

        if type(edgetype) != int:
            edgetype = self.typeid(edgetype)

        if type(start) == dict:
            start = start['_id']
        if type(end) == dict:
            end = end['_id']

        edge = [start, end, edgetype]
        self.edges[_id] = edge

        if kwargs:
            self.edgedata[_id] = kwargs
            le = self.lightEdge(_id, edge)
            self.edge_catalog.index_doc(_id, le)

        le = self.lightEdge(_id, edge)
        # edgeid:nodeid
        data = self.outgoing.setdefault(edgetype,
                                        IOBTree()).setdefault(start, {})
        data[_id] = end
        self.outgoing[edgetype][start] = data

        data = self.incoming.setdefault(edgetype,
                                        IOBTree()).setdefault(end, {})
        data[_id] = start
        self.incoming[edgetype][end] = data

        return le
Esempio n. 4
0
 def __init__(self):
     """Setup our data structures"""
     self._anon_ratings = IOBTree()
     self._ratings = OOBTree()
     self._sessions = OOBTree()
     self._length = Length()
     self._anon_length = Length()
    def _convertBTrees(self, threshold=200):

        if type(self._lexicon) is type(''):
            # Turn the name reference into a hard reference.
            self._lexicon=self.getLexicon()

        if type(self._index) is IOBTree: return

        from BTrees.convert import convert

        _index=self._index
        self._index=IOBTree()

        def convertScores(scores,
                          type=type, TupleType=TupleType, IIBTree=IIBTree
                          ):
            if type(scores) is not TupleType and type(scores) is not IIBTree():
                scores=IIBTree(scores)
            return scores

        convert(_index, self._index, threshold, convertScores)

        _unindex=self._unindex
        self._unindex=IOBTree()
        convert(_unindex, self._unindex, threshold)
Esempio n. 6
0
    def __getitem__(self, item):
        if isinstance(item, slice):
            _slice = self._reslice(item)
            return (
                IOBTree.__getitem__(self, index)
                for index in range(
                    _slice.start, min(len(self), _slice.stop), _slice.step
                )
            )

        elif isinstance(item, int):
            if item >= len(self):
                raise IndexError

            try:
                if not item:
                    return IOBTree.__getitem__(self, 0)
                return IOBTree.__getitem__(self, item > 0 and item or len(self) + item)
            except KeyError as ex:
                raise IndexError(ex)

        else:
            raise TypeError(
                f"Invalid LargeList key '{item}'. It must be an integer or a slice."
            )
Esempio n. 7
0
 def clear(self):
     self.data = IOBTree()  # {rid -> record as tuple}
     self.indexes = {}  # {index_name -> OOBTree({value -> IITreeSet})}
     self.primary_index = OIBTree()  # {primary key -> rid}
     for position, column in self.col_info:
         if column.indexed:
             self.indexes[column.name] = OOBTree()
Esempio n. 8
0
 def clear(self):
     """Empty the lexicon.
     """
     self.length = Length()
     self._wid_length_based = False
     self._wids = OIBTree()  # word -> wid
     self._words = IOBTree()  # wid -> word
 def clear(self):
     """Reinitialize the text index."""
     self._index   = IOBTree()
     self._unindex = IOBTree()
     if self.getLexicon() and self.vocabulary_id=='__userdefined__':
         self.getLexicon().clear()
     self._lexicon = None
Esempio n. 10
0
    def __init__(self):
        super(ContentTypeScopeManager, self).__init__()
        self._mappings = IOBTree()

        # Methods permitted to access this mapping with.  Originally
        # I wanted to provide alternative sets of mapping on a per
        # mapping_id basis, however this proved to be complex and
        # complicated due to extra relationships involved.
        self._methods = IOBTree()

        # For metadata related to the above.
        self._mappings_metadata = IOBTree()

        # To ease the usage of scopes, the mappings are referenced by
        # names and are called profiles which add a few useful fields to
        # allow slightly easier usage.  This separates the name from the
        # already active tokens such that once a token is instantiated
        # with a scope, the mapping is stuck until the token is revoked.
        self._named_mappings = OIBTree()  # name to id.

        # To not overburden the named mappings with work-in-progress
        # profiles, instantiate one here also.
        self._edit_mappings = OOBTree()

        self.default_mapping_id = self.addMapping({})
Esempio n. 11
0
    def _convertBTrees(self, threshold=200):

        if type(self._lexicon) is type(''):
            # Turn the name reference into a hard reference.
            self._lexicon = self.getLexicon()

        if type(self._index) is IOBTree: return

        from BTrees.convert import convert

        _index = self._index
        self._index = IOBTree()

        def convertScores(scores,
                          type=type,
                          TupleType=TupleType,
                          IIBTree=IIBTree):
            if type(scores) is not TupleType and type(scores) is not IIBTree():
                scores = IIBTree(scores)
            return scores

        convert(_index, self._index, threshold, convertScores)

        _unindex = self._unindex
        self._unindex = IOBTree()
        convert(_unindex, self._unindex, threshold)
Esempio n. 12
0
 def clear(self):
     """Reinitialize the text index."""
     self._index = IOBTree()
     self._unindex = IOBTree()
     if self.getLexicon() and self.vocabulary_id == '__userdefined__':
         self.getLexicon().clear()
     self._lexicon = None
Esempio n. 13
0
    def reset(self):
        # wid -> {docid -> weight}; t -> D -> w(D, t)
        # Different indexers have different notions of term weight, but we
        # expect each indexer to use ._wordinfo to map wids to its notion
        # of a docid-to-weight map.
        # There are two kinds of OOV words:  wid 0 is explicitly OOV,
        # and it's possible that the lexicon will return a non-zero wid
        # for a word we don't currently know about.  For example, if we
        # unindex the last doc containing a particular word, that wid
        # remains in the lexicon, but is no longer in our _wordinfo map;
        # lexicons can also be shared across indices, and some other index
        # may introduce a lexicon word we've never seen.
        # A word is in-vocabulary for this index if and only if
        # wid in _wordinfo.  Note that wid 0 must not be a key.
        # This does not use the BTree family since wids are always "I"
        # flavor trees.
        self._wordinfo = IOBTree()

        # docid -> weight
        # Different indexers have different notions of doc weight, but we
        # expect each indexer to use ._docweight to map docids to its
        # notion of what a doc weight is.
        self._docweight = self.family.IF.BTree()

        # docid -> WidCode'd list of wids
        # Used for un-indexing, and for phrase search.
        self._docwords = self.family.IO.BTree()

        # Use a BTree length for efficient length computation w/o conflicts
        self.word_count = Length.Length()
        self.indexed_count = Length.Length()
Esempio n. 14
0
    def __init__(self, lexicon):
        self._lexicon = lexicon

        # wid -> {docid -> weight}; t -> D -> w(D, t)
        # Different indexers have different notions of term weight, but we
        # expect each indexer to use ._wordinfo to map wids to its notion
        # of a docid-to-weight map.
        # There are two kinds of OOV words:  wid 0 is explicitly OOV,
        # and it's possible that the lexicon will return a non-zero wid
        # for a word we don't currently know about.  For example, if we
        # unindex the last doc containing a particular word, that wid
        # remains in the lexicon, but is no longer in our _wordinfo map;
        # lexicons can also be shared across indices, and some other index
        # may introduce a lexicon word we've never seen.
        # A word is in-vocabulary for this index if and only if
        # _wordinfo.has_key(wid).  Note that wid 0 must not be a key.
        self._wordinfo = IOBTree()

        # docid -> weight
        # Different indexers have different notions of doc weight, but we
        # expect each indexer to use ._docweight to map docids to its
        # notion of what a doc weight is.
        self._docweight = IIBTree()

        # docid -> WidCode'd list of wids
        # Used for un-indexing, and for phrase search.
        self._docwords = IOBTree()

        # Use a BTree length for efficient length computation w/o conflicts
        self.length = BTrees.Length.Length()
Esempio n. 15
0
 def __init__(self, id=None, **kwargs):
     super(TracListing, self).__init__(id, **kwargs)
     # manage an index of parent-to-child, int parent ticket id key
     # to PersistentList of int ticket id value:
     self._children = IOBTree()
     # indexes for score and reward-ratio values:
     self._scores = IIBTree()  # int (ticket#) -> int (sum/score)
     self._reward = IOBTree()  # int (ticket#) -> float (ratio)
Esempio n. 16
0
 def __init__(self, id=None, **kwargs):
     super(TracListing, self).__init__(id, **kwargs)
     # manage an index of parent-to-child, int parent ticket id key
     # to PersistentList of int ticket id value:
     self._children = IOBTree()
     # indexes for score and reward-ratio values:
     self._scores = IIBTree()  # int (ticket#) -> int (sum/score)
     self._reward = IOBTree()  # int (ticket#) -> float (ratio)
Esempio n. 17
0
 def __init__(self):
     self.timeouts = IOBTree()
     self.locks = OOBTree()
     if self.__class__ is LockStorage:
         raise TypeError(
             "%s.LockStorage is insane; use a persistent subclass instead"
             " (%s.PersistentLockStorage should do nicely)"
             % (__name__, __name__))
Esempio n. 18
0
 def clear(self):
     """Empty the index"""
     self._length = Length()
     self._end2uid = OOBTree()
     self._start2uid = OOBTree()
     self._uid2end = IOBTree()  # Contains the index used in _end2uid
     self._uid2duration = IOBTree()  # Contains the duration
     self._uid2start = IOBTree()
     self._uid2recurrence = IOBTree()
Esempio n. 19
0
def initializeRoomBookingDB(location, force=False):
    """
    Modifies Indico main database.
    - location list

    Creates necessary branches in room booking database.
    - rooms branch
    - bookings branch
    - several indexes
    """
    indicoRoot = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
    root = DALManagerCERN().getRoot()
    # 1. Location -----------------------------------------------------------

    initialLocation = Location(location, FactoryCERN)
    if force or not indicoRoot.has_key('RoomBookingLocationList'):
        indicoRoot['RoomBookingLocationList'] = [initialLocation]
    if force or not indicoRoot.has_key('DefaultRoomBookingLocation'):
        indicoRoot['DefaultRoomBookingLocation'] = location

    # 2. Rooms & Bookings ---------------------------------------------------

    # Create rooms branch
    if force or not root.has_key('Rooms'):
        root['Rooms'] = IOBTree()

    # Create reservations branch
    if force or not root.has_key('Reservations'):
        root['Reservations'] = IOBTree()

    # Create blocking branch
    if force or not root.has_key('RoomBlocking'):
        root['RoomBlocking'] = OOBTree()
        root['RoomBlocking']['Blockings'] = IOBTree()
        root['RoomBlocking']['Indexes'] = OOBTree()
        root['RoomBlocking']['Indexes']['OwnerBlockings'] = OOBTree()
        root['RoomBlocking']['Indexes']['DayBlockings'] = CalendarDayIndex()
        root['RoomBlocking']['Indexes']['RoomBlockings'] = OOBTree()

    # Create indexes
    if force or not root.has_key('RoomReservationsIndex'):
        root['RoomReservationsIndex'] = OOBTree()
    if force or not root.has_key('UserReservationsIndex'):
        root['UserReservationsIndex'] = OOBTree()
    if force or not root.has_key('DayReservationsIndex'):
        root['DayReservationsIndex'] = OOBTree()
    if force or not root.has_key('RoomDayReservationsIndex'):
        root['RoomDayReservationsIndex'] = OOBTree()

    # Create possible equipment branch
    if force or not root.has_key('EquipmentList'):
        root['EquipmentList'] = {}

    # update Catalog with new rb indexes
    Catalog.updateDB()

    DALManagerCERN().commit()
 def clear(self):
     """Start over fresh."""
     self._always = IITreeSet()
     self._since_only = IOBTree()
     self._until_only = IOBTree()
     self._since = IOBTree()
     self._until = IOBTree()
     self._unindex = IOBTree()  # 'datum' will be a tuple of date ints
     self._length = Length()
Esempio n. 21
0
    def clear(self):
        self._length = Length()
        self._index = OOBTree()
        self._unindex = IOBTree()

        if self._counter is None:
            self._counter = Length()
        else:
            self._increment_counter()
Esempio n. 22
0
 def clear(self):
     """Start over fresh."""
     self._always = IITreeSet()
     self._since_only = IOBTree()
     self._until_only = IOBTree()
     self._since = IOBTree()
     self._until = IOBTree()
     self._unindex = IOBTree()  # 'datum' will be a tuple of date ints
     self._length = Length()
Esempio n. 23
0
 def __init__(self, storage, db=None, scan_interval=10):
     self.storage = storage
     self.db = db
     self.next_conn_id = 1
     self.conn_oids = IOBTree()  # IOBTree({ conn_id -> OOSet([oid]) } })
     self.oids = OOSet()  # OOSet([oid])
     self.lock = allocate_lock()
     self.scan_interval = scan_interval
     self.next_scan = time() + scan_interval
Esempio n. 24
0
class BranchInfo(Implicit, Persistent):
    """A utility class to hold branch (line-of-descent) information. It
       maintains the name of the branch, the version id of the root of
       the branch and indices to allow for efficient lookups."""

    security = ClassSecurityInfo()

    def __init__(self, name, root):
        # m_order maintains a newest-first mapping of int -> version id.
        # m_date maintains a mapping of a packed date (int # of minutes
        # since the epoch) to a lookup key in m_order. The two structures
        # are separate because we only support minute precision for date
        # lookups (and multiple versions could be added in a minute).
        self.date_created = time.time()
        self.m_order = IOBTree()
        self.m_date = IIBTree()
        self.name = name
        self.root = root

    security.declarePublic('getId')

    def getId(self):
        """Return the name of the object as string."""
        return self.name

    security.declarePrivate('append')

    def append(self, version):
        """Append a version to the branch information. Note that this
           does not store the actual version, but metadata about the
           version to support ordering and date lookups."""
        if len(self.m_order):
            key = self.m_order.minKey() - 1
        else:
            key = MAX32
        self.m_order[key] = version.id
        timestamp = int(version.date_created / 60.0)
        self.m_date[timestamp] = key

    security.declarePrivate('versionIds')

    def versionIds(self):
        """Return a newest-first sequence of version ids in the branch."""
        return self.m_order.values()

    security.declarePrivate('latest')

    def latest(self):
        """Return the version id of the latest version in the branch."""
        mapping = self.m_order
        if not len(mapping):
            return self.root
        return mapping[mapping.keys()[0]]

    def __len__(self):
        return len(self.m_order)
Esempio n. 25
0
 def __init__(self, *pipeline):
     self._wids = OIBTree()  # word -> wid
     self._words = IOBTree() # wid -> word
     # wid 0 is reserved for words that aren't in the lexicon (OOV -- out
     # of vocabulary).  This can happen, e.g., if a query contains a word
     # we never saw before, and that isn't a known stopword (or otherwise
     # filtered out).  Returning a special wid value for OOV words is a
     # way to let clients know when an OOV word appears.
     self.wordCount = Length()
     self._pipeline = pipeline
Esempio n. 26
0
 def __init__(self):
     self.bookings = OOBTree()
     # we need real randomness for object keys
     # but we cannot use the same uid for zope.catalog ids
     # because it does not support 128bit integers
     # (and we do not like to use zope.intid).
     # So, we use different keys for storage and catalog
     # and we store mapping between them here.
     self.mapping = IOBTree()
     self.catalog = setup_catalog()
Esempio n. 27
0
 def sync(self):
     adapter = self._adapter()
     self._children = IOBTree()  # reset all parent/child refs
     q = 'status!=closed'
     for number in adapter.select(q):
         if str(number) not in self.objectIds():
             if number in (self.visible_tickets or []):
                 self._add(number, adapter)
         else:
             self.get(str(number)).sync()
Esempio n. 28
0
    def clear(self):
        """ clear catalog """

        self.data = IOBTree()  # mapping of rid to meta_data
        self.uids = OIBTree()  # mapping of uid to rid
        self.paths = IOBTree()  # mapping of rid to uid
        self._length = BTrees.Length.Length()

        for index in self.indexes.keys():
            self.getIndex(index).clear()
Esempio n. 29
0
def initializeRoomBookingDB(location, force=False):
    """
    Modifies Indico main database.
    - location list

    Creates necessary branches in room booking database.
    - rooms branch
    - bookings branch
    - several indexes
    """
    indicoRoot = MaKaC.common.DBMgr.getInstance().getDBConnection().root()
    root = DALManagerCERN().root

    # 1. Location -----------------------------------------------------------

    initialLocation = Location(location, FactoryCERN)
    if force or not indicoRoot.has_key('RoomBookingLocationList'):
        indicoRoot['RoomBookingLocationList'] = [initialLocation]
        print "Locations branch created (Indico db)"
    if force or not indicoRoot.has_key('DefaultRoomBookingLocation'):
        indicoRoot['DefaultRoomBookingLocation'] = location
        print "Default location set to " + location

    # 2. Rooms & Bookings ---------------------------------------------------

    # Create rooms branch
    if force or not root.has_key('Rooms'):
        root['Rooms'] = IOBTree()
        print "Rooms branch created"

    # Create reservations branch
    if force or not root.has_key('Reservations'):
        root['Reservations'] = IOBTree()
        print "Reservations branch created"

    # Create indexes
    if force or not root.has_key('RoomReservationsIndex'):
        root['RoomReservationsIndex'] = OOBTree()
        print "Room => Reservations Index branch created"
    if force or not root.has_key('UserReservationsIndex'):
        root['UserReservationsIndex'] = OOBTree()
        print "User => Reservations Index branch created"
    if force or not root.has_key('DayReservationsIndex'):
        root['DayReservationsIndex'] = OOBTree()
        print "Day => Reservations Index branch created"

    # Create possible equipment branch
    if force or not root.has_key('EquipmentList'):
        root['EquipmentList'] = {}
        print "Equipment branch created"

    AvatarHolder().invalidateRoomManagerIdList()
    print "Cached list of room managers invalidated"

    DALManagerCERN().commit()
Esempio n. 30
0
 def __init__(self, name, root):
     # m_order maintains a newest-first mapping of int -> version id.
     # m_date maintains a mapping of a packed date (int # of minutes
     # since the epoch) to a lookup key in m_order. The two structures
     # are separate because we only support minute precision for date
     # lookups (and multiple versions could be added in a minute).
     self.date_created = time.time()
     self.m_order = IOBTree()
     self.m_date = IIBTree()
     self.name = name
     self.root = root
Esempio n. 31
0
class BranchInfo(Implicit, Persistent):
    """A utility class to hold branch (line-of-descent) information. It
       maintains the name of the branch, the version id of the root of
       the branch and indices to allow for efficient lookups."""

    security = ClassSecurityInfo()

    def __init__(self, name, root):
        # m_order maintains a newest-first mapping of int -> version id.
        # m_date maintains a mapping of a packed date (int # of minutes
        # since the epoch) to a lookup key in m_order. The two structures
        # are separate because we only support minute precision for date
        # lookups (and multiple versions could be added in a minute).
        self.date_created = time.time()
        self.m_order = IOBTree()
        self.m_date = IIBTree()
        self.name = name
        self.root = root

    security.declarePublic('getId')
    def getId(self):
        """Return the name of the object as string."""
        return self.name

    security.declarePrivate('append')
    def append(self, version):
        """Append a version to the branch information. Note that this
           does not store the actual version, but metadata about the
           version to support ordering and date lookups."""
        if len(self.m_order):
            key = self.m_order.minKey() - 1
        else:
            key = MAX32
        self.m_order[key] = version.id
        timestamp = int(version.date_created / 60.0)
        self.m_date[timestamp] = key

    security.declarePrivate('versionIds')
    def versionIds(self):
        """Return a newest-first sequence of version ids in the branch."""
        return self.m_order.values()

    security.declarePrivate('latest')
    def latest(self):
        """Return the version id of the latest version in the branch."""
        mapping = self.m_order
        if not len(mapping):
            return self.root
        return mapping[mapping.keys()[0]]

    def __len__(self):
        return len(self.m_order)
Esempio n. 32
0
 def clear(self):
     """Start over fresh."""
     self._always = IITreeSet()
     self._since_only = IOBTree()
     self._until_only = IOBTree()
     self._since = IOBTree()
     self._until = IOBTree()
     self._unindex = IOBTree()  # 'datum' will be a tuple of date ints
     self._length = Length()
     if self._counter is None:
         self._counter = Length()
     else:
         self._increment_counter()
 def clear(self):
     """Start over fresh."""
     self._always = IITreeSet()
     self._since_only = IOBTree()
     self._until_only = IOBTree()
     self._since = IOBTree()
     self._until = IOBTree()
     self._unindex = IOBTree()  # 'datum' will be a tuple of date ints
     self._length = Length()
     if self._counter is None:
         self._counter = Length()
     else:
         self._increment_counter()
Esempio n. 34
0
    def _init(self):
        self.nodes = IOBTree()
        self.edges = IOBTree()
        self.edgedata = IOBTree()

        self.outgoing = IOBTree()
        self.incoming = IOBTree()

        self.typeids = PObject()

        self._nodeid = Length(0)
        self._edgeid = Length(0)
        self._typeid = Length(0)
Esempio n. 35
0
    def _init(self):
        self.nodes = IOBTree()
        self.edges = IOBTree()
        self.edgedata = IOBTree()

        self.outgoing = IOBTree()
        self.incoming = IOBTree()

        self.typeids = PObject()

        self._nodeid = Length(0)
        self._edgeid = Length(0)
        self._typeid = Length(0)
 def __init__(self):
     curdir = os.path.abspath(os.path.dirname(__file__))
     db_file = os.path.join(curdir, 'OData.db')
     storage = FileStorage.FileStorage(db_file)
     db = DB(storage)
     conn = db.open()
     self.dbroot = conn.root()
     if 'zcalibdb' not in self.dbroot:
         self.dbroot['zcalibdb'] = OOBTree()
         zcalibdb = self.dbroot['zcalibdb']
         zcalibdb['members'] = IOBTree()
         zcalibdb['books'] = IOBTree()
         zcalibdb['circulations'] = IOBTree()
         self.commit()
Esempio n. 37
0
class OrderFormStorage(Persistent):
    implements(IOrderFormStorage)

    def __init__(self):
        self.storage = IOBTree()
        self.indeces = OOBTree()

    def getData(self, min_timestamp=None, max_timestamp=None):
        if min_timestamp and max_timestamp:
            indeces = self.indeces['timestamp'].keys(
                min=min_timestamp,
                max=max_timestamp
            )
        else:
            indeces = []

        result = []
        for i in indeces or self.storage.keys():
            data = self.storage[i]
            data.update({'id': i})

            result.append(data)

        return result

    def addToIndex(self, index, key, value):
        if index not in self.indeces:
            self.indeces[index] = OOBTree()

        self.indeces[index][key] = value

    def addOrder(self, order, title='', uid=''):
        if len(self.storage) == 0:
            new_key = 0
        else:
            new_key = self.storage.maxKey()
            new_key += 1

        new_dict = {}

        for key in order.keys():
            new_dict[key] = order[key]

        new_dict['timestamp'] = DateTime()
        new_dict['title'] = title
        new_dict['uid'] = uid

        self.storage[new_key] = new_dict

        self.addToIndex('timestamp', new_key, new_dict['timestamp'])
Esempio n. 38
0
 def createEvent(self,
                 obj,
                 date,
                 eventType=None,
                 eventSpan=None,
                 handleEventSpan=True):
     '''Create a new event in the calendar, at some p_date (day).
        If p_eventType is given, it is used; else, rq['eventType'] is used.
        If p_handleEventSpan is True, we will use p_eventSpan (or
        rq["eventSpan"] if p_eventSpan is not given) and also
        create the same event for successive days.'''
     obj = obj.o  # Ensure p_obj is not a wrapper.
     rq = obj.REQUEST
     # Get values from parameters
     if not eventType: eventType = rq['eventType']
     if handleEventSpan and not eventSpan:
         eventSpan = rq.get('eventSpan', None)
     # Split the p_date into separate parts
     year, month, day = date.year(), date.month(), date.day()
     # Check that the "preferences" dict exists or not.
     if not hasattr(obj.aq_base, self.name):
         # 1st level: create a IOBTree whose keys are years.
         setattr(obj, self.name, IOBTree())
     yearsDict = getattr(obj, self.name)
     # Get the sub-dict storing months for a given year
     if year in yearsDict:
         monthsDict = yearsDict[year]
     else:
         yearsDict[year] = monthsDict = IOBTree()
     # Get the sub-dict storing days of a given month
     if month in monthsDict:
         daysDict = monthsDict[month]
     else:
         monthsDict[month] = daysDict = IOBTree()
     # Get the list of events for a given day
     if day in daysDict:
         events = daysDict[day]
     else:
         daysDict[day] = events = PersistentList()
     # Create and store the event, excepted if an event already exists.
     if not events:
         event = Object(eventType=eventType)
         events.append(event)
     # Span the event on the successive days if required
     if handleEventSpan and eventSpan:
         nbOfDays = min(int(eventSpan), self.maxEventLength)
         for i in range(nbOfDays):
             date = date + 1
             self.createEvent(obj, date, handleEventSpan=False)
Esempio n. 39
0
 def _mapFromParams(self, params):
     self._normaliseAuthorParams(params)
     self._primaryAuthors = IOBTree()
     self._secondaryAuthors = IOBTree()
     maxId = -1
     for idx in range(len(params["auth_id"])):
         id = int(params["auth_id"][idx])
         if id > maxId:
             maxId = id
         author = self._getAuthorFromParams(idx, params)
         if author["auth_primary"]:
             self._primaryAuthors[id] = author
         else:
             self._secondaryAuthors[id] = author
     self._nextId = maxId + 1
Esempio n. 40
0
 def _mapFromParams( self, params ):
     self._normaliseAuthorParams( params )
     self._primaryAuthors = IOBTree()
     self._secondaryAuthors = IOBTree()
     maxId = -1
     for idx in range( len( params["auth_id"] ) ):
         id = int( params["auth_id"][idx] )
         if id>maxId:
             maxId = id
         author = self._getAuthorFromParams( idx, params )
         if author["auth_primary"]:
             self._primaryAuthors[ id ] = author
         else:
             self._secondaryAuthors[ id ] = author
     self._nextId = maxId+1
Esempio n. 41
0
    def insert(self, idx, results, relnames=None, treePrefix=None):
        for brain in results:
            rid = brain.getRID()
            path = brain.getPath()
            if treePrefix and not path.startswith(treePrefix):
                paths = brain.global_catalog._catalog.indexes['path']._unindex[
                    rid]
                for p in paths:
                    if p.startswith(treePrefix):
                        path = p
                        break
            else:
                paths = [path]

            for path in paths:
                path = path.split('/', 3)[-1]
                if relnames:
                    if isinstance(relnames, basestring):
                        relnames = (relnames, )
                    for relname in relnames:
                        path = path.replace('/' + relname, '')
                if rid:  # TODO review this I just did it to avoid exception
                    self._brains[rid] = brain
                    for depth in xrange(path.count('/') + 1):
                        comp = idx.setdefault(path, IOBTree())
                        comp.setdefault(depth, []).append(rid)
                        path = path.rsplit('/', 1)[0]
Esempio n. 42
0
 def clear(self):
     """ See IPluggableIndex.
     """
     self._depth = 0
     self._index = OOBTree()
     self._unindex = IOBTree()
     self._length = Length(0)
Esempio n. 43
0
    def __init__(self):

        PersistentMapping.__init__(self)

        self.blogs = IOBTree()
        self.categories = Categories()
        self.tags = Tags()
Esempio n. 44
0
 def __init__(self):
     """Setup our data structures"""
     self._anon_ratings = IOBTree()
     self._ratings = OOBTree()
     self._sessions = OOBTree()
     self._length = Length()
     self._anon_length = Length()
Esempio n. 45
0
 def __init__(self):
     ouiPath = os.getenv("ICT_OUI_PATH")
     if ouiPath is not None:
         f = open(ouiPath, "r") #oui: http://standards.ieee.org/regauth/oui/oui.txt
     else:
         f = open("src/org/ict_ok/libs/oui.txt", "r") #oui: http://standards.ieee.org/regauth/oui/oui.txt
     self._data = IOBTree()
     last_mac = None
     EOF = False
     re_mac = re.compile(r"[A-F0-9]*\-[A-F0-9]*\-[A-F0-9]*")
     while not EOF:
         line = f.readline()
         if re.match(re_mac, line):
             last_mac = int(line[:8].replace("-", ""), 16)
             index = line.rfind("\t")+len("\t")
             org = line[index:].strip()
             self._data[last_mac] = {"short": org, "other":[]}
         elif last_mac != None:
             index = line.rfind("\t")
             if index != -1:
                 index += len("\t")
                 other = line[index:].strip()
                 self._data[last_mac]["other"].append(other)
             if (line == "\n"):
                 country_index = len(self._data[last_mac]["other"])-1 #last element
                 self._data[last_mac]["country"] = self._data[last_mac]["other"][country_index]
                 del self._data[last_mac]["other"][country_index]
         if line == '':
             EOF=True
     f.close()
Esempio n. 46
0
    def __init__(self, principalId):
        self.index = OIBTree()
        self.messages = IOBTree()
        self.services = OOBTree()
        self.readstatus = IITreeSet()
        self.principalId = principalId

        self._next = Length(1)
    def _clear_and_rebuild(self, ids=[]):
        """
        """
        self._positionId = IOBTree()
        self._idPosition = OIBTree()

        for id in ids:
            self.addObject(id)
Esempio n. 48
0
 def clear(self):
     self._nextid      = BTrees.Length.Length()
     self._forward_idx = OIBTree()
     self._inverse_idx = IOBTree()
     if self.truncate_left:
         self._lforward_idx = OIBTree()
     else:
         self._lforward_idx = None
Esempio n. 49
0
    def __init__(self, id=None):
        super(LinkCheckTool, self).__init__(id)

        # This is the work queue; items in this queue are scheduled
        # for link validity check.
        self.queue = CompositeQueue()

        # This is the link database. It maps a hyperlink index to a
        # tuple (timestamp, status, referers).
        self.checked = IOBTree()

        # Indexes
        self.index = OIBTree()
        self.links = IOBTree()

        # This is a counter that allows us to add new hyperlinks and
        # provide an indexc quickly.
        self.counter = 0
Esempio n. 50
0
 def __init__(self, storage, db=None, scan_interval=10):
     self.storage = storage
     self.db = db
     self.next_conn_id = 1
     self.conn_oids = IOBTree()   # IOBTree({ conn_id -> OOSet([oid]) } })
     self.oids = OOSet()          # OOSet([oid])
     self.lock = allocate_lock()
     self.scan_interval = scan_interval
     self.next_scan = time() + scan_interval
Esempio n. 51
0
class ActionLogger(Persistent):
    """ ``IActionLogItem`` container. This is used in `Products.Naaya.NySite`
    site manager."""

    interface.implements(IActionLogger)

    def __init__(self):
        super(ActionLogger, self).__init__()
        self.container = IOBTree()

    def append(self, log):
        """ Add an ``IActionLog``"""

        assert IActionLogItem in interface.providedBy(log), "%s must implementation of IActionLogItem" % log
        try:
            new_id = self.container.maxKey() + 1
        except ValueError:
            new_id = 1
        self.container[new_id] = log
        return new_id

    def create(self, **kw):
        """ Convenience function """

        log = ActionLogItem(**kw)
        return self.append(log)

    def items(self, type=None):
        """ Return container items filtered by type"""
        if type is None:
            return self.container.items()
        return filter(lambda (log_id, log): log.type == type, self.container.items())

    def __iter__(self):
        return self.container.iteritems()

    def __getitem__(self, key):
        return self.container[key]

    def __delitem__(self, key):
        del self.container[key]

    def __len__(self):
        return len(self.container)
Esempio n. 52
0
    def __init__( self, conference):
        """ Constructor.
            conference must be a Conference object (not an id).
        """
        self._conference = conference
        self._contribution_index = IOBTree()

        #lists of users with reviewing roles
        self._reviewersList = []
        self._editorsList = []
        self._refereesList = []
        self._paperReviewManagersList = []

        self.setChoice(self.NO_REVIEWING) #initial reviewing mode: no reviewing

        #default dates
        self._startSubmissionDate = None
        self._endSubmissionDate = None
        self._defaultRefereeDueDate = None
        self._defaultEditorDueDate = None
        self._defaultReviwerDueDate = None

        #auto e-mails
        self._enablePRMEmailNotif = True
        self._enableRefereeEmailNotif = False
        self._enableEditorEmailNotif = False
        self._enableReviewerEmailNotif = False
        self._enableRefereeEmailNotifForContribution = False
        self._enableEditorEmailNotifForContribution = False
        self._enableReviewerEmailNotifForContribution = False
        self._enableRefereeJudgementEmailNotif = False
        self._enableEditorJudgementEmailNotif = False
        self._enableReviewerJudgementEmailNotif = False
        self._enableAuthorSubmittedMatRefereeEmailNotif = False
        self._enableAuthorSubmittedMatEditorEmailNotif = False
        self._enableAuthorSubmittedMatReviewerEmailNotif = False
        self._enableEditorSubmittedRefereeEmailNotif = False
        self._enableReviewerSubmittedRefereeEmailNotif = False

        self._statuses = [] # list of content reviewing and final judgement
        self._reviewingQuestions = [] #list of content reviewing and final judgement questions
        self._layoutQuestions = [] #list of layout editing criteria
        self._templates = {} #dictionary with layout templates. key: id, value: Template object
        self._templateCounter = Counter(1) #counter to make new id's for the templates
        self._userCompetences = {} #dictionary with the competences of each user. key: user, value: list of competences
        self._userCompetencesByTag = {} #dictionary with the users for each competence. key: competence, value: list of users
        self._reviewingMaterials = {}
        self.notifyModification()

        # id generators
        self._statusCounter = Counter(1)
        self._questionCounter = Counter(1)
        self._answerCounter = Counter(1)
        self.addStatus("Accept", False)
        self.addStatus("To be corrected", False)
        self.addStatus("Reject", False)
Esempio n. 53
0
    def clear(self):
        """ clear catalog """

        self.data = IOBTree()  # mapping of rid to meta_data
        self.uids = OIBTree()  # mapping of uid to rid
        self.paths = IOBTree()  # mapping of rid to uid
        self._length = BTrees.Length.Length()

        for index in self.indexes.keys():
            self.getIndex(index).clear()
 def __init__(self):
     self.bookings = OOBTree()
     # we need real randomness for object keys
     # but we cannot use the same uid for zope.catalog ids
     # because it does not support 128bit integers
     # (and we do not like to use zope.intid).
     # So, we use different keys for storage and catalog
     # and we store mapping between them here.
     self.mapping = IOBTree()
     self.catalog = setup_catalog()
Esempio n. 55
0
    def setTags(self, pid, oid, tags):
        self.removeTags(pid, oid)

        if not tags:
            return

        t = []
        for tag in tags:
            tag = tag.lower().strip()
            if tag:
                t.append(tag)
        if not t:
            return

        tags = t

        pdata = self.tags.get(pid)
        if pdata is None:
            pdata = IOBTree()
            self.tags[pid] = pdata

        oids = pdata.get(oid)
        if oids is None:
            oids = OOSet()
            pdata[oid] = oids

        oids.update(tags)

        # insert oid -> pid reference
        oids = self.oids.get(oid)
        if oids is None:
            oids = OOSet()
            self.oids[oid] = oids

        oids.insert(pid)

        #update tagging engine
        engine = self.getEngine(pid)
        try:
            engine.update(oid, tags)
        except:
            engine.clear()
            engine.update(oid, tags)
Esempio n. 56
0
 def sync(self):
     adapter = self._adapter()
     self._children = IOBTree()   # reset all parent/child refs
     q = 'status!=closed'
     for number in adapter.select(q):
         if str(number) not in self.objectIds():
             if number in (self.visible_tickets or []):
                 self._add(number, adapter)
         else:
             self.get(str(number)).sync()