コード例 #1
0
ファイル: LDAPTreeItem.py プロジェクト: einaru/luma
    def fetchChildList(self):
        """
        (Re)aquire the list of childs for this item (if any).
        """       
        lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)

        bindSuccess, exceptionObject = lumaConnection.bindSync()
        
        if not bindSuccess:
            tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)
        
        # Search for items at the level under this one
        success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \
                scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit)
        lumaConnection.unbind()
        
        if not success:
            tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)
        
        self.error = False
        
        # Default behavior: return all
        return (True, [LDAPTreeItem(x, self.serverParent, self) for x in resultList], exceptionObject)
コード例 #2
0
ファイル: Search.py プロジェクト: einaru/luma
    def onServerChanged(self, index):
        """Slot for the server combo box.

        When the selected index changes, we want to fetch the baseDN
        list off of the selected server, and populate the baseDN combo
        box.

        :param index: the index of the server entry in the combobox.
        :type index: int
        """
        server = self.searchForm.server.decode('utf-8')

        # No need to try to fetch the base dn list off of no server.
        if server == '':
            self.searchForm.baseDNBox.clear()
            return

        # Get the server object for the selected server.
        # And return if this object is None
        self.currentServer =  self.serverListObject.getServerObject(server)

        if self.currentServer is None:
            return

        #self.connection = LumaConnection(self.currentServer)
        con = LumaConnectionWrapper(self.currentServer, self)

        if self.currentServer.autoBase:
            #success, baseDNList, e = self.connection.getBaseDNList()
            success, baseDNList, e = con.getBaseDNListSync()
            if not success:
                # TODO: give some visual feedback to the user, regarding
                #       the unsuccessful bind operation
                msg = 'Could not retrieve baseDN. Reason:\n{0}'.format(str(e))
                self.searchForm.onSearchError(True, msg)
                self.__logger.error(msg)
        else:
            baseDNList = [self.currentServer.baseDN]

        # Try to populate it with the newly fetched baseDN list.
        # We need make sure the baseDN combo box is cleared before we
        self.searchForm.populateBaseDNBox(baseDNList)

        # Try to fetch the list of available attributes, for use in the
        # filter wizard and for autocompletion.
        # Jippi ay o' what a beautiful var name!!
        ocai = ObjectClassAttributeInfo(self.currentServer)
        attributes = ocai.getAttributeList()
        objectClasses = ocai.getObjectClasses()

        self.filterBuilder.onServerChanged(objectClasses, attributes)

        if self.autocompleteIsEnabled:
            self.searchForm.initAutoComplete(attributes)
コード例 #3
0
ファイル: Search.py プロジェクト: khosrow/luma-devel
    def onServerChanged(self, index):
        """Slot for the server combo box.

        When the selected index changes, we want to fetch the baseDN
        list off of the selected server, and populate the baseDN combo
        box.

        :param index: the index of the server entry in the combobox.
        :type index: int
        """
        server = self.searchForm.server.decode('utf-8')

        # No need to try to fetch the base dn list off of no server.
        if server == '':
            self.searchForm.baseDNBox.clear()
            return

        # Get the server object for the selected server.
        # And return if this object is None
        self.currentServer = self.serverListObject.getServerObject(server)

        if self.currentServer is None:
            return

        #self.connection = LumaConnection(self.currentServer)
        con = LumaConnectionWrapper(self.currentServer, self)

        if self.currentServer.autoBase:
            #success, baseDNList, e = self.connection.getBaseDNList()
            success, baseDNList, e = con.getBaseDNListSync()
            if not success:
                # TODO: give some visual feedback to the user, regarding
                #       the unsuccessful bind operation
                msg = 'Could not retrieve baseDN. Reason:\n{0}'.format(str(e))
                self.searchForm.onSearchError(True, msg)
                self.__logger.error(msg)
        else:
            baseDNList = [self.currentServer.baseDN]

        # Try to populate it with the newly fetched baseDN list.
        # We need make sure the baseDN combo box is cleared before we
        self.searchForm.populateBaseDNBox(baseDNList)

        # Try to fetch the list of available attributes, for use in the
        # filter wizard and for autocompletion.
        # Jippi ay o' what a beautiful var name!!
        ocai = ObjectClassAttributeInfo(self.currentServer)
        attributes = ocai.getAttributeList()
        objectClasses = ocai.getObjectClasses()

        self.filterBuilder.onServerChanged(objectClasses, attributes)

        if self.autocompleteIsEnabled:
            self.searchForm.initAutoComplete(attributes)
