filemaker服务器xml接口的python对象包装器
PyFileMaker的Python项目详细描述
最新版本的文档和代码可在https://github.com/aeguana/PyFileMaker
PyFileMaker模块是为脚本和交互使用而设计的。 交互会话期间使用的任何命令都可以键入脚本。
简介
有关完整和最新的参考,请转到https://github.com/aeguana/PyFileMaker/tree/master/Examples
以交互方式运行python(或者更好地运行ipython):
$ ipython
数据库和布局设置
在开始时,您必须设置服务器、数据库和布局:
>> from PyFileMaker import FMServer >> fm = FMServer('http://login:password@filemaker.server.com') >> fm. [and press Tab to see available methods and variables] >> help fm.getDbNames [displays help for the method] >> fm.getDbNames() ['dbname','anoterdatabase'] >> fm.setDb('dbname') >> fm.getLayoutNames() ['layoutname','anotherlayout'] >> fm.setLayout('layoutname')
您也可以直接键入:
>> fm = FMServer('http://login:password@filemaker.server.com','dbname','layoutname')
列出字段名
从活动布局中获取字段列表:
>> fm.doView() ['column1', 'column2']
查找记录
搜索记录:
>> fm.doFind(column1='abc') <FMProResult instance with 2 records> [column1='abcdef' column2'='some data' RECORDID=1, column1='abc' column2='another data' RECORDID=2]
您有两个记录的列表,通常只需要处理一个记录:
>> a = fm.doFind(column1='abc') >> len(a) 2 >> r = a[0] >> r. [press Tab for available layout variables or for completition of variable name] >> r.column1 'abcdef' >> r['column1'] 'abcdef' >> print r.column1 abcdef >> r.column.related 'content' >> fm.doFind( column1='abc', column__related='abc', LOP='OR', SKIP=1, MAX=1)
如果在文件生成器中插入时documentid字段自动递增,则获取最新记录:
>> fm.doFind( SORT=['documentID':'<'], MAX=1)
或使用dict-for运算符和非ascii字段进行更多低级访问:
>> fm.doFind( {'documentID.op':'lt', '-max':1})
允许任何属性组合…
查询空记录的BTW:
>> fm.doFind( column1='==')
编辑记录
当您在先前返回的记录中更改某些变量时,这是不够的:
>> r = fm.doFindAny()[0] >> r.column = 'NEWVALUE' >> fm.doEdit(r)
这将只更新表中已更改的列“column”。 您也可以在其他函数中使用已更改的旧记录-dodup、donew、dodelete。 dofind(r)将查找具有相同recordid的记录,但modid将被更新。
新记录可以指定为donew()的参数,如:
fm.doNew(column1='newvalue', column2='old') fm.doNew({'column':'newvalue','column2':'old'})
模板
返回数据的结构适合与cheetah模板一起使用。 编写模板非常容易:
import Cheetah.Template t = Cheetah.Template.Template(''' Document Template ~~~~~~~~~~~~~~~~ DocumentID: $documentID DocumentType: $DocumentType.documentType Item descriptions: #for $l in $DocumentLine - $l.description #end for ''', searchList=[r[0]])
调试连接
如何调试错误的最佳方法:
>> fm._debug = True
然后通过外部工具(如curl、xmlstarlet)检查打印的url请求:
$ curl 'http://test:test@filemaker.server.com:80/fmi/xml/fmresultset.xml?-db=test&-layout=test&-findall' | xmlstarlet fo
错误报告
如果有些东西没有按它应该的方式运行,请报告github项目的问题https://github.com/aeguana/PyFileMaker。 欢迎对守则作出新的贡献。