WEB开发网
开发学院软件开发Python python操作sharepoint对象模型 阅读

python操作sharepoint对象模型

 2010-09-22 11:27:22 来源:WEB开发网   
核心提示: 编译后生成pyps.dll,然后注册com组件,运行命令regasm pyps.dll / register下面是python 代码:pspy.py 1import win32com.client 2class PySite: 3 def __init__(self,url): 4 sel

编译后生成pyps.dll,然后注册com组件,运行命令regasm pyps.dll / register

下面是python 代码:

pspy.py

  1import win32com.client
  2class PySite:
  3    def __init__(self,url):
  4        self.__com__=win32com.client.Dispatch("PySP.PySite")
  5        self.__com__.open(url)
  6    def OpenWeb(self,url):
  7        return pyweb(self.__com__.openweb(url))
  8    def Close(self):
  9        self.__com__.close
 10 
 11
 12class PyWeb(object):
 13    def __init__(self,com):
 14        self.__com__=com
 15    @property
 16    def AllowAnonymousAccess(self):
 17        return self.__com__.AllowAnonymousAccess
 18    @property
 19    def AllowAutomaticASPXPageIndexing(self):
 20        return self.__com__.AllowAnonymousAccess
 21    @AllowAutomaticASPXPageIndexing.setter
 22    def AllowAutomaticASPXPageIndexing(self,bool):
 23        self.__com__.AllowAutomaticASPXPageIndexing=bool
 24    @property
 25    def AllowRssFeeds(self):
 26        return self.__com__.AllowAnonymousAccess
 27    @property
 28    def AllowUnsafeUpdates(self):
 29        return self.__com__.AllowAnonymousAccess
 30    @AllowUnsafeUpdates.setter
 31    def AllowUnsafeUpdates(self,value):
 32        self.__com__.AllowUnsafeUpdates=value
 33    @property
 34    def Title(self):
 35        return self.__com__.Title
 36    @Title.setter
 37    def Title(self,value):
 38        self.__com__.Title=value
 39    def Update(self):
 40        self.__com__.Update
 41    def Close(self):
 42        self.__com__.Close
 43    @property
 44    def Lists(self):
 45        return pylistcollection(self.__com__.Lists)
 46
 47class PyList(object):
 48    def __init__(self,com):
 49        self.__com__=com
 50    @property
 51    def Title(self):
 52        return self.__com__.Title
 53    @Title.setter
 54    def Title(self,value):
 55        self.__com__.Title=value
 56    @property
 57    def AllowContentTypes(self):
 58        return self.__com__.AllowContentTypes
 59    @property
 60    def AllowDeletion(self):
 61        return self.__com__.AllowDeletion
 62    @property
 63    def CanReceiveEmail(self):
 64        return self.__com__.CanReceiveEmail
 65    @property
 66    def Created(self):
 67        return self.__com__.Created
 68    @property
 69    def Items(self):
 70        return pylistitemcollection(self.__com__.GetAllItems)
 71    def update(self):
 72        self.__com__.Update
 73
 74class PyListCollection(object):
 75    def __init__(self,com):
 76        self.__com__=com
 77    @property
 78    def Count(self):
 79        return self.__com__.Count
 80    def getList(self,index=-1,name=''):
 81        if index!=-1:
 82            return pylist(self.__com__.GetListByIndex(index))
 83        if name!='':
 84            return pylist(self.__com__.GetListByName(name))
 85
 86class PyListItem(object):
 87    def __init__(self,com):
 88        self.__com__=com
 89    @property
 90    def Title(self):
 91        return self.__com__.Title
 92    def Update(self):
 93        self.__com__.Update
 94
 95class PyListItemCollection(object):
 96    def __init__(self,com):
 97        self.__com__=com
 98    @property
 99    def Count(self):
100        return self.__com__.Count
101    def getItem(self,index=-1):
102        return  pylistitem(self.__com__.GetItemByIndex(index))
103   
104
105   

最后是python的简单测试代码:

>>site=PySite('http://sun/')

>>web=site.OpenWeb('/test')

>>print  web.Title

>>'Moss'

>>web.Title='MyMoss'

>>web.Update()

>>print web.Title

>>'MyMoss'

这是一时无聊写下的代码,本身也没有什么实用价值。

不过还是希望大虾们指点一下,这样写会有什么副作用没有?

谢谢.

上一页  2 3 4 5 6 7 

Tags:python 操作 sharepoint

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接