コード例 #4
0
ファイル: EntryModel.py プロジェクト: einaru/luma
    def saveModel(self):
        """
        Save changes to the current object.
        """

        lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        if self.CREATE:
            success, exceptionObject = lumaConnection.addDataObject(self.smartObject)
            lumaConnection.unbind()

            if success:
                #self.CREATE = False
                self.EDITED = False
                self.modelChangedSignal.emit(False)
                return (True, None, None)
            else:
                message = self.str_ADD
                return (False, message, exceptionObject)
        else:
            success, exceptionObject = lumaConnection.updateDataObject(self.smartObject)
            lumaConnection.unbind()
            if success:
                self.EDITED = False
                self.modelChangedSignal.emit(False)
                return (True, None, None)
            else:
                message = self.str_SAVE
                return (False, message, exceptionObject)
コード例 #5
0
ファイル: EntryModel.py プロジェクト: einaru/luma
    def initModel(self, create=False):
        if create:
            self.EDITED = True
            self.ISLEAF = False
            self.CREATE = True
            self.VALID = True
        else:
            self.EDITED = False
            isLeave = False
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid

            serverMeta = self.smartObject.getServerMeta()

            lumaConnection = LumaConnectionWrapper(serverMeta, self)

            bindSuccess, exceptionObject = lumaConnection.bindSync()

            if not bindSuccess:
                message = self.str_BIND
                return (False, message, exceptionObject)

            success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.dn, ldap.SCOPE_ONELEVEL, filter="(objectClass=*)", attrList=None, attrsonly=1, sizelimit=1)
            lumaConnection.unbind()

            # Our search succeeded. No errors
            if success:

                # There are no leaves below
                if len(resultList) == 0:
                    self.ISLEAF = True

                # Leaves are below
                else:
                    self.ISLEAF = False

            # Error during search request
            else:
                self.ISLEAF = False
                message = self.str_CHECK_LEAF
                self.modelChangedSignal.emit(True)
                return (False, message, exceptionObject)

            self.CREATE = False

        self.modelChangedSignal.emit(True)
        return (True, None, None)
コード例 #6
0
ファイル: Search.py プロジェクト: khosrow/luma-devel
class Search(QObject):
    """Object representing a search."""

    #: Signal used to inform about returned search results
    resultsRetrieved = pyqtSignal(list, object)
    __logger = logging.getLogger(__name__)

    def __init__(self, parent, server, **kwargs):
        """
        :param parent: the connection object to perform the search
        :type parent: QObject
        :param server: the sever to search on.
        :type server: ServerObject
        :param **kwargs: a dict with keyword arguments to pass to the
         LDAP search operation.
        :type **kwargs: dict
        """
        super(Search, self).__init__(parent)
        self.filter = kwargs['filter']
        self.connection = LumaConnectionWrapper(server, self)
        self.connection.searchFinished.connect(self.onSearchFinished)

        bindSuccess, e = self.connection.bindSync()
        if not bindSuccess:
            msg = 'Unable to bind to {0}. Reason\n{1}'
            self.__logger.error(msg.format(server, str(e)))
        else:
            self.connection.searchAsync(**kwargs)

    def onSearchFinished(self, success, result, e):
        """Slot for the searchFinished signal in LumaConnectionWrapper.
        As of now this reemits a signal that SearchPlugin has connected
        to. This is done in order to be able to provide the filter and
        attributes needed for the result view.
        """
        # If self.connection wasn't an object attribute
        # it should probably be unparented here so that it
        # is GCed.
        #self.sender().setParent(None)

        if success:
            result.append(self.filter)
            self.resultsRetrieved.emit(result, None)
        else:
            self.resultsRetrieved.emit([], e)
