Exemplo n.º 1
0
    def test_mapping_copy(self):
        a = PersistentMapping(dict(a=3, b=5))
        b = a.copy()
        c = copy.copy(a)
        d = copy.deepcopy(a)

        assert a == b
        assert a == c
        assert a == d
        assert a is not b
        assert a is not c
        assert b is not c
        assert a is not d

        del a["a"]
        assert b["a"]  # NOT impacted
        assert "a" in c  # NOT impacted
        assert d["a"]  # NOT impacted
Exemplo n.º 2
0
    def _reassembleWorkingCopy(self, new_baseline, baseline):
        # NOTE: we rewrite this method because it is broken. It should check
        # for workflows not on the self.context (as it is in original), but on
        # the new baseline
        try:
            new_baseline.workflow_history = PersistentMapping(
                baseline.workflow_history.items())
        except AttributeError:
            # No workflow apparently.  Oh well.
            pass

        # reset wf state security directly
        workflow_tool = getToolByName(self.context, 'portal_workflow')
        wfs = workflow_tool.getWorkflowsFor(new_baseline)

        for wf in wfs:
            if not isinstance(wf, DCWorkflowDefinition):
                continue
            wf.updateRoleMappingsFor(new_baseline)

        return new_baseline
Exemplo n.º 3
0
 def __init__(self, id):
     self.id = id
     self.dat = PersistentMapping()  # automatical Persictence of Dictionary
     self.dat.update({
         'title': None,
         'graphname': None,
         'gridlines': None,
         'height': None,
         'width': None,
         'data': TALESMethod(None),
         'legend': TALESMethod(None),
         'colnames': TALESMethod(None),
         'stylesheet': None,
         'convertername': None,
         'fixcolumn': None,
         'specialattrib': None,
         'intcaption': None,
         'fillgaps': None,
         'taltitle': TALESMethod(None),
     })
     self.current_version = self.version  # set at creation & update
Exemplo n.º 4
0
 def convert(self, ob):
     # Creates a copy of ob without its children.
     ob = aq_base(ob)
     k = self._klass
     if hasattr(k, '__basicnew__'):
         newob = k.__basicnew__()
     else:
         newob = new.instance(k, {})
     id = ob.id
     if callable(id):
         id = id()
     try: newob._setId(id)
     except AttributeError: newob.id = id
     newob.__dict__.update(ob.__dict__)
     if hasattr(newob, '_objects'):
         # Clear the children.
         for info in newob._objects:
             del newob.__dict__[info['id']]
         newob._objects = ()
     if hasattr(newob, '_container'):
         # Clear the children.
         newob._container = PersistentMapping()
     return newob
Exemplo n.º 5
0
    def _reassembleWorkingCopy(self, new_baseline, baseline):
        # reattach the source's workflow history, try avoid a dangling ref
        try:
            new_baseline.workflow_history = PersistentMapping(
                baseline.workflow_history.items())
        except AttributeError:
            # No workflow apparently.  Oh well.
            pass

        # reset wf state security directly
        workflow_tool = getToolByName(self.context, 'portal_workflow')
        wfs = workflow_tool.getWorkflowsFor(self.context)
        for wf in wfs:
            if not isinstance(wf, DCWorkflowDefinition):
                continue
            wf.updateRoleMappingsFor(new_baseline)

        # reattach the source's uid, this will update wc refs to point back to
        # the new baseline
        original_refs = len(new_baseline.getRefs())
        original_back_refs = len(new_baseline.getBRefs())
        new_baseline._setUID(baseline.UID())
        new_refs = len(new_baseline.getRefs())
        new_back_refs = len(new_baseline.getBRefs())
        if original_refs != new_refs:
            self._removeDuplicateReferences(new_baseline, backrefs=False)
        if original_back_refs != new_back_refs:
            self._removeDuplicateReferences(new_baseline, backrefs=True)

        # reattach the source's history id, to get the previous version
        # ancestry
        histid_handler = getToolByName(self.context, 'portal_historyidhandler')
        huid = histid_handler.getUid(baseline)
        histid_handler.setUid(new_baseline, huid, check_uniqueness=False)

        return new_baseline
Exemplo n.º 6
0
 def __init__(self, id, title):
     """ constructor """
     self.id =           id
     self.title =        title
     self.altterms =    PersistentMapping()
 def __init__(self):
     self.transforms = PersistentMapping()
     self.enable_anon_name = False
Exemplo n.º 8
0
 def __init__(self, id, title):
     """ constructor """
     self.id = id
     self.title = title
     self.concept_relations = PersistentMapping()
Exemplo n.º 9
0
 def __init__(self, elemContainer):
     self._container = OOBTree()
     self._pointers = PersistentMapping()
     self._elemContainer = elemContainer
