def RoundTripNonCollection(self): # Export repo = self.repos[0] theItem = ContentItem(view=repo.view) theItem.displayName = "I'm an item" conduit = Sharing.FileSystemConduit(sharePath=".", shareName="exporteditem", view=repo.view) format = Sharing.CloudXMLFormat(view=repo.view) self.share3 = Sharing.Share(contents=theItem, conduit=conduit, format=format, view=repo.view) if self.share3.exists(): self.share3.destroy() self.share3.create() self.share3.put() # Import repo = self.repos[1] conduit = Sharing.FileSystemConduit(sharePath=".", shareName="exporteditem", view=repo.view) format = Sharing.CloudXMLFormat(view=repo.view) self.share4 = Sharing.Share(conduit=conduit, format=format, view=repo.view) self.share4.get() alsoTheItem = self.share4.contents self.assert_(alsoTheItem.displayName == "I'm an item", "Single-item import/export failed")
def RoundTrip(self): # Export repo = self.repos[0] sandbox = repo.findPath("//sandbox") coll = sandbox.findPath("testcollection") conduit = Sharing.FileSystemConduit(name="conduit", parent=sandbox, sharePath=".", shareName="exportedcollection", view=repo.view) format = Sharing.CloudXMLFormat(name="format", parent=sandbox, view=repo.view) self.share1 = Sharing.Share(name="share", parent=sandbox, contents=coll, conduit=conduit, format=format, view=repo.view) if self.share1.exists(): self.share1.destroy() self.share1.create() self.share1.put() # Import repo = self.repos[1] sandbox = repo.findPath("//sandbox") coll = sandbox.findPath("testcollection") conduit = Sharing.FileSystemConduit(name="conduit", parent=sandbox, sharePath=".", shareName="exportedcollection", view=repo.view) format = Sharing.CloudXMLFormat(name="format", parent=sandbox, view=repo.view) self.share2 = Sharing.Share(name="share", parent=sandbox, conduit=conduit, format=format, view=repo.view) self.share2.get() # Make sure that the items we imported have the same displayNames # as the ones we exported (and no fewer, no more) names = {} for item in self.share1.contents: names[item.displayName] = 1 for item in self.share2.contents: self.assert_(item.displayName in names, "Imported item that wasn't" "exported") del names[item.displayName] self.assert_(len(names) == 0, "Import is missing some items that were" "exported")
def testImport(self): if os.environ.get('CHANDLER_PERFORMANCE_TEST'): self.loadParcel("parcel:osaf.pim.calendar") path = os.path.join(os.getenv('CHANDLERHOME') or '.', 'parcels', 'osaf', 'sharing', 'tests') conduit = Sharing.FileSystemConduit(name="conduit", sharePath=path, shareName="3kevents.ics", view=self.rep.view) format = ICalendar.ICalendarFormat(name="format", view=self.rep.view) share = Sharing.Share(name="share", conduit=conduit, format=format, view=self.rep.view) share.get()
def Import(self, view, filename): path = os.path.join(os.getenv('CHANDLERHOME') or '.', 'parcels', 'osaf', 'sharing', 'tests') sandbox = self.repo.findPath("//sandbox") conduit = Sharing.FileSystemConduit(parent=sandbox, sharePath=path, shareName=filename, view=view) format = ICalendar.ICalendarFormat(parent=sandbox) self.share = Sharing.Share(parent=sandbox, conduit=conduit, format=format) self.share.get() return format
def OnOk(self, evt): title = self.textTitle.GetValue() shareName = self.textShareName.GetValue() accountIndex = self.choiceAccount.GetSelection() - 1 account = self.accounts[accountIndex] if not self.join: collIndex = self.choiceColl.GetSelection() - 1 collection = self.collections[collIndex] if self.share is None: conduit = Sharing.WebDAVConduit(account=account, shareName=shareName, view=self.view) if shareName.endswith('.ics'): format = ICalendar.ICalendarFormat(view=self.view) else: format = Sharing.CloudXMLFormat(view=self.view) if self.join: self.share = Sharing.Share(conduit=conduit, format=format, view=self.view) else: self.share = Sharing.Share(contents=collection, conduit=conduit, format=format, view=self.view) self.share.displayName = title else: self.share.displayName = title self.share.conduit.account = account self.share.conduit.shareName = shareName self.share.contents = collection self.EndModal(True)
def OnSubscribe(self, evt): view = self.view url = self.textUrl.GetValue() if url.startswith('webcal:'): url = 'http:' + url[7:] share = Sharing.findMatchingShare(view, url) if share is not None: self.__showStatus("You are already subscribed") return try: share = Sharing.Share(view=view) share.configureInbound(url) if share is None: return if self.accountPanel.IsShown(): share.conduit.account.username = self.textUsername.GetValue() share.conduit.account.password = self.textPassword.GetValue() self.__showStatus("In progress...") wx.Yield() share.sync() collection = share.contents mainView = Globals.views[0] mainView.postEventByName( "AddToSidebarWithoutCopyingAndSelectFirst", {'items': [collection]}) event = 'ApplicationBarAll' if share.filterKinds and len(share.filterKinds) == 1: filterKind = share.filterKinds[0] if filterKind == '//parcels/osaf/pim/calendar/CalendarEventMixin': event = 'ApplicationBarEvent' elif filterKind == '//parcels/osaf/pim/tasks/TaskMixin': event = 'ApplicationBarTask' elif filterKind == '//parcels/osaf/pim/mail/MailMessageMixin': event = 'ApplicationBarMail' mainView.postEventByName(event, {}) self.EndModal(True) except Sharing.NotAllowed, err: self.__showAccountInfo(share.conduit.account) share.delete(True)
def writeICalendarUnicodeBug3338(self): event = Calendar.CalendarEvent(view = self.repo.view) event.displayName = u"unicode \u0633\u0644\u0627\u0645" event.startTime = datetime.datetime(2010, 1, 1, 10) event.endTime = datetime.datetime(2010, 1, 1, 11) coll = ItemCollection(name="testcollection", parent=self.sandbox) coll.add(event) filename = "unicode_export.ics" conduit = Sharing.FileSystemConduit(name="conduit", sharePath=".", shareName=filename, view=self.repo.view) format = ICalendar.ICalendarFormat(name="format", view=self.repo.view) self.share = Sharing.Share(name="share",contents=coll, conduit=conduit, format=format, view=self.repo.view) if self.share.exists(): self.share.destroy() self.share.create() self.share.put() cal=vobject.readComponents(file(filename, 'rb')).next() self.assertEqual(cal.vevent[0].summary[0].value, event.displayName) self.share.destroy()