コード例 #1
0
 def set(self, cpus, mems):
     if isiterable(cpus):
         cpus = list_to_ranges(cpus)
     if isiterable(mems):
         mems = list_to_ranges(mems)
     self.device.set_sysfile_value(self.cpus_file, cpus)
     self.device.set_sysfile_value(self.mems_file, mems)
コード例 #2
0
 def set(self, cpus, mems):
     if isiterable(cpus):
         cpus = list_to_ranges(cpus)
     if isiterable(mems):
         mems = list_to_ranges(mems)
     self.device.set_sysfile_value(self.cpus_file, cpus)
     self.device.set_sysfile_value(self.mems_file, mems)
コード例 #3
0
    def invoke(self,
               binary,
               args=None,
               in_directory=None,
               on_cpus=None,
               background=False,
               as_root=False,
               timeout=30):
        """
        Executes the specified binary under the specified conditions.

        :binary: binary to execute. Must be present and executable on the device.
        :args: arguments to be passed to the binary. The can be either a list or
               a string.
        :in_directory:  execute the binary in the  specified directory. This must
                        be an absolute path.
        :on_cpus:  taskset the binary to these CPUs. This may be a single ``int`` (in which
                   case, it will be interpreted as the mask), a list of ``ints``, in which
                   case this will be interpreted as the list of cpus, or string, which
                   will be interpreted as a comma-separated list of cpu ranges, e.g.
                   ``"0,4-7"``.
        :background: If ``True``, a ``subprocess.Popen`` object will be returned straight
                     away. If ``False`` (the default), this will wait for the command to
                     terminate and return the STDOUT output
        :as_root: Specify whether the command should be run as root
        :timeout: If the invocation does not terminate within this number of seconds,
                  a ``TimeoutError`` exception will be raised. Set to ``None`` if the
                  invocation should not timeout.

        """
        command = binary
        if args:
            if isiterable(args):
                args = ' '.join(args)
            command = '{} {}'.format(command, args)
        if on_cpus:
            if isinstance(on_cpus, basestring):
                on_cpus = ranges_to_list(on_cpus)
            if isiterable(on_cpus):
                on_cpus = list_to_mask(on_cpus)  # pylint: disable=redefined-variable-type
            command = '{} taskset 0x{:x} {}'.format(self.busybox, on_cpus,
                                                    command)
        if in_directory:
            command = 'cd {} && {}'.format(in_directory, command)
        return self.execute(command,
                            background=background,
                            as_root=as_root,
                            timeout=timeout)
コード例 #4
0
 def set_value(self, obj, value=None):
     if value is None:
         if self.default is not None:
             value = self.default
         elif self.mandatory:
             msg = 'No values specified for mandatory parameter {} in {}'
             raise ConfigError(msg.format(self.name, obj.name))
     else:
         try:
             value = self.kind(value)
         except (ValueError, TypeError):
             typename = self.get_type_name()
             msg = 'Bad value "{}" for {}; must be {} {}'
             article = get_article(typename)
             raise ConfigError(
                 msg.format(value, self.name, article, typename))
     current_value = getattr(obj, self.name, None)
     if current_value is None:
         setattr(obj, self.name, value)
     elif not isiterable(current_value):
         setattr(obj, self.name, value)
     else:
         new_value = current_value + [value]
         setattr(obj, self.name, new_value)
     if value is not None:
         if self.allowed_values:
             self._validate_allowed_values(obj, value)
         if self.constraint:
             self._validate_constraint(obj, value)
コード例 #5
0
 def set_value(self, obj, value=None):
     if value is None:
         if self.default is not None:
             value = self.default
         elif self.mandatory:
             msg = 'No values specified for mandatory parameter {} in {}'
             raise ConfigError(msg.format(self.name, obj.name))
     else:
         try:
             value = self.kind(value)
         except (ValueError, TypeError):
             typename = self.get_type_name()
             msg = 'Bad value "{}" for {}; must be {} {}'
             article = get_article(typename)
             raise ConfigError(msg.format(value, self.name, article, typename))
     current_value = getattr(obj, self.name, None)
     if current_value is None:
         setattr(obj, self.name, value)
     elif not isiterable(current_value):
         setattr(obj, self.name, value)
     else:
         new_value = current_value + [value]
         setattr(obj, self.name, new_value)
     if value is not None:
         if self.allowed_values:
             self._validate_allowed_values(obj, value)
         if self.constraint:
             self._validate_constraint(obj, value)
コード例 #6
0
def try_convert_to_numeric(v):
    try:
        if isiterable(v):
            return map(numeric, v)
        else:
            return numeric(v)
    except ValueError:
        return v
