Beispiel #1
0
    def to_value_str(cls, value):
        """
        :param str value: Value associated with a key.
        :return:
            String that suitable for a value of a key.
            Return ``"NULL"`` if the value is |None|.
        :rtype: str

        :Examples:

            >>> from simplesqlite.sqlquery import SqlQuery
            >>> SqlQuery.to_value_str(1.2)
            '1.2'
            >>> SqlQuery.to_value_str("value")
            "'value'"
            >>> SqlQuery.to_value_str(None)
            'NULL'
        """

        if value is None:
            return "NULL"

        if dataproperty.is_integer(value) or dataproperty.is_float(value):
            return str(value)

        return "'%s'" % (value)
    def __get_filter(self, device):
        qdisc_parser = tcconfig.parser.TcQdiscParser()
        filter_parser = tcconfig.parser.TcFilterParser()

        # parse qdisc ---
        command = "tc qdisc show dev %s" % (device)
        proc = self.__subproc_wrapper.popen_command(command)
        qdisc_stdout, _stderr = proc.communicate()
        qdisc_param = qdisc_parser.parse(qdisc_stdout)

        # parse filter ---
        command = "tc filter show dev %s" % (device)
        proc = self.__subproc_wrapper.popen_command(command)
        filter_stdout, _stderr = proc.communicate()

        filter_table = {}

        for filter_param in filter_parser.parse_filter(filter_stdout):
            key_item_list = []

            if dataproperty.is_not_empty_string(filter_param.get("network")):
                key_item_list.append("network=" + filter_param.get("network"))

            if dataproperty.is_integer(filter_param.get("port")):
                key_item_list.append("port=%d" % (filter_param.get("port")))

            filter_key = ", ".join(key_item_list)
            filter_table[filter_key] = {}
            if filter_param.get("flowid") == qdisc_param.get("parent"):
                work_qdisc_param = dict(qdisc_param)
                del work_qdisc_param["parent"]
                filter_table[filter_key] = work_qdisc_param

        return filter_table
Beispiel #3
0
    def __set_cell_width(self):
        font_size = self.__cell_format_property.get("font_size")

        if not dataproperty.is_integer(font_size):
            return

        for col_idx, col_prop in enumerate(self._column_prop_list):
            width = (min(col_prop.padding_len, self.MAX_CELL_WIDTH) *
                     (font_size / 10.0) + 2)
            self.stream.set_column(col_idx, col_idx, width=width)
Beispiel #4
0
    def __set_cell_width(self):
        font_size = self.__cell_format_property.get("font_size")

        if not dataproperty.is_integer(font_size):
            return

        for col_idx, col_prop in enumerate(self._column_prop_list):
            width = (
                min(col_prop.padding_len, self.MAX_CELL_WIDTH) *
                (font_size / 10.0) + 2
            )
            self.stream.set_column(col_idx, col_idx, width=width)
Beispiel #5
0
    def __get_number_property(self):
        dict_col_numprops = {}
        for col, col_prop in enumerate(self._column_prop_list):
            num_props = {}
            if dataproperty.is_integer(col_prop.minmax_decimal_places.max_value):
                float_digit = col_prop.minmax_decimal_places.max_value
                if float_digit > 0:
                    num_props = {"num_format": "0.%s" % ("0" * float_digit)}

            dict_col_numprops[col] = num_props

        return dict_col_numprops
Beispiel #6
0
    def get_arg_text():
        arg_list = []
        for arg in sys.argv[1:]:
            if dataproperty.is_integer(arg):
                arg_list.append(arg)
                continue

            if re.search("[\s]+", arg) is not None:
                arg = "'%s'" % (arg)
            arg_list.append(arg)

        return " ".join(arg_list)