コード例 #7
0
ファイル: Search.py プロジェクト: einaru/luma
class Search(QObject):
    """Object representing a search."""

    #: Signal used to inform about returned search results
    resultsRetrieved = pyqtSignal(list, object)
    __logger = logging.getLogger(__name__)

    def __init__(self, parent, server, **kwargs):
        """
        :param parent: the connection object to perform the search
        :type parent: QObject
        :param server: the sever to search on.
        :type server: ServerObject
        :param **kwargs: a dict with keyword arguments to pass to the
         LDAP search operation.
        :type **kwargs: dict
        """
        super(Search, self).__init__(parent)
        self.filter = kwargs['filter']
        self.connection = LumaConnectionWrapper(server, self)
        self.connection.searchFinished.connect(self.onSearchFinished)

        bindSuccess, e = self.connection.bindSync()
        if not bindSuccess:
            msg = 'Unable to bind to {0}. Reason\n{1}'
            self.__logger.error(msg.format(server, str(e)))
        else:
            self.connection.searchAsync(**kwargs)

    def onSearchFinished(self, success, result, e):
        """Slot for the searchFinished signal in LumaConnectionWrapper.
        As of now this reemits a signal that SearchPlugin has connected
        to. This is done in order to be able to provide the filter and
        attributes needed for the result view.
        """
        # If self.connection wasn't an object attribute
        # it should probably be unparented here so that it
        # is GCed.
        #self.sender().setParent(None)

        if success:
            result.append(self.filter)
            self.resultsRetrieved.emit(result, None)
        else:
            self.resultsRetrieved.emit([], e)
コード例 #8
0
ファイル: BrowserDialogs.py プロジェクト: khosrow/luma-devel
    def delete(self):

        self.deleteButton.setEnabled(False)
        if self.hasTriedToDelete:
            # Should not be called twice
            return

        # At his point, we don't "cancel" but say we're done
        self.cancelButton.setText("Done")
        self.hasTriedToDelete = True
        allDeleted = True

        # True for now
        self.passedItemsWasDeleted = True

        # Iterate through the modelitems and remove unchekced items
        # from the dictionary, which will be used later.
        for i in xrange(self.model.rowCount()):
            item = self.model.itemFromIndex(self.model.index(i, 0))
            if item.checkState() != QtCore.Qt.Checked:
                self.deleteDict.pop(self.__utf8(item.text()))
                # If we unchecked something, can't be sure the passed items was deleted
                self.passedItemsWasDeleted = False

        # Map the dictionary keys
        deleteSOList = map(lambda x: self.deleteDict[x][0],
                           self.deleteDict.keys())
        deleteSOList.sort(
            key=lambda x: len(x.getDN()))  #parents first (sorted by length)
        deleteSOList.reverse()

        # We now have a list with smartObjects to be deleted, so let's do so
        # TODO Do in thread?
        for sO in deleteSOList:
            # Create a LumaConnection if necessary
            if not self.serverConnections.has_key(sO.serverMeta.name):
                self.serverConnections[
                    sO.serverMeta.name] = LumaConnectionWrapper(sO.serverMeta)
                self.serverConnections[sO.serverMeta.name].bindSync()

            # Use it to delete the object on the server
            conn = self.serverConnections[sO.serverMeta.name]
            status, e = conn.delete(sO.getDN())

            # Update the status in the dialog
            if not status:
                self.passedItemsWasDeleted = False
                allDeleted = False
                self.deleteDict[getRep(sO)][2].setText(str(e))
            else:
                self.deleteDict[getRep(sO)][2].setText("OK!")

        # Remember to unbind all the servers
        for conn in self.serverConnections.values():
            conn.unbind()
コード例 #9
0
ファイル: LDAPTreeItem.py プロジェクト: einaru/luma
 def delete(self):
     """ Tries to delete the item on the server
     """
     
     lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)
     bindSuccess, exceptionObject = lumaConnection.bindSync()
     
     if not bindSuccess:
         message = QtCore.QCoreApplication.translate("LDAPTreeItem","Could not bind to server.")
         return (False, message, exceptionObject)
     
     success, exceptionObject = lumaConnection.delete(self.smartObject().getDN())
     lumaConnection.unbind()
     
     if success:
         self.childItems = []
         self.populated = True
         return (True, None, None)
     else:
         message = QtCore.QCoreApplication.translate("LDAPTreeItem","Could not delete entry: "+exceptionObject[0]["desc"])
         return (False, message, exceptionObject)
