Python 如何根据文件夹在Plone中的完整路径检查文件夹是否存在?

Python 如何根据文件夹在Plone中的完整路径检查文件夹是否存在?,python,plone,xmlrpclib,Python,Plone,Xmlrpclib,我使用xmlrpclib、wsapi4plone连接到plone: client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone') 是否有方法通过其url检查plone上是否存在文件夹?类似于:client.exists('/sites/ng/path/to/folder') 我所做的有点作弊: try: client.get_types('/sites/ng/path/to/folder') exce

我使用xmlrpclib、wsapi4plone连接到plone:

client = xmlrpclib.ServerProxy('http://user:password@blah.com/plone')
是否有方法通过其url检查plone上是否存在文件夹?类似于:
client.exists('/sites/ng/path/to/folder')

我所做的有点作弊:

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)

我没有管理员权限,所以我不能查看方法列表(有人告诉我它在plone网站的某个地方,但我需要成为管理员)。我不想在这里一直问关于什么方法可用的问题,网络上的任何地方都有plone的方法列表吗

快速解决方案是查询目录,如下所示:

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
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
另一种解决方案是遍历文件夹结构,如下所示:

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
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
编辑

我必须给出我的答案。我试图通过xmlrpc与portal_目录交互,但实际上并不容易。我的两个选项很好,但不适合通过xmlrpc使用。因此,举个例子,检查远程文件夹是否存在的一个简单选项(与您的实现没有太大区别)是:

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

我喜欢第一种解决方案。但是,当我尝试它时,我得到了以下错误:
TypeError:\uu调用\uu()得到了一个意外的关键字参数“path”
。或者,如果删除关键字,则会出现以下错误:
xmlrpclib.Fault: