Logo Search packages:      
Sourcecode: qm version File versions

def qm::test::cmdline::QMTest::__ExecuteRegister (   self  )  [private]

Register a new extension class.

Definition at line 1054 of file cmdline.py.

01054                                :
        """Register a new extension class."""

        # Make sure that the KIND and CLASS were specified.
        if (len(self.__arguments) != 2):
            return 2
        kind = self.__arguments[0]
        class_name = self.__arguments[1]

        # Check that the KIND is valid.
        if kind not in base.extension_kinds:
            raise qm.cmdline.CommandError, \
                  qm.error("invalid extension kind",
                           kind = kind)

        # Check that the CLASS_NAME is well-formed.
        if class_name.count('.') != 1:
            raise qm.cmdline.CommandError, \
                  qm.error("invalid class name",
                           class_name = class_name)
        module, name = class_name.split('.')

        # Try to load the database.  It may provide additional
        # directories to search.
            database = self.GetDatabase()
            database = None
        # Hunt through all of the extension class directories looking
        # for an appropriately named module.
        found = None
        directories = get_extension_directories(kind, database,
        for directory in directories:
            for ext in (".py", ".pyc", ".pyo"):
                file_name = os.path.join(directory, module + ext)
                if os.path.exists(file_name):
                    found = file_name
            if found:

        # If we could not find the module, issue an error message.
        if not found:
            raise qm.QMException, \
                  qm.error("module does not exist",
                           module = module)

        # Inform the user of the location in which QMTest found the
        # module.  (Sometimes, there might be another module with the
        # same name in the path.  Telling the user where we've found
        # the module will help the user to deal with this situation.)
                           (qm.message("loading class",
                                       class_name = name,
                                       file_name = found)))
        # We have found the module.  Try loading it.
        extension_class = get_extension_class_from_directory(class_name,

        # Create or update the classes.qmc file.
        classes_file_name = os.path.join(directory, "classes.qmc")
        # Create a new DOM document for the class directory.
        document = (qm.xmlutil.create_dom_document
                    (public_id = "Class-Directory",
        # Copy entries from the old file to the new one.
        extensions \
            = qm.test.base.get_extension_class_names_in_directory(directory)
        for k, ns in extensions.iteritems():
            for n in ns:
                # Remove previous entries for the class being added.
                if k == kind and n == class_name:
                element = document.createElement("class")
                element.setAttribute("kind", k)
                element.setAttribute("name", n)

        # Add an entry for the new element.
        element = document.createElement("class")
        element.setAttribute("kind", kind)
        element.setAttribute("name", class_name)

        # Write out the file.
        document.writexml(open(classes_file_name, "w"),
                          addindent = " ", newl = "\n")

        return 0

    def __ExecuteSummarize(self):

Generated by  Doxygen 1.6.0   Back to index