コード例 #10
0
ファイル: Search.py プロジェクト: khosrow/luma-devel
    def __init__(self, parent, server, **kwargs):
        """
        :param parent: the connection object to perform the search
        :type parent: QObject
        :param server: the sever to search on.
        :type server: ServerObject
        :param **kwargs: a dict with keyword arguments to pass to the
         LDAP search operation.
        :type **kwargs: dict
        """
        super(Search, self).__init__(parent)
        self.filter = kwargs['filter']
        self.connection = LumaConnectionWrapper(server, self)
        self.connection.searchFinished.connect(self.onSearchFinished)

        bindSuccess, e = self.connection.bindSync()
        if not bindSuccess:
            msg = 'Unable to bind to {0}. Reason\n{1}'
            self.__logger.error(msg.format(server, str(e)))
        else:
            self.connection.searchAsync(**kwargs)
コード例 #11
0
    def deleteObject(self):
        """
        Deletes the remote object that this model represents
        """

        lumaConnection = LumaConnectionWrapper(
            self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, exceptionObject = lumaConnection.delete(
            self.smartObject.getDN())
        lumaConnection.unbind()

        if success:
            #serverName = self.smartObject.getServerAlias()
            #dn = self.smartObject.getPrettyParentDN()
            #self.model().reloadItem(self.smartObject.parent())
            #self.modelChangedSignal.emit()
            return (True, None, None)
        else:
            message = self.str_DELETE
            return (False, message, exceptionObject)
コード例 #12
0
    def reloadModel(self):
        """
        Refreshes the LDAP data from server,
        """
        lumaConnection = LumaConnectionWrapper(
            self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, resultList, exceptionObject = lumaConnection.searchSync(
            self.smartObject.getDN(), ldap.SCOPE_BASE)
        lumaConnection.unbind()

        if success and (len(resultList) > 0):
            self.smartObject = resultList[0]
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid
            self.EDITED = False
            self.modelChangedSignal.emit(True)
            return (True, None, None)
        else:
            message = self.str_REFRESH
            return (False, message, exceptionObject)
コード例 #13
0
ファイル: LDAPTreeItem.py プロジェクト: khosrow/luma-devel
    def fetchChildList(self):
        """
        (Re)aquire the list of childs for this item (if any).
        """
        lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)

        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"),
                                self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)

        # Search for items at the level under this one
        success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \
                scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit)
        lumaConnection.unbind()

        if not success:
            tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"),
                                self.serverParent, self)
            # We're adding the error as LDAPErrorItem-child, so return True
            return (True, [tmp], exceptionObject)

        self.error = False

        # Default behavior: return all
        return (True,
                [LDAPTreeItem(x, self.serverParent, self)
                 for x in resultList], exceptionObject)
コード例 #14
0
ファイル: LDAPTreeItem.py プロジェクト: khosrow/luma-devel
    def delete(self):
        """ Tries to delete the item on the server
        """

        lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta)
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = QtCore.QCoreApplication.translate(
                "LDAPTreeItem", "Could not bind to server.")
            return (False, message, exceptionObject)

        success, exceptionObject = lumaConnection.delete(
            self.smartObject().getDN())
        lumaConnection.unbind()

        if success:
            self.childItems = []
            self.populated = True
            return (True, None, None)
        else:
            message = QtCore.QCoreApplication.translate(
                "LDAPTreeItem",
                "Could not delete entry: " + exceptionObject[0]["desc"])
            return (False, message, exceptionObject)
コード例 #15
0
ファイル: BrowserDialogs.py プロジェクト: khosrow/luma-devel
    def __init__(self, sOList, subTree=True, parent=None):
        """
        subTree:
            False = only sOList
            True = subtree of SOList
        """
        super(DeleteDialog, self).__init__(parent)
        self.setupUi(self)

        self.iconLabel.setPixmap(
            pixmapFromTheme('document-close', ':/icons/64/document-close'))

        self.model = QtGui.QStandardItemModel()

        self.model.setHorizontalHeaderLabels(["DN", "Status"])
        self.items = sOList
        self.deleteDict = {}

        self.subTree = subTree
        self.serverConnections = {}

        if not self.subTree:  # The nodes only
            for smd in self.items:
                self.addItemToModel(smd)
        else:
            # Load subtrees
            for sO in self.items:
                if not self.serverConnections.has_key(sO.serverMeta.name):
                    self.serverConnections[
                        sO.serverMeta.name] = LumaConnectionWrapper(
                            sO.serverMeta)
                    self.serverConnections[sO.serverMeta.name].bindSync()
                con = self.serverConnections[sO.serverMeta.name]
                # Subtree
                success, result, e = con.searchSync(base=sO.getDN(),
                                                    scope=ldap.SCOPE_SUBTREE)
                if success:
                    for i in result:
                        # Subtree only
                        if i.getDN() == sO.getDN():
                            continue
                        self.addItemToModel(i)
                else:
                    continue

        self.deleteItemView.setModel(self.model)
        self.deleteItemView.setAlternatingRowColors(True)
        self.deleteItemView.setUniformRowHeights(True)

        self.hasTriedToDelete = False
        self.passedItemsWasDeleted = False
