目前在銀行研發中心作項目管理工做。咱們單位的項目經理從需求、設計、編碼到測試以及上線,都要有很大程度的參與。沒有工具支持,不少事根本忙不過來、或者無法在有限的時間裏保證項目質量。
大概半年前開始接觸PYTHON,多多少少寫了一些能與項目結合使用的小工具。
從自動化交易接口生成工具,到一些適合咱們項目使用的測試工具。
由於項目性質,我手頭大部分活兒都是C平臺上開發的,我本身也是對C比較熟。 使用PYTHON以後,感受大好,比起用C實現,一些想法能以快得多的速度用python得以落實或驗證,PDMHandler是這些小程序中的一個。python
目前此代碼託管在GitHub上:git
咱們常見的使用場景,就是修改PowerDesigner模型文件(.pdm),轉成SQL,在開發環境上變動數據庫實例、業務代碼開發。github
大量併發需求來時,pdm常被改亂,時間一長pdm與數據庫實例的一致性就不能獲得保證了。一些較大型的系統幾百上千張表,靠人工覈對一致性是很苦的體力活兒。shell
PDMHandler實現的API能夠解決這個過程當中的SQL生成、PDM與數據庫實例的比對、在unix環境下查看pdm數據字典等功能。數據庫
其實,實現原理仍是比較簡單的。小程序
PowerDesigner的模型文件(.pdm文件)其實是一個標準的XML數據文件
沒想到吧?:)併發
一但瞭解了這一點,實現對.pdm文件的解析就變成了對xml文件的處理。dom
剩下的事就是:工具
(1)選用合適的python的xml庫 (注:PDMHandler採用了xml.dom.minidom)
(2)分析.pdm文件的詳細結構
(3)定義PDMHandler工具類的API接口,實現對.pdm的操做、解析測試
全部的"包、表定義、表字段定義、索引、索引字段定義等「全都定義在.pdm文件的這個路徑下(以類文件系統路徑方式表示):
shell/Model/o:RootObject/c:Children/o:Model
好比(包 - o:Package)定義:
注意:包定義是可嵌套的,/c:Packages/o:Package可反覆嵌套;另外o:Model自己也能夠看做一個包
shell/Model/o:RootObject/c:Children/o:Model/c:Packages/o:Package ...
再如(表 - o:Table)定義:
shell/Model/o:RootObject/c:Children/o:Model/c:Packages/o:Package/c:Tables/o:Table ...
其它PDM元素的位置再也不冗述,請見代碼PDMHandler.py
如下是Github中此項目的README.md文件,直接貼一份過來供參考 :)
歡迎fork/clone此項目,提出建議
項目主頁:https://github.com/petjiang/PDMHandler
源碼地址:git@github.com:petjiang/PDMHandler.git
A tool class to handle sybase PowerDesigner datafile(.pdm).
Currently, it is able to handle PhysicalDiagram in .pdm.
The class implementation of PDMHandler.
use following command to see help docs (sorry that I type it in Chinese):
shell$ echo "import PDMHandler; help(PDMHandler);"|python
PowerDesigner model file (.pdm) is prepared in [repodir]/src/testpdm
use these as input argument for testing the example1.py
* NOTICE: (.pdm) files come from PowerDesigner15 directory [Sybase\PowerDesigner 15\Examples]
pythonPKG_ATTR_LIST=["Name","Code","CreationDate","Creator","ModificationDate","Modifier"] TBL_ATTR_LIST=["Name","Code","CreationDate","Creator","ModificationDate","Modifier", "PhysicalOptions"] COL_ATTR_LIST=["Name","Code","CreationDate","Creator","ModificationDate","Modifier", "DataType","Length","Column.Mandatory","Comment"] IDX_ATTR_LIST=["Name","Code","CreationDate","Creator","ModificationDate","Modifier", "PhysicalOptions","Unique"] IDXCOL_ATTR_LIST=["CreationDate","Creator","ModificationDate","Modifier"]
By running :
shell$ python example1.py testpdm/Consol.pdm
shows the output to standout :
shellP: Duplicated Database DUPLICATED_DATABASE lpommier T: Duplicated Account DUPLICATED_ACCOUNT vaudino T-PATH: /Model/o:RootObject/c:Children/o:Model/c:Tables/o:Table C: Email EMAIL char(256) 256 1 C: Name NAME char(256) 256 C: URL URL char(256) 256 I: ACCOUNT_PK ACCOUNT_PK 1 IC: EMAIL T: Duplicated Auteurs DUPLICATED_AUTEURS vaudino T-PATH: /Model/o:RootObject/c:Children/o:Model/c:Tables/o:Table C: Email EMAIL char(256) 256 1 C: Title TITLE char(256) 256 1 I: AUTEURS_PK AUTEURS_PK 1 IC: EMAIL IC: TITLE I: Publication_FK PUBLICATION_FK IC: EMAIL I: Authors_FK AUTHORS_FK IC: TITLE T: Duplicated Publication DUPLICATED_PUBLICATION vaudino T-PATH: /Model/o:RootObject/c:Children/o:Model/c:Tables/o:Table C: Title TITLE char(256) 256 1 C: Email EMAIL char(256) 256 1 C: Pub_Title PUB_TITLE char(256) 256 C: Summary SUMMARY long varchar C: Keywords KEYWORDS char(256) 256 I: PUBLICATION_PK PUBLICATION_PK 1 IC: TITLE I: PUBLISHER_FK PUBLISHER_FK IC: EMAIL I: REFERENCES_FK REFERENCES_FK IC: PUB_TITLE
Yes,it is just a tiny code for fun.
But I hope more features will be added in it, and it will be useful to solve some headachy problem. Just like :