Ejemplo n.º 1
0
 def get_suite_state_summary(self):
     return unicode_encode(
         self.call_server_func(COMMS_STATE_OBJ_NAME, "get_state_summary"))
Ejemplo n.º 2
0
 def get_suite_state_summary(self):
     return unicode_encode(
         self.call_server_func(COMMS_STATE_OBJ_NAME, "get_state_summary"))
Ejemplo n.º 3
0
    def clear(self, point_strings=None, namespaces=None, cancel_settings=None):
        """Clear settings globally, or for listed namespaces and/or points.

        Return a tuple (modified_settings, bad_options), where:
        * modified_settings is similar to the return value of the "put" method,
          but for removed settings.
        * bad_options is a dict in the form:
              {"point_strings": ["20020202", ..."], ...}
          The dict is only populated if there are options not associated with
          previous broadcasts. The keys can be:
          * point_strings: a list of bad point strings.
          * namespaces: a list of bad namespaces.
          * cancel: a list of tuples. Each tuple contains the keys of a bad
            setting.
        """

        if hasattr(cherrypy.request, "json"):
            point_strings = (
                cherrypy.request.json.get("point_strings", point_strings))
            namespaces = (
                cherrypy.request.json.get("namespaces", namespaces))
            cancel_settings = (
                cherrypy.request.json.get("cancel_settings", cancel_settings))
            point_strings = unicode_encode(point_strings)
            namespaces = unicode_encode(namespaces)
            cancel_settings = unicode_encode(cancel_settings)
        # If cancel_settings defined, only clear specific settings
        cancel_keys_list = self._settings_to_keys_list(cancel_settings)

        # Clear settings
        modified_settings = []
        with self.lock:
            for point_string, point_string_settings in self.settings.items():
                if point_strings and point_string not in point_strings:
                    continue
                for namespace, namespace_settings in (
                        point_string_settings.items()):
                    if namespaces and namespace not in namespaces:
                        continue
                    stuff_stack = [([], namespace_settings)]
                    while stuff_stack:
                        keys, stuff = stuff_stack.pop()
                        for key, value in stuff.items():
                            if isinstance(value, dict):
                                stuff_stack.append((keys + [key], value))
                            elif (not cancel_keys_list or
                                    keys + [key] in cancel_keys_list):
                                stuff[key] = None
                                setting = {key: value}
                                for rkey in reversed(keys):
                                    setting = {rkey: setting}
                                modified_settings.append(
                                    (point_string, namespace, setting))

        # Prune any empty branches
        bad_options = self._get_bad_options(
            self._prune(), point_strings, namespaces, cancel_keys_list)

        # Log the broadcast
        self._append_db_queue(modified_settings, is_cancel=True)
        self.log.info(
            get_broadcast_change_report(modified_settings, is_cancel=True))
        if bad_options:
            self.log.error(get_broadcast_bad_options_report(bad_options))

        return (modified_settings, bad_options)
Ejemplo n.º 4
0
    def put(self, point_strings=None, namespaces=None, settings=None,
            not_from_client=False):
        """Add new broadcast settings (server side interface).

        Return a tuple (modified_settings, bad_options) where:
          modified_settings is list of modified settings in the form:
            [("20200202", "foo", {"command scripting": "true"}, ...]
          bad_options is as described in the docstring for self.clear().
        """
        check_access_priv(self, 'full-control')
        self.report('broadcast_put')
        if not not_from_client:
            point_strings = (
                cherrypy.request.json.get("point_strings", point_strings))
            namespaces = (
                cherrypy.request.json.get("namespaces", namespaces))
            settings = (
                cherrypy.request.json.get("settings", settings))
            point_strings = unicode_encode(point_strings)
            namespaces = unicode_encode(namespaces)
            settings = unicode_encode(settings)

        modified_settings = []
        bad_point_strings = []
        bad_namespaces = []

        with self.lock:
            for setting in settings:
                for point_string in point_strings:
                    # Standardise the point and check its validity.
                    bad_point = False
                    try:
                        point_string = standardise_point_string(point_string)
                    except Exception as exc:
                        if point_string != '*':
                            bad_point_strings.append(point_string)
                            bad_point = True
                    if not bad_point and point_string not in self.settings:
                        self.settings[point_string] = {}
                    for namespace in namespaces:
                        if namespace not in self.linearized_ancestors:
                            bad_namespaces.append(namespace)
                        elif not bad_point:
                            if namespace not in self.settings[point_string]:
                                self.settings[point_string][namespace] = {}
                            self._addict(
                                self.settings[point_string][namespace],
                                setting)
                            modified_settings.append(
                                (point_string, namespace, setting))

        # Log the broadcast
        self._append_db_queue(modified_settings)
        self.log.info(get_broadcast_change_report(modified_settings))

        bad_options = {}
        if bad_point_strings:
            bad_options["point_strings"] = bad_point_strings
        if bad_namespaces:
            bad_options["namespaces"] = bad_namespaces
        return modified_settings, bad_options
