[Zope] - backing up Data.bbb

simon@joyful.com simon@joyful.com
20 Jan 1999 21:03:52 -0800


Jim, Paul, thanks for your comments -

Jim Fulton <jim.fulton@digicool.com> writes:
> By "my find function" do you mean using the find tab or do you mean
> something that you have written yourself?  I'm a bit surprised that
> this would take so long, although I can't say I've tried an
> application like the

I mean an external method which I based on PrincipiaFind(). It's
appended below.

> > It makes me wonder if I need "ExternalFile" and "ExternalFolder"
> > objects,
> 
> Do you have reason to think that this would make things faster?

No, beyond my gut feelings about how long a filesystem "find" of 179
files should take. I thought that perhaps by stuffing large data files
into the zbase, I am using the machinery inefficiently.

Thanks also for the comments on the file-less method product. I see
someone else asked about it too. I'll put that aside for now.

The other problem I'm having is how to filter the search results based
on user permissions. My best guess, after much wailing and gnashing of
teeth, is:

  if (REQUEST.AUTHENTICATED_USER.allowed(ob,ob.aq_acquire('__roles__')))

but I don't see roles getting acquired like I would expect. Any light
on *this* subject would be most helpful!

Regards,
-Simon



def Find(self, 
         obj, 
         obj_searchterm=None,
         obj_days=0, 
         search_sub=0,
         REQUEST=None, 
         result=None, 
         pre=''):
    """find function, based on PrincipiaFind"""

    if result is None:
        result=[]
        try:
            obj_days = int(obj_days)
        except:
            obj_days = 0

    base=obj
    if hasattr(obj, 'aq_base'):
        base=obj.aq_base

    if not hasattr(base, 'objectItems'):
        return result

    try:    items=base.objectItems() 
    except: return result

    try: add_result=result.append
    except:
        raise AttributeError, `result`

    for id, ob in items:

        if pre: p="%s/%s" % (pre, id)
        else:   p=id
            
        dflag=0
        if hasattr(ob, '_p_changed') and (ob._p_changed == None):
            dflag=1

        if hasattr(ob, 'aq_base'):
            bs=ob.aq_base

        if (                            # it's a file,
            (hasattr(bs, 'meta_type') and bs.meta_type == 'File')
            and                         # we have access,
            # see if we have permission to access this object
            # do I know what I'm doing
            (REQUEST.AUTHENTICATED_USER.allowed(ob,ob.aq_acquire('__roles__')))
            and                         # the text matches,
            (not obj_searchterm or      
             find(lower(absattr(bs.id)), lower(obj_searchterm)) >= 0 or
             find(lower(absattr(bs.title)), lower(obj_searchterm)) >= 0)
            and                         # and the age matches
            (not obj_days or            
             (hasattr(ob, '_p_mtime') and 
              ((DateTime().earliestTime() - DateTime(ob._p_mtime).earliestTime()) < obj_days)))
            ):
            add_result((p, ob))         # then add it to the results
            dflag=0
                    
        if search_sub and hasattr(bs, 'objectItems'):
            Find(self,
                 ob, 
                 obj_searchterm,
                 obj_days,
                 search_sub,
                 REQUEST, 
                 result, 
                 p)
        if dflag: ob._p_deactivate()

    return result