您的位置:首页 > 编程语言 > Python开发

使用SharedStore的Python实现方法

2011-12-27 14:32 906 查看
打算在我的QTP framework中的HTML reporting里面加入detailed steps,想到了早期翻译的Tarun的文章中提到的一个工具:Shared Store

由于是COM组件,所以可以在python中实现 (我的HTML reporting也是用python实现的)

以下是具体的代码:

import win32com.client

class SharedStore():

def __init__(self):
self.SSName = 'HTMLReporting'
self.StoreName = 'HTMLReporting'
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")

def SharedStore_add(self, contents):
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
else:
oStore = self.SS.AddStore(self.SSName)
li = []
if oStore.Exists(self.StoreName):
tempTuple = oStore.GetItem(self.StoreName)
for tu in tempTuple:
if '' != tu:
li.append(tu)
li.append(contents)
oStore.SetItem (self.StoreName, li)
else:
li.append(contents)
oStore.AddItem (self.StoreName, li)

self.SS.PersistInMemory = True

def SharedStore_Get(self):
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
oStore = self.SS.GetStore(self.SSName)
oDict = oStore.GetItem (self.StoreName)
return oDict

def SharedStore_Kill(self):
self.SS = win32com.client.Dispatch("KnowledgeInbox.SharedStore")
if self.SS.Exists(self.SSName):
oStore = self.SS.GetStore(self.SSName)
oStore.RemoveAll
oStore.SetItem(self.StoreName, '')
self.SS.PersistInMemory = False

if __name__ == '__main__':
test = SharedStore()
test.SharedStore_add('hello1')
test.SharedStore_add('hello2')
test.SharedStore_add('hello3')
test.SharedStore_add('hello4')
test.SharedStore_add('hello5')
print test.SharedStore_Get()
test.SharedStore_Kill()
test.SharedStore_add('hello1')
print test.SharedStore_Get()


关于SharedStore的下载请见:http://knowledgeinbox.com/downloads/general/shared-store/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: