def PublishCollection(self, overwrite=False):
        # Publish the collection

        # Update the UI by disabling/hiding various panels, and swapping in a
        # new set of buttons
        self.mainPanel.Enable(False)
        self.buttonPanel.Hide()
        self.mySizer.Detach(self.buttonPanel)
        self.buttonPanel = self.resources.LoadPanel(self,
                                                    "PublishingButtonsPanel")
        self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5)
        publishingButton = wx.xrc.XRCCTRL(self, "BUTTON_PUBLISHING")
        publishingButton.Enable(False)
        self.Bind(wx.EVT_BUTTON, self.OnStopPublish, id=wx.ID_CANCEL)

        self._clearStatus()
        self._resize()
        wx.GetApp().Yield(True)

        filters = self._getAttributeFilterState()

        accountIndex = self.accountsControl.GetSelection()
        account = self.accountsControl.GetClientData(accountIndex)
        self.pubAccount = account

        class ShareTask(task.Task):

            def __init__(task, view, account, collection, activity, overwrite,
                options):
                super(ShareTask, task).__init__(view)
                task.accountUUID = account.itsUUID
                task.collectionUUID = collection.itsUUID
                task.activity = activity
                task.overwrite = overwrite
                task.options = options

            def error(task, err):
                self._shareError(err)
                self.done = True
                self.success = False

            def success(task, result):
                self._finishedShare(result)
                self.done = True
                self.success = True

            def shutdownInitiated(task, arg):
                self._shutdownInitiated()

            def run(task):

                account = task.view.find(task.accountUUID)
                collection = task.view.find(task.collectionUUID)

                msg = _(u"Publishing collection to server...\n")
                task.callInMainThread(self._showStatus, msg)

                displayName = self.collection.displayName

                if self.name:
                    displayName = self.name

                share = sharing.publish(collection, account,
                                         filters=filters,
                                         displayName=displayName,
                                         activity=task.activity,
                                         overwrite=task.overwrite,
                                         options=task.options)

                return share.itsUUID

        # Run this in its own background thread
        self.view.commit()
        self.taskView = sharing.getView(self.view.repository)
        self.activity = Activity("Publish: %s" % self.collection.displayName)
        self.currentTask = ShareTask(self.taskView, account, self.collection,
            self.activity, overwrite, self.options)
        self.listener = Listener(activity=self.activity,
            callback=self._updateCallback)
        self.activity.started()
        self.done = False
        self.currentTask.start(inOwnThread=True)
Example #2
0
def importICalendarFile(
    fullpath,
    view,
    targetCollection=None,
    filterAttributes=None,
    activity=None,
    tzinfo=None,
    logger=None,
    selectedCollection=False,
):
    """Import ics file at fullpath into targetCollection.
    
    If selectedCollection is True, ignored targetCollection and import into
    the currently selected sidebar collection.
    If Trash is chosen as the target collection, a new collection will be 
    created instead.

    """
    from osaf.framework.blocks.Block import Block
    import translator, ics
    from osaf import sharing

    if selectedCollection:
        targetCollection = Block.findBlockByName("MainView").getSidebarSelectedCollection()

    trash = schema.ns("osaf.pim", view).trashCollection
    if targetCollection == trash:
        targetCollection = None

    view.commit(sharing.mergeFunction)  # to make target collection available
    # Note: if everyone is following the commit rules that says a commit
    # happens after every user action, this commit is not required.

    rv = sharing.getView(view.repository)
    if targetCollection is not None:
        targetCollection = rv.findUUID(targetCollection.itsUUID)

    if not os.path.isfile(fullpath):
        raise ICalendarImportError(_(u"File does not exist, import cancelled."))

    before = epoch_time()

    (dir, filename) = os.path.split(fullpath)

    try:
        # TODO: coerceTzinfo?

        import stateless

        try:
            collection = stateless.importFile(
                rv, fullpath, collection=targetCollection, filters=filterAttributes, activity=activity
            )
        except:
            if logger:
                logger.exception("Failed importFile %s" % fullpath)
            raise ICalendarImportError(_(u"Problem with the file, import cancelled."))

        if targetCollection is None:
            collectionName = getattr(collection, "displayName", "Untitled")
            if collectionName == "Untitled":
                name = "".join(filename.split(".")[0:-1]) or filename
                collection.displayName = name

        rv.commit(sharing.mergeFunction)  # makes new collection available
        view.refresh(sharing.mergeFunction)  # main ui repo view

    finally:
        sharing.releaseView(rv)

    collection = view.findUUID(collection.itsUUID)

    if targetCollection is None:
        schema.ns("osaf.app", view).sidebarCollection.add(collection)
        sideBarBlock = Block.findBlockByName("Sidebar")
        sideBarBlock.postEventByName("SelectItemsBroadcast", {"items": [collection]})
    if logger:
        logger.info("Imported collection in %s seconds" % (epoch_time() - before))

    return collection