コード例 #16
0
ファイル: EntryModel.py プロジェクト: einaru/luma
    def deleteObject(self):
        """
        Deletes the remote object that this model represents
        """

        lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, exceptionObject = lumaConnection.delete(self.smartObject.getDN())
        lumaConnection.unbind()

        if success:
            #serverName = self.smartObject.getServerAlias()
            #dn = self.smartObject.getPrettyParentDN()
            #self.model().reloadItem(self.smartObject.parent())
            #self.modelChangedSignal.emit()
            return (True, None, None)
        else:
            message = self.str_DELETE
            return (False, message, exceptionObject)
コード例 #17
0
ファイル: EntryModel.py プロジェクト: einaru/luma
    def reloadModel(self):
        """
        Refreshes the LDAP data from server,
        """
        lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.getDN(), ldap.SCOPE_BASE)
        lumaConnection.unbind()

        if success and (len(resultList) > 0):
            self.smartObject = resultList[0]
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid
            self.EDITED = False
            self.modelChangedSignal.emit(True)
            return (True, None, None)
        else:
            message = self.str_REFRESH
            return (False, message, exceptionObject)
コード例 #18
0
ファイル: ServerTreeItem.py プロジェクト: einaru/luma
    def fetchChildList(self):
        """
        Gets the list of baseDNs for the server and return them.
        """
                
        connection = LumaConnectionWrapper(self.serverMeta)
        
        # If baseDNs are aleady spesified
        if self.serverMeta.autoBase == False:
            self.logger.debug("autoBase=False")
            tmpList = self.serverMeta.baseDN
            
            #Need to bind in order to fetch the data for the baseDNs
            bindSuccess, exceptionObject = connection.bindSync()
            if not bindSuccess:
                self.logger.debug("Bind failed.")
                tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self, self)
                # We're adding the error as LDAPErrorItem-child, so return True
                return (True, [tmp], exceptionObject)
            
        # Else get them from the server
        else:
            self.logger.debug("Using getBaseDNList()")
            #self.isWorking.emit()
            success, tmpList, exceptionObject = connection.getBaseDNListSync()
        
            if not success:
                self.logger.debug("getBaseDNList failed:"+str(exceptionObject))
                tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self, self)
                return (True, [tmp], exceptionObject) #See above
            
            #getBaseDNList calles unbind(), so let's rebind
            connection.bindSync()
        
        self.logger.debug("Entering for-loop")

        # Get the info for the baseDNs
        newChildList = []
        for base in tmpList:
            success, resultList, exceptionObject = connection.searchSync(base, \
                    scope=ldap.SCOPE_BASE,filter='(objectclass=*)', sizelimit=1)
            if not success:
                self.logger.debug("Couldn't search item:"+str(exceptionObject))
                tmp = LDAPErrorItem(str(base+" ["+exceptionObject[0]["desc"]+"]"), self, self)
                newChildList.append(tmp)
                continue
            
            if resultList:
                self.logger.debug("Found item")
                tmp = LDAPTreeItem(resultList[0], self, self)    
                newChildList.append(tmp)
            
        self.logger.debug("End populatItem")
        
        return (True, newChildList, exceptionObject)
コード例 #19
0
    def initModel(self, create=False):
        if create:
            self.EDITED = True
            self.ISLEAF = False
            self.CREATE = True
            self.VALID = True
        else:
            self.EDITED = False
            isLeave = False
            self.smartObject.checkIntegrity()
            self.VALID = self.smartObject.isValid

            serverMeta = self.smartObject.getServerMeta()

            lumaConnection = LumaConnectionWrapper(serverMeta, self)

            bindSuccess, exceptionObject = lumaConnection.bindSync()

            if not bindSuccess:
                message = self.str_BIND
                return (False, message, exceptionObject)

            success, resultList, exceptionObject = lumaConnection.searchSync(
                self.smartObject.dn,
                ldap.SCOPE_ONELEVEL,
                filter="(objectClass=*)",
                attrList=None,
                attrsonly=1,
                sizelimit=1)
            lumaConnection.unbind()

            # Our search succeeded. No errors
            if success:

                # There are no leaves below
                if len(resultList) == 0:
                    self.ISLEAF = True

                # Leaves are below
                else:
                    self.ISLEAF = False

            # Error during search request
            else:
                self.ISLEAF = False
                message = self.str_CHECK_LEAF
                self.modelChangedSignal.emit(True)
                return (False, message, exceptionObject)

            self.CREATE = False

        self.modelChangedSignal.emit(True)
        return (True, None, None)