Beispiel #7
0
    def __get_number_property(self):
        dict_col_numprops = {}
        for col, col_prop in enumerate(self._column_prop_list):
            num_props = {}
            if dataproperty.is_integer(
                    col_prop.minmax_decimal_places.max_value):
                float_digit = col_prop.minmax_decimal_places.max_value
                if float_digit > 0:
                    num_props = {"num_format": "0.%s" % ("0" * float_digit)}

            dict_col_numprops[col] = num_props

        return dict_col_numprops
Beispiel #8
0
    def to_value_str(cls, value):
        """
        :param str value: Value associated with a key.
        :return:
            String that suitable for value of a key.
            Return ``"NULL"`` if the value is ``None``
        :rtype: str
        """

        if value is None:
            return "NULL"

        if dataproperty.is_integer(value) or dataproperty.is_float(value):
            return str(value)

        return "'%s'" % (value)
Beispiel #9
0
    def to_value_str(cls, value):
        """
        :param str value: Value associated with a key.
        :return:
            String that suitable for value of a key.
            Return ``"NULL"`` if the value is ``None``
        :rtype: str
        """

        if value is None:
            return "NULL"

        if dataproperty.is_integer(value) or dataproperty.is_float(value):
            return str(value)

        return "'%s'" % (value)
Beispiel #10
0
    def __set_pre_network_filter(self, qdisc_major_id):
        if all([
                dataproperty.is_empty_string(self.network),
                not dataproperty.is_integer(self.port),
        ]):
            flowid = "{:x}:{:d}".format(qdisc_major_id,
                                        self.__get_qdisc_minor_id())
        else:
            flowid = "{:x}:2".format(qdisc_major_id)

        command_list = [
            "tc filter add", "dev " + self.__get_tc_device(), "protocol ip",
            "parent {:x}:".format(qdisc_major_id),
            "prio 2 u32 match ip {:s} 0.0.0.0/0".format(
                self.__get_network_direction_str()), "flowid " + flowid
        ]

        return SubprocessRunner(" ".join(command_list)).run()
    def __set_pre_network_filter(self, qdisc_major_id):
        if all([
            dataproperty.is_empty_string(self.network),
            not dataproperty.is_integer(self.port),
        ]):
            flowid = "%x:%d" % (qdisc_major_id, self.__get_qdisc_minor_id())
        else:
            flowid = "%x:2" % (qdisc_major_id)

        command_list = [
            "tc filter add",
            "dev " + self.__get_tc_device(),
            "protocol ip",
            "parent %x:" % (qdisc_major_id),
            "prio 2 u32 match ip %s 0.0.0.0/0" % (
                self.__get_network_direction_str()),
            "flowid " + flowid
        ]

        return self.__subproc_wrapper.run(" ".join(command_list))
Beispiel #12
0
    def __get_filter(self, device):
        if dataproperty.is_empty_string(device):
            return {}

        qdisc_parser = TcQdiscParser()
        filter_parser = TcFilterParser()

        # parse qdisc ---
        command = "tc qdisc show dev {:s}".format(device)
        qdisk_show_runner = SubprocessRunner(command)
        qdisk_show_runner.run()
        qdisc_param = qdisc_parser.parse(qdisk_show_runner.stdout)

        # parse filter ---
        command = "tc filter show dev {:s}".format(device)
        filter_show_runner = SubprocessRunner(command)
        filter_show_runner.run()

        filter_table = {}
        for filter_param in filter_parser.parse_filter(
                filter_show_runner.stdout):
            key_item_list = []

            if dataproperty.is_not_empty_string(filter_param.get("network")):
                key_item_list.append("network=" + filter_param.get("network"))

            if dataproperty.is_integer(filter_param.get("port")):
                key_item_list.append("port={:d}".format(
                    filter_param.get("port")))

            filter_key = ", ".join(key_item_list)
            filter_table[filter_key] = {}
            if filter_param.get("flowid") == qdisc_param.get("parent"):
                work_qdisc_param = dict(qdisc_param)
                del work_qdisc_param["parent"]
                filter_table[filter_key] = work_qdisc_param

        return filter_table