示例#1
0
	def loadModules(self):

		# TODO
		# This variable seems to be used nowhere. SHOULD BE REMOVED...
		
		nbp = 40

		# Parse modules conf file 
		# return a description of each module and global namespaces with
		# their associated prefix (used in xpath)
		#moduleDescrList, self.namespaces = ModuleReader.getInstance().readModules()
		moduleDescrList = ModuleReader.getInstance().readModules()
		

		# Create modules

		for moduleDescr in moduleDescrList:
			# Set the namespace prefix list
			self.prefixes[moduleDescr["pref"]] = moduleDescr["namespace"]
			# Create the new module from its descriptor
			newModule = ModuleFactory.getInstance().createModule(moduleDescr)
			if newModule == None:
				print moduleDescr
			else:
				# Add the module to the module list
				self.modules.append(newModule)
    def loadModule(self, name):

        for module in self.modules:
            if module.name == name:
                # Should return an error, saying that this module is already loaded.
                return 2

        # Parse modules conf file
        moduleDescrList = ModuleReader.getInstance().readModules()

        # Create modules
        for moduleDescr in moduleDescrList:
            if moduleDescr["name"] == name:
                # Set the namespace prefix list
                self.prefixes[moduleDescr["pref"]] = moduleDescr["namespace"]
                # Create the new module from its descriptor
                newModule = ModuleFactory.getInstance().createModule(
                    moduleDescr)
                if newModule == None:
                    print moduleDescr
                    return 0
                else:
                    # Add the module to the module list
                    self.modules.append(newModule)
                    dm = DatastoreManager.getInstance()

                    # Build the parent XML nodes from the root up to the module node.
                    dm.initConfigModule(newModule, C.RUNNING, "config")
                    dm.initConfigModule(newModule, C.RUNNING, "state")
                    dm.initConfigModule(newModule, C.STARTUP, "config")
                    dm.initConfigModule(newModule, C.STARTUP, "state")

                    # Query the module to update the config.
                    dm.updateConfig(C.RUNNING, "config")
                    dm.updateConfig(C.RUNNING, "state")
                    dm.updateConfig(C.STARTUP, "config")
                    dm.updateConfig(C.STARTUP, "state")

                    # Success
                    return 1

        return 3
    def loadModules(self):

        # This variable seems to be used nowhere. SHOULD BE REMOVED...
        nbp = 40

        # Parse modules conf file
        moduleDescrList = ModuleReader.getInstance().readModules()

        # Create modules

        for moduleDescr in moduleDescrList:
            # Set the namespace prefix list
            self.prefixes[moduleDescr["pref"]] = moduleDescr["namespace"]
            # Create the new module from its descriptor
            newModule = ModuleFactory.getInstance().createModule(moduleDescr)
            if newModule == None:
                print moduleDescr
            else:
                # Add the module to the module list
                self.modules.append(newModule)

import ModuleReader

mr = ModuleReader.getInstance()

l = mr.readModules()
print l

mr.addModule("name", "xpath", "namespace", "n1", 15, {"ip":6})
mr.addModule("name2", "xpath2", "namespace2", "n2", 17, {})
mr.writeModules()

mr.removeModule("name2")
mr.writeModules()