2011-11-09 52 views
1

我用的xmlrpclib,wsapi4plone连接到Plone的:如何通过Plone中的完整路径检查文件夹是否存在?

client = xmlrpclib.ServerProxy('http://user:[email protected]/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的方法列表?

回答

2

一种快速的解决方案是查询目录,像这样:

client = xmlrpclib.ServerProxy('http://user:[email protected]/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:[email protected]/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_catalog进行交互,实际上并不那么容易。我的两个选项都很好,但不适用于通过xmlrpc。因此,以transmogrify.ploneremote为例,用于检查远程文件夹是否存在的一个简单选项(与您的实现没有太大区别)是:

try: 
    path = 'http://user:[email protected]/plone/sites/ng/path/to/folder' 
    xmlrpclib.ServerProxy(path).getPhysicalPath() 
    return True 
except xmlrpclib.Fault, e: 
    return False 
+0

我喜欢第一个解决方案。然而,当我尝试它,我得到这个错误:TypeError:__call __()有一个意想不到的关键字参数'路径'。或者,如果我删除关键字,我得到这个错误:'xmlrpclib.Fault:<故障-1:“意外的Zope异常: - 字符串索引必须是整数,而不是str”>' – BPm

相关问题