سؤال

I use xmlrpclib, wsapi4plone to connect to plone:

client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')

is there a method to check if a folder on plone exists by its url? something like: client.exists('/sites/ng/path/to/folder')
What I did is a bit of cheating:

try:    
    client.get_types('/sites/ng/path/to/folder')
except:
    #if there's an exception, that means there's no folder -> create it here
    client.post_object(folder)

I dont have the admin rights so i can't look at the methods list (which I was told that it's somewhere on the plone site but I need to be the admin). I don't want to keep having to ask question on here about what method is available, is there a plone's methods list anywhere on the web?

هل كانت مفيدة؟

المحلول

A fast solution is to query the catalog, like this:

client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')
completePath = '/'.join(client.getPhysicalPath()) + '/sites/ng/path/to/folder'
if len(client.portal_catalog.searchResults(path=completePath)):
    return True

Another solution could be to traverse the folders structure like this:

client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')
path = '/sites/ng/path/to/folder'
subdirs = path.split('/')[1:]
dir = client
for subdir in subdirs:
    if subdir in dir.objectIds():
        dir = dir[subdir]
    else:
        return False
return True

edit:

I have to ammend my answer. I tried to interact with the portal_catalog via xmlrpc and actually it's not so easy. My two options are good, but not for use via xmlrpc. So, taking as example transmogrify.ploneremote, a simple option (not very different from your implementation) for checking if a remote folder exists is this:

try:
   path = 'http://user:password@blah.com/plone/sites/ng/path/to/folder'
   xmlrpclib.ServerProxy(path).getPhysicalPath()
   return True
except xmlrpclib.Fault, e:
   return False
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top