コード例 #7
0
def list_of_ints(value):
    """
    Value must be iterable. All elements will be converted to ``int``\ s.

    """
    if not isiterable(value):
        raise ValueError(value)
    return map(int, value)
コード例 #8
0
def list_of_strs(value):
    """
    Value must be iterable. All elements will be converted to strings.

    """
    if not isiterable(value):
        raise ValueError(value)
    return map(str, value)
コード例 #9
0
def list_of_numbers(value):
    """
    Value must be iterable. All elements will be converted to numbers (either ``ints`` or
    ``float``\ s depending on the elements).
    """
    if not isiterable(value):
        raise ValueError(value)
    return map(numeric, value)
コード例 #10
0
def try_convert_to_numeric(v):
    try:
        if isiterable(v):
            return map(numeric, v)
        else:
            return numeric(v)
    except ValueError:
        return v
コード例 #11
0
 def __init__(self, value=None):
     if isiterable(value):
         super(arguments, self).__init__(map(str, value))
     elif isinstance(value, basestring):
         posix = os.name != 'nt'
         super(arguments, self).__init__(shlex.split(value, posix=posix))
     elif value is None:
         super(arguments, self).__init__()
     else:
         super(arguments, self).__init__([str(value)])
コード例 #12
0
    def invoke(self, binary, args=None, in_directory=None, on_cpus=None,
               background=False, as_root=False, timeout=30):
        """
        Executes the specified binary under the specified conditions.

        :binary: binary to execute. Must be present and executable on the device.
        :args: arguments to be passed to the binary. The can be either a list or
               a string.
        :in_directory:  execute the binary in the  specified directory. This must
                        be an absolute path.
        :on_cpus:  taskset the binary to these CPUs. This may be a single ``int`` (in which
                   case, it will be interpreted as the mask), a list of ``ints``, in which
                   case this will be interpreted as the list of cpus, or string, which
                   will be interpreted as a comma-separated list of cpu ranges, e.g.
                   ``"0,4-7"``.
        :background: If ``True``, a ``subprocess.Popen`` object will be returned straight
                     away. If ``False`` (the default), this will wait for the command to
                     terminate and return the STDOUT output
        :as_root: Specify whether the command should be run as root
        :timeout: If the invocation does not terminate within this number of seconds,
                  a ``TimeoutError`` exception will be raised. Set to ``None`` if the
                  invocation should not timeout.

        """
        command = binary
        if args:
            if isiterable(args):
                args = ' '.join(args)
            command = '{} {}'.format(command, args)
        if on_cpus:
            if isinstance(on_cpus, basestring):
                on_cpus = ranges_to_list(on_cpus)
            if isiterable(on_cpus):
                on_cpus = list_to_mask(on_cpus)  # pylint: disable=redefined-variable-type
            command = '{} taskset 0x{:x} {}'.format(self.busybox, on_cpus, command)
        if in_directory:
            command = 'cd {} && {}'.format(in_directory, command)
        return self.execute(command, background=background, as_root=as_root, timeout=timeout)
コード例 #13
0
def list_of_bools(value, interpret_strings=True):
    """
    Value must be iterable. All elements will be converted to ``bool``\ s.

    .. note:: By default, ``boolean()`` conversion function will be used, which means that
              strings like ``"0"`` or ``"false"`` will be interpreted as ``False``. If this
              is undesirable, set ``interpret_strings`` to ``False``.

    """
    if not isiterable(value):
        raise ValueError(value)
    if interpret_strings:
        return map(boolean, value)
    else:
        return map(bool, value)
コード例 #14
0
 def __init__(self, value):
     # pylint: disable=non-parent-init-called,super-init-not-called
     if isiterable(value):
         list_type.__init__(self, value)
     else:
         list_type.__init__(self, [value])
コード例 #15
0
def disable(to_disable):
    if isiterable(to_disable):
        for inst in to_disable:
            _disable_instrument(inst)
    else:
        _disable_instrument(to_disable)
コード例 #16
0
def enable(to_enable):
    if isiterable(to_enable):
        for inst in to_enable:
            _enable_instrument(inst)
    else:
        _enable_instrument(to_enable)
コード例 #17
0
def disable(to_disable):
    if isiterable(to_disable):
        for inst in to_disable:
            _disable_instrument(inst)
    else:
        _disable_instrument(to_disable)
コード例 #18
0
def enable(to_enable):
    if isiterable(to_enable):
        for inst in to_enable:
            _enable_instrument(inst)
    else:
        _enable_instrument(to_enable)