Example #3
0
def importICalendarFile(fullpath, view, targetCollection = None,
                        filterAttributes = None, activity=None,
                        tzinfo = None, logger=None, selectedCollection = False):
    """Import ics file at fullpath into targetCollection.
    
    If selectedCollection is True, ignored targetCollection and import into
    the currently selected sidebar collection.
    If Trash is chosen as the target collection, a new collection will be 
    created instead.

    """
    from osaf.framework.blocks.Block import Block
    import translator, ics
    from osaf import sharing

    if selectedCollection:
        targetCollection = Block.findBlockByName("MainView").getSidebarSelectedCollection()

    trash = schema.ns("osaf.pim", view).trashCollection
    if targetCollection == trash:
        targetCollection = None


    view.commit(sharing.mergeFunction) # to make target collection available
    # Note: if everyone is following the commit rules that says a commit
    # happens after every user action, this commit is not required.


    rv = sharing.getView(view.repository)
    if targetCollection is not None:
        targetCollection = rv.findUUID(targetCollection.itsUUID)

    if not os.path.isfile(fullpath):
        raise ICalendarImportError(_(u"File does not exist, import cancelled."))

    before = epoch_time()

    (dir, filename) = os.path.split(fullpath)

    try:
        # TODO: coerceTzinfo?

        import stateless
        try:
            collection = stateless.importFile(rv , fullpath,
                collection=targetCollection, filters=filterAttributes,
                activity=activity)
        except:
            if logger:
                logger.exception("Failed importFile %s" % fullpath)
            raise ICalendarImportError(_(u"Problem with the file, import cancelled."))

        if targetCollection is None:
            collectionName = getattr(collection, 'displayName', 'Untitled')
            if collectionName == 'Untitled':
                name = "".join(filename.split('.')[0:-1]) or filename
                collection.displayName = name

        rv.commit(sharing.mergeFunction) # makes new collection available
        view.refresh(sharing.mergeFunction) # main ui repo view

    finally:
        sharing.releaseView(rv)

    collection = view.findUUID(collection.itsUUID)

    if targetCollection is None:
        schema.ns("osaf.app", view).sidebarCollection.add(collection)
        sideBarBlock = Block.findBlockByName('Sidebar')
        sideBarBlock.postEventByName ("SelectItemsBroadcast",
                                      {'items':[collection]})
    if logger:
        logger.info("Imported collection in %s seconds" % (epoch_time()-before))
        
    return collection
