使用SharedStore的Python实现方法
2011-12-27 14:32
906 查看
打算在我的QTP framework中的HTML reporting里面加入detailed steps,想到了早期翻译的Tarun的文章中提到的一个工具:Shared Store
由于是COM组件,所以可以在python中实现 (我的HTML reporting也是用python实现的)
以下是具体的代码:
关于SharedStore的下载请见:http://knowledgeinbox.com/downloads/general/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/
相关文章推荐
- 使用Python实现租车计费系统的两种方法
- 使用python原生的方法实现发送email
- kNN算法实现,及python库和函数的使用方法回顾
- python使用reportlab实现图片转换成pdf的方法
- 使用Python脚本实现批量网站存活检测遇到问题及解决方法
- Python使用matplotlib实现在坐标系中画一个矩形的方法
- python中的__new__方法与__init__方法区别与调用;通过使用__new__实现单例模式
- Python使用functools实现注解同步方法
- Python使用re模块实现信息筛选的方法
- python使用multiprocessing模块实现带回调函数的异步调用方法
- Python使用ftplib实现简易FTP客户端的方法
- Python使用函数默认值实现函数静态变量的方法
- python使用分治法实现求解最大值的方法
- python实现linux下使用xcopy的方法
- python使用smtplib模块通过gmail实现邮件发送的方法
- Python使用shelve模块实现简单数据存储的方法
- 使用Python的元类实现AOP监控类方法调用过程
- python使用fileinput模块实现逐行读取文件的方法
- 使用python实现接口的方法