Esempio n. 1
0
    def _build_calculated(self):

        self._unresolved = dict()
        self._not_yet_resolved = dict()
        self._combined = dict()
        self._resolved = dict()

        for section_name, section_data \
        in self._data.items ():

            self._unresolved[section_name] = dict()
            self._not_yet_resolved[section_name] = dict()
            self._combined[section_name] = dict()
            self._resolved[section_name] = dict()

            for item_name, item_data \
            in section_data.items ():

                self._unresolved[section_name][item_name] = (
                    wbs.deep_copy(item_data))

                self._not_yet_resolved[section_name][item_name] = (
                    wbs.deep_copy(item_data))

                self._combined[section_name][item_name] = (
                    wbs.deep_copy(item_data))

                full_name = ("%s_%s" % (section_name, item_name))

                self._unresolved[full_name] = (wbs.deep_copy(item_data))

                self._combined[full_name] = (wbs.deep_copy(item_data))
	def load_resources_1 (self):

		for resource_name, resource_data \
		in self.context.resources.get_all_list_quick ():

			resource_data = (
				wbs.deep_copy (
					resource_data))

			# check basics

			if not "identity" in resource_data:
				raise Exception ()

			if resource_data ["identity"] ["type"] != "resource":

				raise Exception (
					"Invalid type '%s' for resource '%s'" % (
						resource_data ["identity"] ["type"],
						resource_name))

			# create resource

			self.add_resource (
				resource_data)
Esempio n. 3
0
    def _build_data(self):

        self._data = (wbs.deep_copy(self._class.data()))

        self._data["identity"] = (wbs.deep_copy(
            self._class.resource_identity()))

        # add resource data

        for section_name, section_data \
        in self._raw_data.items ():

            if section_name != "identity" \
            and section_name not in self._data:

                raise Exception(
                    "Resource %s contains invalid section %s for class %s" %
                    (self._name, section_name, self._class.name()))

            for item_name, item_data \
            in section_data.items ():

                self._data[section_name][item_name] = (
                    wbs.deep_copy(item_data))
Esempio n. 4
0
    def load_resources_1(self):

        for resource_name, resource_data \
        in self.context.resources.get_all_list_quick ():

            resource_data = (wbs.deep_copy(resource_data))

            # check basics

            if not "identity" in resource_data:
                raise Exception()

            if resource_data["identity"]["type"] != "resource":

                raise Exception(
                    "Invalid type '%s' for resource '%s'" %
                    (resource_data["identity"]["type"], resource_name))

            # create resource

            self.add_resource(resource_name, resource_data)
