如何通过 Plone 中的完整路径检查文件夹是否存在?

发布于 2024-12-14 17:09:26 字数 672 浏览 1 评论 0原文

我使用 xmlrpclib、wsapi4plone 连接到 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)

我没有管理员权限,所以我无法查看方法列表(我被告知它位于克隆站点上的某个位置,但我需要成为管理员)。我不想一直在这里问有关可用方法的问题,网络上是否有克隆人的方法列表?

I use xmlrpclib, wsapi4plone to connect to plone:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2024-12-21 17:09:28

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

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

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

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

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

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

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:[email protected]/plone/sites/ng/path/to/folder'
   xmlrpclib.ServerProxy(path).getPhysicalPath()
   return True
except xmlrpclib.Fault, e:
   return False
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文