Example #4
0
    def OnYes(self, evt):
        global restoreDialog

        index = 0
        totalWork = 0
        for accountUUID, info in self.data:
            if not type(info) is Exception and info:
                # info is a list of (uuid, name, tickets) tuples
                account = self.rv.findUUID(accountUUID)
                if account is not None:
                    account.requested = set()
                    if self.checkBoxes[index].GetValue(): # restore all
                        for uuid, name, tickets in info:
                            account.requested.add(uuid)
                            totalWork += 1
                    else:
                        clb = self.checkListBoxes[index]
                        for i in range(len(clb.GetItems())):
                            uuid = info[i][0]
                            if clb.IsChecked(i):
                                account.requested.add(uuid)
                                totalWork += 1
                            else:
                                account.ignored.add(uuid)


                index += 1

        for cb in self.checkBoxes:
            cb.Enable(False)
        for cbl in self.checkListBoxes:
            cbl.Enable(False)

        self.SyncButton.Destroy()
        self.LaterButton.Destroy()
        self.NoButton.Destroy()

        self.CancelButton = wx.Button(self.panel, wx.ID_CANCEL)
        self.CancelButton.SetDefault()
        self.buttonSizer.Add(self.CancelButton, 0, wx.ALIGN_RIGHT|wx.ALL, 5)


        self.gaugeCtrl = wx.Gauge(self.panel, -1, size=(300,10))
        self.sizer.Add(self.gaugeCtrl, 0,
            wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
        self.gaugeCtrl.Pulse()

        self.statusCtrl = wx.StaticText(self.panel, -1, "")
        self.sizer.Add(self.statusCtrl, 0, wx.ALIGN_LEFT|wx.ALL, 5)

        self._resize()


        class RestoreTask(task.Task):

            def __init__(task, view, activity):
                super(RestoreTask, task).__init__(view)
                task.activity = activity

            def error(task, err):
                if restoreDialog:
                    sharing.releaseView(self.taskView)
                    self.restoring = False
                    self._restoreError(err)

            def success(task, result):
                if restoreDialog:
                    sharing.releaseView(self.taskView)
                    self.restoring = False
                    self._restoreSuccess(result)

            def shutdownInitiated(task):
                if restoreDialog:
                    self.restoring = False
                    self._shutdownInitiated()

            def run(task):
                for account in sharing.CosmoAccount.iterAccounts(task.view):
                    if account.isSetUp():
                        account.restoreCollections(activity=task.activity)

        self.rv.commit(sharing.mergeFunction)
        self.taskView = sharing.getView(self.rv.repository)
        self.activity = Activity(_(u"Restoring collections"))
        self.currentTask = RestoreTask(self.taskView, self.activity)
        self.listener = Listener(activity=self.activity,
            callback=self._updateCallback)
        self.activity.started()
        self.activity.update(totalWork=totalWork+1)
        self.restoring = True
        self.currentTask.start(inOwnThread=True)
Example #5
0
    def OnYes(self, evt):
        global restoreDialog

        index = 0
        totalWork = 0
        for accountUUID, info in self.data:
            if not type(info) is Exception and info:
                # info is a list of (uuid, name, tickets) tuples
                account = self.rv.findUUID(accountUUID)
                if account is not None:
                    account.requested = set()
                    if self.checkBoxes[index].GetValue():  # restore all
                        for uuid, name, tickets in info:
                            account.requested.add(uuid)
                            totalWork += 1
                    else:
                        clb = self.checkListBoxes[index]
                        for i in range(len(clb.GetItems())):
                            uuid = info[i][0]
                            if clb.IsChecked(i):
                                account.requested.add(uuid)
                                totalWork += 1
                            else:
                                account.ignored.add(uuid)

                index += 1

        for cb in self.checkBoxes:
            cb.Enable(False)
        for cbl in self.checkListBoxes:
            cbl.Enable(False)

        self.SyncButton.Destroy()
        self.LaterButton.Destroy()
        self.NoButton.Destroy()

        self.CancelButton = wx.Button(self.panel, wx.ID_CANCEL)
        self.CancelButton.SetDefault()
        self.buttonSizer.Add(self.CancelButton, 0, wx.ALIGN_RIGHT | wx.ALL, 5)

        self.gaugeCtrl = wx.Gauge(self.panel, -1, size=(300, 10))
        self.sizer.Add(self.gaugeCtrl, 0,
                       wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
        self.gaugeCtrl.Pulse()

        self.statusCtrl = wx.StaticText(self.panel, -1, "")
        self.sizer.Add(self.statusCtrl, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        self._resize()

        class RestoreTask(task.Task):
            def __init__(task, view, activity):
                super(RestoreTask, task).__init__(view)
                task.activity = activity

            def error(task, err):
                if restoreDialog:
                    sharing.releaseView(self.taskView)
                    self.restoring = False
                    self._restoreError(err)

            def success(task, result):
                if restoreDialog:
                    sharing.releaseView(self.taskView)
                    self.restoring = False
                    self._restoreSuccess(result)

            def shutdownInitiated(task):
                if restoreDialog:
                    self.restoring = False
                    self._shutdownInitiated()

            def run(task):
                for account in sharing.CosmoAccount.iterAccounts(task.view):
                    if account.isSetUp():
                        account.restoreCollections(activity=task.activity)

        self.rv.commit(sharing.mergeFunction)
        self.taskView = sharing.getView(self.rv.repository)
        self.activity = Activity(_(u"Restoring collections"))
        self.currentTask = RestoreTask(self.taskView, self.activity)
        self.listener = Listener(activity=self.activity,
                                 callback=self._updateCallback)
        self.activity.started()
        self.activity.update(totalWork=totalWork + 1)
        self.restoring = True
        self.currentTask.start(inOwnThread=True)