Пример #1
0
    def parseXML(self, node):
        """
        Parse an entire XML directory.

        @param node: the XML element for the root of the directory file.
        @type node: C{xml.etree.ElementTree.Element}
        """
        if node.tag == tags.ELEMENT_ACCOUNTS:
            self.realm = node.get(tags.ATTRIBUTE_REALM, "")

            for child in node.getchildren():
                record = XMLRecord()
                record.parseXML(child)
                self.records[record.recordType].append(record)
Пример #2
0
    def parseXML(self, node):
        """
        Parse an entire XML directory.

        @param node: the XML element for the root of the directory file.
        @type node: C{xml.etree.ElementTree.Element}
        """
        if node.tag == tags.ELEMENT_ACCOUNTS:
            self.realm = node.get(tags.ATTRIBUTE_REALM, "")

            for child in node.getchildren():
                record = XMLRecord()
                record.parseXML(child)
                self.records[record.recordType].append(record)
Пример #3
0
    def checkXML(self, x):

        x = x.replace("\n", "\r\n")

        # Parse the XML data
        a = XMLRecord()
        a.parseXML(XML(x))

        # Generate the XML data
        node = a.writeXML()
        os = StringIO()
        xmldoc = BetterElementTree(node)
        xmldoc.writeUTF8(os)

        # Verify data
        self.assertEqual(os.getvalue(), x)
Пример #4
0
    def checkXML(self, x):

        x = x.replace("\n", "\r\n")

        # Parse the XML data
        a = XMLRecord()
        a.parseXML(XML(x))

        # Generate the XML data
        node = a.writeXML()
        os = StringIO()
        xmldoc = BetterElementTree(node)
        xmldoc.writeUTF8(os)

        # Verify data
        self.assertEqual(os.getvalue(), x)
Пример #5
0
    def doAdd(self):
        """
        Prompts the user for details and then adds a new record to the directory.
        """

        # Prompt for each thing we need in the record
        record = XMLRecord()
        record.recordType = self.recordType
        print "Enter the fields for the record (ctrl-D to stop at any time)"
        try:
            # uid
            while True:
                record.uid = raw_input("Id: ")
                if not record.uid:
                    print "A valid uid is required. Please try again."
                elif self.directory.containsRecord(self.recordType, record.uid):
                    print "Record uid: '%s' of type: '%s' does already exists in the directory." % (record.uid, self.recordType,)
                else:
                    break

            # guid
            while True:
                record.guid = raw_input("GUID [leave empty to auto-generate]: ")
                if record.guid and self.directory.containsGUID(record.guid):
                    print "GUID: '%s' already used in the directory" % (record.guid,)
                else:
                    break

            # password
            record.password = self.promptPassword()

            # name
            record.name = raw_input("Name: ")

            # members
            if self.recordType in (recordtypes.recordType_groups,):
                record.members = self.getMemberList("Enter members of this group", "Member", "members")

            # cuaddr
            while True:
                cuaddr = raw_input("Calendar user address [leave empty to stop adding addresses]: ")
                if cuaddr:
                    record.calendarUserAddresses.add(cuaddr)
                else:
                    break

            # auto-schedule
            if self.recordType in (recordtypes.recordType_locations, recordtypes.recordType_resources,):
                auto_schedule = raw_input("Turn on automatic scheduling [y/n]?: ")
                if auto_schedule == "y":
                    record.autoSchedule = True

            # enabled for calendaring
            if self.recordType in (recordtypes.recordType_users, recordtypes.recordType_groups,):
                enable_calendars = raw_input("Create calendar account rather than access-only account [y/n]?: ")
                if enable_calendars == "n":
                    record.enabledForCalendaring = False

            # proxies
            if self.recordType in (recordtypes.recordType_locations, recordtypes.recordType_resources,):
                record.proxies = self.getMemberList("Enter proxies of this location or resource", "Proxy", "proxies")

        except EOFError:
            return 0

        # Now validate the record and save it
        if not record.guid:
            record.guid = str(uuid4())

        self.directory.addRecord(record)

        return 1
    def doAdd(self):
        """
        Prompts the user for details and then adds a new record to the directory.
        """

        # Prompt for each thing we need in the record
        record = XMLRecord()
        record.recordType = self.recordType
        print "Enter the fields for the record (ctrl-D to stop at any time)"
        try:
            # uid
            while True:
                record.uid = raw_input("Id: ")
                if not record.uid:
                    print "A valid uid is required. Please try again."
                elif self.directory.containsRecord(self.recordType,
                                                   record.uid):
                    print "Record uid: '%s' of type: '%s' does already exists in the directory." % (
                        record.uid,
                        self.recordType,
                    )
                else:
                    break

            # guid
            while True:
                record.guid = raw_input(
                    "GUID [leave empty to auto-generate]: ")
                if record.guid and self.directory.containsGUID(record.guid):
                    print "GUID: '%s' already used in the directory" % (
                        record.guid, )
                else:
                    break

            # password
            record.password = self.promptPassword()

            # name
            record.name = raw_input("Name: ")

            # members
            if self.recordType in (recordtypes.recordType_groups, ):
                record.members = self.getMemberList(
                    "Enter members of this group", "Member", "members")

            # cuaddr
            while True:
                cuaddr = raw_input(
                    "Calendar user address [leave empty to stop adding addresses]: "
                )
                if cuaddr:
                    record.calendarUserAddresses.add(cuaddr)
                else:
                    break

            # auto-schedule
            if self.recordType in (
                    recordtypes.recordType_locations,
                    recordtypes.recordType_resources,
            ):
                auto_schedule = raw_input(
                    "Turn on automatic scheduling [y/n]?: ")
                if auto_schedule == "y":
                    record.autoSchedule = True

            # enabled for calendaring
            if self.recordType in (
                    recordtypes.recordType_users,
                    recordtypes.recordType_groups,
            ):
                enable_calendars = raw_input(
                    "Create calendar account rather than access-only account [y/n]?: "
                )
                if enable_calendars == "n":
                    record.enabledForCalendaring = False

            # proxies
            if self.recordType in (
                    recordtypes.recordType_locations,
                    recordtypes.recordType_resources,
            ):
                record.proxies = self.getMemberList(
                    "Enter proxies of this location or resource", "Proxy",
                    "proxies")

        except EOFError:
            return 0

        # Now validate the record and save it
        if not record.guid:
            record.guid = str(uuid4())

        self.directory.addRecord(record)

        return 1