Exemplo n.º 10
0
def install(portal):
    out          = StringIO()
    portal_types    = getToolByName(portal, 'portal_types')
    portal_skins    = getToolByName(portal, 'portal_skins')
    portal_workflow = getToolByName(portal, 'portal_workflow')
    portal_setup = getToolByName(portal, 'portal_setup')
    
    portal_setup.runAllImportStepsFromProfile('profile-ZWiki:default')

    # XXX move the following into the profile above.. cf
    # http://dev.plone.org/plone/browser/CMFPlone/trunk/profiles/default/types/Discussion_Item.xml
    
    # register our skin layer(s) and add to each existing skin
    if 'zwiki' not in portal_skins.objectIds():
        addDirectoryViews(portal_skins, 'skins', {'__name__':'Products.ZWiki'})
    for skin in portal_skins.getSkinSelections():
        path = portal_skins.getSkinPath(skin)
        path = [s.strip() for s in path.split(',')]
        for layer in ['zwiki']:
            if not layer in path: path.append(layer)
        path = ', '.join(path)
        portal_skins.addSkinSelection(skin, path)
        out.write("Added zwiki layer to %s skin\n" % skin)

    # ensure that all catalog indexes and metadata required for best Zwiki
    # performance are present. These will (hopefully) be harmless for
    # non-wiki page content.
    ZWikiPage().__of__(portal).setupCatalog()

    # disable workflow for wiki pages
    cbt = portal_workflow._chains_by_type
    if cbt is None: cbt = PersistentMapping()
    cbt[PAGE_PORTALTYPE] = []
    portal_workflow._chains_by_type = cbt
    out.write("Disabled workflow on Wiki Page\n")

    # make wiki pages use External Editor, if installed, 
    if safe_hasattr(portal.Control_Panel.Products, 'ExternalEditor'):
        # XXX Uses addAction and portal_migration, which are plonisms.
        # How should we do this for vanilla CMF ? Do nothing for now.
        try:
            migrationtool = getToolByName(portal, 'portal_migration')
            for ctype in portal_types.objectValues():
                if ctype.getId() == 'Wiki Page':
                    # We must detect plone 1 or plone 2 here because addAction has a 
                    # different number of arguments
                    # XXX actually I'm pretty sure we don't/don't need to support plone 1
                    # any more, check
                    if(migrationtool.getInstanceVersion().strip().startswith('1')):
                        ctype.addAction( 'external_edit'
                                       , name='External Edit'
                                       , action='external_edit'
                                       , permission=permissions.ModifyPortalContent
                                       , category='object'
                                       , visible=0 )
                    else:
                        ctype.addAction( 'external_edit'
                                       , name='External Edit'
                                       , action='string:$object_url/external_edit'
                                       , condition=''
                                       , permission=permissions.ModifyPortalContent
                                       , category='object'
                                       , visible=0 )
            out.write("Enabled External Editor for Wiki Pages")
        except AttributeError:
            out.write("External Editor is installed, please add the external_edit action to Wiki Page in portal_types")

    return out.getvalue()
Exemplo n.º 11
0
 def __init__(self):
     self._libraries = PersistentList()
     self._res_types = PersistentMapping()
     self.linkbyuid = False
Exemplo n.º 12
0
 def __init__(self):
     self.transforms = PersistentMapping()
Exemplo n.º 13
0
def ___test_huge_db_ghosting_system():
    """
    Interactive testcase, to demonstrate the behaviour of ZODB regarding memory management and ghost objects.
    Launch it with a "top"-like window opened next to it.

    MIGHT TRIGGER THIS WARNING:

        <...>Connection.py:550: UserWarning: The <class 'persistent.list.PersistentList'>
        object you're saving is large. (20001339 bytes.)

        Perhaps you're storing media which should be stored in blobs.

        Perhaps you're using a non-scalable data structure, such as a
        PersistentMapping or PersistentList.

        Perhaps you're storing data in objects that aren't persistent at
        all. In cases like that, the data is stored in the record of the
        containing persistent object.

        In any case, storing records this big is probably a bad idea.

        If you insist and want to get rid of this warning, use the
        large_record_size option of the ZODB.DB constructor (or the
        large-record-size option in a configuration file) to specify a larger
        size.

    Playing with this test shows that:
    
    - contants of persistent lists and mappings are really only loaded when accessed (eg. when lookup is done on them..)
    - non persistent types (list(), dict()) are badly treated, and remain in memory even when committed to file
    """

    use_non_persistent_types = False

    PersistentList = globals()["PersistentList"]
    PersistentMapping = globals()["PersistentMapping"]
    if use_non_persistent_types:
        PersistentList = list
        PersistentMapping = dict

    db, connection, root = _get_huge_db_root()

    root["data"] = PersistentList(PersistentMapping({"toto": "tata"*random.randint(5000, 6000)}) for i in range(20000))
    root["data"][0] = PersistentMapping({"toto": "tata"*5000000})  # HUGE first element

    print("We have a HUGE database filled with transient data now!")
    time.sleep(5)

    transaction.commit()

    print("We have committed the transaction!")
    time.sleep(5)

    connection.close()
    db.close()

    # ---------

    db, connection, root = _get_huge_db_root()

    print("We have reopened the huge database now!")
    time.sleep(5)

    data = root["data"]

    print("We have accessed data list!")
    time.sleep(5)

    var1 = data[0]

    print("We have accessed first element of data list!")
    time.sleep(5)

    var1 = data[0]["toto"]

    print("We have unghosted first element of data list!")
    time.sleep(5)

    for i in data:
        i  # no unghosting

    print("We have accessed all elements of data list!")
    time.sleep(5)

    for i in data:
        i["toto"]  # THIS removes the ghosting effect on element

    print("We have unghosted all elements of data list!")
    time.sleep(15)
Exemplo n.º 14
0
 def checkJobsDict(self):
     """Check jobs data structure exists"""
     if not hasattr(self.DB.meta, 'peatsa_jobs'):
         from ZODB.PersistentMapping import PersistentMapping
         self.DB.meta.peatsa_jobs = PersistentMapping()
Exemplo n.º 15
0
 def __init__(self):
     self.searchValues = PersistentMapping()