我使用 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
编辑:
我必须修改我的答案。我尝试通过 xmlrpc 与 Portal_catalog 进行交互,但实际上并不那么容易。我的两个选项都不错,但不能通过 xmlrpc 使用。因此,以 transmogrify.ploneremote 为例,用于检查远程文件夹是否存在的一个简单选项(与您的实现没有太大不同)如下:
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
关于python - 如何通过 Plone 中的完整路径检查文件夹是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070981/