コード例 #20
0
    def saveModel(self):
        """
        Save changes to the current object.
        """

        lumaConnection = LumaConnectionWrapper(
            self.smartObject.getServerMeta())
        bindSuccess, exceptionObject = lumaConnection.bindSync()

        if not bindSuccess:
            message = self.str_BIND
            return (False, message, exceptionObject)

        if self.CREATE:
            success, exceptionObject = lumaConnection.addDataObject(
                self.smartObject)
            lumaConnection.unbind()

            if success:
                #self.CREATE = False
                self.EDITED = False
                self.modelChangedSignal.emit(False)
                return (True, None, None)
            else:
                message = self.str_ADD
                return (False, message, exceptionObject)
        else:
            success, exceptionObject = lumaConnection.updateDataObject(
                self.smartObject)
            lumaConnection.unbind()
            if success:
                self.EDITED = False
                self.modelChangedSignal.emit(False)
                return (True, None, None)
            else:
                message = self.str_SAVE
                return (False, message, exceptionObject)
コード例 #21
0
ファイル: Search.py プロジェクト: einaru/luma
    def __init__(self, parent, server, **kwargs):
        """
        :param parent: the connection object to perform the search
        :type parent: QObject
        :param server: the sever to search on.
        :type server: ServerObject
        :param **kwargs: a dict with keyword arguments to pass to the
         LDAP search operation.
        :type **kwargs: dict
        """
        super(Search, self).__init__(parent)
        self.filter = kwargs['filter']
        self.connection = LumaConnectionWrapper(server, self)
        self.connection.searchFinished.connect(self.onSearchFinished)

        bindSuccess, e = self.connection.bindSync()
        if not bindSuccess:
            msg = 'Unable to bind to {0}. Reason\n{1}'
            self.__logger.error(msg.format(server, str(e)))
        else:
            self.connection.searchAsync(**kwargs)
コード例 #22
0
ファイル: BrowserView.py プロジェクト: khosrow/luma-devel
    def __exportSelection(self, scope=0):
        """Slot for the context menu.

        Opens the ExportDialog with the selected entries, giving the
        user the option to validate the selection before exporting.

        :param scope: The scope selection.
         0 = SCOPE_BASE -> Item(s),
         1 = SCOPE_ONELEVEL -> Subtree(s);
         2 = SCOPE_SUBTREE -> Subtree(s) with parent
        :type scope: int
        """
        exportObjects = []
        msg = ''

        self.setBusy(True)
        for index in self.selection:
            smartObject = index.internalPointer().smartObject()

            serverName = smartObject.getServerAlias()
            dn = smartObject.getDN()
            serverObject = self.serverList.getServerObject(serverName)
            con = LumaConnectionWrapper(serverObject, self)

            # For both subtree and subtree with parent, we fetch the
            # whole subtree including the parent, with a basic sync
            # search operation. Then, if only the subtree is to be
            # exported, we remove the smartObject(s) selected.
            if scope > 0:
                pass

                # Do a search on the whole subtree
                # 2 = ldap.SCOPE_SUBTREE
                #elif scope == 2:

                success, e = con.bindSync()

                if not success:
                    self.__logger.error(str(e))
                    continue
                success, result, e = con.searchSync(base=dn, scope=2)

                if success:
                    exportObjects.extend(result)
                else:
                    self.__logger.error(str(e))

                # If only the subtree is to be selected, we remove
                # the parent, which happens to be the smartObject(s)
                # initialy selected.
                if scope == 1:
                    exportObjects.remove(smartObject)

            # For scope == 0 we need not do any LDAP search operation
            # because we already got what we need
            else:
                exportObjects.append(smartObject)

        # Initialize the export dialog
        # and give it the items for export
        dialog = ExportDialog(msg)
        dialog.setExportItems(exportObjects)
        self.setBusy(False)
        dialog.exec_()