Ejemplo n.º 5
0
    def clear(self, point_strings=None, namespaces=None, cancel_settings=None):
        """Clear settings globally, or for listed namespaces and/or points.

        Return a tuple (modified_settings, bad_options), where:
        * modified_settings is similar to the return value of the "put" method,
          but for removed settings.
        * bad_options is a dict in the form:
              {"point_strings": ["20020202", ..."], ...}
          The dict is only populated if there are options not associated with
          previous broadcasts. The keys can be:
          * point_strings: a list of bad point strings.
          * namespaces: a list of bad namespaces.
          * cancel: a list of tuples. Each tuple contains the keys of a bad
            setting.
        """

        if hasattr(cherrypy.request, "json"):
            point_strings = (cherrypy.request.json.get("point_strings",
                                                       point_strings))
            namespaces = (cherrypy.request.json.get("namespaces", namespaces))
            cancel_settings = (cherrypy.request.json.get(
                "cancel_settings", cancel_settings))
            point_strings = unicode_encode(point_strings)
            namespaces = unicode_encode(namespaces)
            cancel_settings = unicode_encode(cancel_settings)
        # If cancel_settings defined, only clear specific settings
        cancel_keys_list = self._settings_to_keys_list(cancel_settings)

        # Clear settings
        modified_settings = []
        with self.lock:
            for point_string, point_string_settings in self.settings.items():
                if point_strings and point_string not in point_strings:
                    continue
                for namespace, namespace_settings in (
                        point_string_settings.items()):
                    if namespaces and namespace not in namespaces:
                        continue
                    stuff_stack = [([], namespace_settings)]
                    while stuff_stack:
                        keys, stuff = stuff_stack.pop()
                        for key, value in stuff.items():
                            if isinstance(value, dict):
                                stuff_stack.append((keys + [key], value))
                            elif (not cancel_keys_list
                                  or keys + [key] in cancel_keys_list):
                                stuff[key] = None
                                setting = {key: value}
                                for rkey in reversed(keys):
                                    setting = {rkey: setting}
                                modified_settings.append(
                                    (point_string, namespace, setting))

        # Prune any empty branches
        bad_options = self._get_bad_options(self._prune(), point_strings,
                                            namespaces, cancel_keys_list)

        # Log the broadcast
        self._append_db_queue(modified_settings, is_cancel=True)
        self.log.info(
            get_broadcast_change_report(modified_settings, is_cancel=True))
        if bad_options:
            self.log.error(get_broadcast_bad_options_report(bad_options))

        return (modified_settings, bad_options)
Ejemplo n.º 6
0
    def put(self,
            point_strings=None,
            namespaces=None,
            settings=None,
            not_from_client=False):
        """Add new broadcast settings (server side interface).

        Return a tuple (modified_settings, bad_options) where:
          modified_settings is list of modified settings in the form:
            [("20200202", "foo", {"command scripting": "true"}, ...]
          bad_options is as described in the docstring for self.clear().
        """
        check_access_priv(self, 'full-control')
        self.report('broadcast_put')
        if not not_from_client:
            point_strings = (cherrypy.request.json.get("point_strings",
                                                       point_strings))
            namespaces = (cherrypy.request.json.get("namespaces", namespaces))
            settings = (cherrypy.request.json.get("settings", settings))
            point_strings = unicode_encode(point_strings)
            namespaces = unicode_encode(namespaces)
            settings = unicode_encode(settings)

        modified_settings = []
        bad_point_strings = []
        bad_namespaces = []

        with self.lock:
            for setting in settings:
                for point_string in point_strings:
                    # Standardise the point and check its validity.
                    bad_point = False
                    try:
                        point_string = standardise_point_string(point_string)
                    except Exception as exc:
                        if point_string != '*':
                            bad_point_strings.append(point_string)
                            bad_point = True
                    if not bad_point and point_string not in self.settings:
                        self.settings[point_string] = {}
                    for namespace in namespaces:
                        if namespace not in self.linearized_ancestors:
                            bad_namespaces.append(namespace)
                        elif not bad_point:
                            if namespace not in self.settings[point_string]:
                                self.settings[point_string][namespace] = {}
                            self._addict(
                                self.settings[point_string][namespace],
                                setting)
                            modified_settings.append(
                                (point_string, namespace, setting))

        # Log the broadcast
        self._append_db_queue(modified_settings)
        self.log.info(get_broadcast_change_report(modified_settings))

        bad_options = {}
        if bad_point_strings:
            bad_options["point_strings"] = bad_point_strings
        if bad_namespaces:
            bad_options["namespaces"] = bad_namespaces
        return modified_settings, bad_options