Esempio n. 5
0
	def _build_identity (self):

		self._namespace = (
			self._inventory.namespaces [
				self._raw_data ["class"] ["namespace"]])

		self._groups = (
			self._raw_data ["class"].get (
				"groups",
				list ()))

		if "parent_namespace" in self._raw_data ["class"]:

			self._parent_namespace = (
				self._inventory.namespaces [
					self._raw_data ["class"] ["parent_namespace"]])

		else:

			self._parent_namespace = None

		self._resource_identity = (
			wbs.deep_copy (
				self._raw_data ["class"].get (
					"resource_identity",
					dict ())))

		self._resource_identity ["namespace"] = (
			self._raw_data ["class"] ["namespace"])

		self._references = (
			self._raw_data ["class"].get (
				"references",
				list ()))

		self._back_references = (
			self._raw_data ["class"].get (
				"back_references",
				list ()))
    def _build_data(self):

        self._data = dict()

        for section_name, section_data \
        in self._raw_data.items ():

            if not isinstance(section_data, dict):

                raise Exception()

            if section_name in ["identity", "namespace"]:

                continue

            self._data[section_name] = dict()

            for item_name, item_data \
            in section_data.items ():

                self._data[section_name][item_name] = (
                    wbs.deep_copy(item_data))
	def __init__ (self, inventory, data):

		self.data = data

		self.identity_class = data ["identity"] ["class"]
		self.identity_name = data ["identity"] ["name"]
		self.identity_parent = data ["identity"].get ("parent")

		self.resource_class = (
			inventory.classes [self.identity_class])

		self.identity_namespace = self.resource_class.namespace

		self.unique_name = "/".join ([
			self.identity_namespace,
			self.identity_name,
		])

		# add resource data

		self.unresolved = wbs.deep_copy (data)
		self.not_yet_resolved = wbs.deep_copy (data)
		self.combined = wbs.deep_copy (data)
		self.resolved = dict ()

		for section_name, section_data in data.items ():

			if not isinstance (section_data, dict):
				continue

			for item_name, item_value \
			in section_data.items ():

				self.unresolved [section_name + "_" + item_name] = (
					item_value)

				self.combined [section_name + "_" + item_name] = (
					item_value)

		# add class data

		for class_prefix, class_data \
		in self.resource_class.items ():

			if class_prefix in [ "identity", "class" ]:
				continue

			if not class_prefix in self.unresolved:

				self.unresolved [class_prefix] = (
					collections.OrderedDict ())

			if not class_prefix in self.not_yet_resolved:

				self.not_yet_resolved [class_prefix] = (
					collections.OrderedDict ())

			if not class_prefix in self.combined:

				self.combined [class_prefix] = (
					collections.OrderedDict ())

			if not isinstance (
				self.unresolved [class_prefix],
				dict):

				raise Exception (
					"Not a dictionary: %s.%s" % (
						self.unique_name,
						class_prefix))

			for section_name, section_value \
			in class_data.items ():

				if section_name in self.unresolved [class_prefix]:
					continue

				self.unresolved [class_prefix] [section_name] = (
					section_value)

				self.not_yet_resolved [class_prefix] [section_name] = (
					section_value)

				self.combined [class_prefix] [section_name] = (
					section_value)

				full_name = (
					"%s_%s" % (
						class_prefix,
						section_name))

				self.unresolved [full_name] = (
					section_value)

				self.combined [full_name] = (
					section_value)

		for identity_name, identity_value \
		in self.resource_class.resource_identity.items ():

			if identity_name \
			not in self.unresolved ["identity"]:

				if identity_name in self.unresolved ["identity"]:
					continue

				identity_full_name = (
					"identity_%s" % (
						identity_name))

				self.unresolved ["identity"] [identity_name] = (
					identity_value)

				self.not_yet_resolved ["identity"] [identity_name] = (
					identity_value)

				self.combined ["identity"] [identity_name] = (
					identity_value)

				self.unresolved [identity_full_name] = (
					identity_value)

				self.combined [identity_full_name] = (
					identity_value)
Esempio n. 8
0
	def _build_data (self):

		self._data = (
			wbs.deep_copy (
				self._namespace.data ()))

		# add class data

		for section_name, section_data \
		in self._raw_data.items ():

			if not isinstance (section_data, dict):

				raise Exception ()

			if section_name in [ "identity", "class" ]:

				continue

			if section_name \
			not in self._context.project_metadata ["resource_section_names"]:

				raise Exception (
					"Class %s contains unrecognised section: %s" % (
						self.name (),
						section_name))

			self._data.setdefault (
				section_name,
				dict ())

			for item_name, item_data \
			in section_data.items ():

				self._data [section_name] [item_name] = (
					wbs.deep_copy (
						item_data))

		# add defaults

		for section_name, section_data \
		in self._context.project_defaults.items ():

			if section_name not in self._data:

				continue

			if not isinstance (section_data, dict):

				raise Exception (
					"Defaults section is %s but should be dictionary: %s" % (
						type (section_data),
						section_name))

			for item_name, item_data \
			in section_data.items ():

				if item_name in self._data [section_name]:

					continue

				self._data [section_name] [item_name] = (
					wbs.deep_copy (
						item_data))