2011-11-09 4 views
1

私はxmlrpclib、Ploneのに接続するwsapi4plone使用:完全なパスでPloneにフォルダが存在するかどうかを確認するには?

client = xmlrpclib.ServerProxy('http://user:[email protected]/plone') 

はPlone上のフォルダはそのurlで存在しているかどうかを確認する方法はありますか?以下のようなもの:私は何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:[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 

編集

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 

別の解決策のようにフォルダ構造を横断することができます。これは次のように

答えて

2

高速なソリューションは、カタログを照会することです私は私の答えを甘やかす必要があります。私はxmlrpc経由でportal_catalogと対話しようとしましたが、実際にはそれほど簡単ではありません。私の2つのオプションは良いですが、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 __()は予期しないキーワード引数 'path'を持っています。 'xmlrpclib.Fault:予期しないZope例外: - 文字列インデックスは整数でなければなりません。 – BPm

関連する問題