コード例 #23
0
ファイル: BrowserView.py プロジェクト: einaru/luma
    def __exportSelection(self, scope=0):
        """Slot for the context menu.

        Opens the ExportDialog with the selected entries, giving the
        user the option to validate the selection before exporting.

        :param scope: The scope selection.
         0 = SCOPE_BASE -> Item(s),
         1 = SCOPE_ONELEVEL -> Subtree(s);
         2 = SCOPE_SUBTREE -> Subtree(s) with parent
        :type scope: int
        """
        exportObjects = []
        msg = ''

        self.setBusy(True)
        for index in self.selection:
            smartObject = index.internalPointer().smartObject()

            serverName = smartObject.getServerAlias()
            dn = smartObject.getDN()
            serverObject = self.serverList.getServerObject(serverName)
            con = LumaConnectionWrapper(serverObject, self)

            # For both subtree and subtree with parent, we fetch the
            # whole subtree including the parent, with a basic sync
            # search operation. Then, if only the subtree is to be
            # exported, we remove the smartObject(s) selected.
            if scope > 0:
                pass

            # Do a search on the whole subtree
            # 2 = ldap.SCOPE_SUBTREE
            #elif scope == 2:

                success, e = con.bindSync()

                if not success:
                    self.__logger.error(str(e))
                    continue
                success, result, e = con.searchSync(base=dn, scope=2)

                if success:
                    exportObjects.extend(result)
                else:
                    self.__logger.error(str(e))

                # If only the subtree is to be selected, we remove
                # the parent, which happens to be the smartObject(s)
                # initialy selected.
                if scope == 1:
                    exportObjects.remove(smartObject)

            # For scope == 0 we need not do any LDAP search operation
            # because we already got what we need
            else:
                exportObjects.append(smartObject)

        # Initialize the export dialog
        # and give it the items for export
        dialog = ExportDialog(msg)
        dialog.setExportItems(exportObjects)
        self.setBusy(False)
        dialog.exec_()
コード例 #24
0
ファイル: ServerTreeItem.py プロジェクト: khosrow/luma-devel
    def fetchChildList(self):
        """
        Gets the list of baseDNs for the server and return them.
        """

        connection = LumaConnectionWrapper(self.serverMeta)

        # If baseDNs are aleady spesified
        if self.serverMeta.autoBase == False:
            self.logger.debug("autoBase=False")
            tmpList = self.serverMeta.baseDN

            #Need to bind in order to fetch the data for the baseDNs
            bindSuccess, exceptionObject = connection.bindSync()
            if not bindSuccess:
                self.logger.debug("Bind failed.")
                tmp = LDAPErrorItem(
                    str("[" + exceptionObject[0]["desc"] + "]"), self, self)
                # We're adding the error as LDAPErrorItem-child, so return True
                return (True, [tmp], exceptionObject)

        # Else get them from the server
        else:
            self.logger.debug("Using getBaseDNList()")
            #self.isWorking.emit()
            success, tmpList, exceptionObject = connection.getBaseDNListSync()

            if not success:
                self.logger.debug("getBaseDNList failed:" +
                                  str(exceptionObject))
                tmp = LDAPErrorItem(
                    str("[" + exceptionObject[0]["desc"] + "]"), self, self)
                return (True, [tmp], exceptionObject)  #See above

            #getBaseDNList calles unbind(), so let's rebind
            connection.bindSync()

        self.logger.debug("Entering for-loop")

        # Get the info for the baseDNs
        newChildList = []
        for base in tmpList:
            success, resultList, exceptionObject = connection.searchSync(base, \
                    scope=ldap.SCOPE_BASE,filter='(objectclass=*)', sizelimit=1)
            if not success:
                self.logger.debug("Couldn't search item:" +
                                  str(exceptionObject))
                tmp = LDAPErrorItem(
                    str(base + " [" + exceptionObject[0]["desc"] + "]"), self,
                    self)
                newChildList.append(tmp)
                continue

            if resultList:
                self.logger.debug("Found item")
                tmp = LDAPTreeItem(resultList[0], self, self)
                newChildList.append(tmp)

        self.logger.debug("End populatItem")

        return (True, newChildList, exceptionObject)