Exemple #1
0
def CreateProcess(name, command_line, process_attr, thread_attr,
                  inherit, flags, env, start_dir, startup_info):
    si = _STARTUPINFO()
    if startup_info is not None:
        si.dwFlags = startup_info.dwFlags
        si.wShowWindow = startup_info.wShowWindow
        if startup_info.hStdInput:
            si.hStdInput = int(startup_info.hStdInput)
        if startup_info.hStdOutput:
            si.hStdOutput = int(startup_info.hStdOutput)
        if startup_info.hStdError:
            si.hStdError = int(startup_info.hStdError)

    pi = _PROCESS_INFORMATION()
    flags |= CREATE_UNICODE_ENVIRONMENT

    if env is not None:
        envbuf = ""
        for k, v in env.items():
            envbuf += "%s=%s\0" % (k, v)
        envbuf += '\0'
    else:
        envbuf = None

    res = _CreateProcess(name, command_line, None, None, inherit, flags, envbuf,
                        start_dir, _byref(si), _byref(pi))

    if not res:
        raise _WinError()

    return _handle(pi.hProcess), _handle(pi.hThread), pi.dwProcessID, pi.dwThreadID
Exemple #2
0
def CreateProcess(name, command_line, process_attr, thread_attr,
                  inherit, flags, env, start_dir, startup_info):
    si = _STARTUPINFO()
    si.dwFlags = startup_info.dwFlags
    si.wShowWindow = getattr(startup_info, 'wShowWindow', 0)
    if startup_info.hStdInput:
        si.hStdInput = startup_info.hStdInput.handle
    if startup_info.hStdOutput:
        si.hStdOutput = startup_info.hStdOutput.handle
    if startup_info.hStdError:
        si.hStdError = startup_info.hStdError.handle

    pi = _PROCESS_INFORMATION()

    if env is not None:
        envbuf = ""
        for k, v in env.iteritems():
            envbuf += "%s=%s\0" % (k, v)
        envbuf += '\0'
    else:
        envbuf = None

    res = _CreateProcess(name, command_line, None, None, inherit, flags, envbuf,
                        start_dir, _byref(si), _byref(pi))

    if not res:
        raise WindowsError("Error")

    return _handle(pi.hProcess), _handle(pi.hThread), pi.dwProcessID, pi.dwThreadID
Exemple #3
0
def netgroup(netgroup,host=None,user=None,domain=None):
    """Perform a netgroup lookup.

    Enumeration is not supported on netgroup, so either one or three keys must be provided.

    To lookup one group by netgroup name::

        >>> ng = netgroup(netgroupname)
        >>> print ng.name
        'netgroupname'

    """
    host,user,domain = c_char_p(None),c_char_p(None),c_char_p(None)

    # If netgroup is None, fatal error
    if netgroup is None:
        return Netgroup(False)
        #return None

    else:
        # True or False
        netgrp = setnetgrent(netgroup)
        members = []
        while netgrp:
            # getnetgrent need pointers to be written
            netgrp = getnetgrent(_byref(host), _byref(user), _byref(domain))
            if netgrp:
                #res.append(Netgroup(netgrp))
                members.append({ 'host':host.value,'user':user.value,'domain':domain.value })
        endnetgrent()
        return Netgroup({'name':netgroup,'members':members})
Exemple #4
0
	def __init__(self, _context=None):
		"""
		Initializes a new instance of the Context class, using the local or the network backend of the IIO library.

		returns: type=iio.Context
			An new instance of this class

		This function will create a network context if the IIOD_REMOTE
		environment variable is set to the hostname where the IIOD server runs.
		If set to an empty string, the server will be discovered using ZeroConf.
		If the environment variable is not set, a local context will be created instead.
		"""
		if(_context is None):
			self._context = _new_default()
		elif type(_context) is str:
			self._context = _new_uri(_context)
		else:
			self._context = _context

		# TODO(pcercuei): Use a dictionary for the devices.
		self._devices = [ Trigger(dev) if _d_is_trigger(dev) else Device(self, dev) for dev in \
				[ _get_device(self._context, x) for x in xrange(0, _devices_count(self._context)) ]]
		self._name = _get_name(self._context)
		self._description = _get_description(self._context)
		self._xml = _get_xml(self._context)

		major = c_uint()
		minor = c_uint()
		buf = create_string_buffer(8)
		_get_version(self._context, _byref(major), _byref(minor), buf)
		self._version = (major.value, minor.value, buf.value )
Exemple #5
0
    def __init__(self, _context=None):
        """
		Initializes a new instance of the Context class, using the local or the network backend of the IIO library.

		returns: type=iio.Context
			An new instance of this class

		This function will create a network context if the IIOD_REMOTE
		environment variable is set to the hostname where the IIOD server runs.
		If set to an empty string, the server will be discovered using ZeroConf.
		If the environment variable is not set, a local context will be created instead.
		"""
        if (_context is None):
            self._context = _new_default()
        else:
            self._context = _context

        # TODO(pcercuei): Use a dictionary for the devices.
        self._devices = [ Trigger(self, dev) if _d_is_trigger(dev) else Device(self, dev) for dev in \
          [ _get_device(self._context, x) for x in xrange(0, _devices_count(self._context)) ]]
        self._name = _get_name(self._context)
        self._description = _get_description(self._context)
        self._xml = _get_xml(self._context)

        major = c_uint()
        minor = c_uint()
        buf = create_string_buffer(8)
        _get_version(self._context, _byref(major), _byref(minor), buf)
        self._version = (major.value, minor.value, buf.value)
Exemple #6
0
def CreateProcess(name, command_line, process_attr, thread_attr, inherit,
                  flags, env, start_dir, startup_info):
    si = _STARTUPINFO()
    if startup_info is not None:
        si.dwFlags = startup_info.dwFlags
        si.wShowWindow = startup_info.wShowWindow
        if startup_info.hStdInput:
            si.hStdInput = int(startup_info.hStdInput)
        if startup_info.hStdOutput:
            si.hStdOutput = int(startup_info.hStdOutput)
        if startup_info.hStdError:
            si.hStdError = int(startup_info.hStdError)

    pi = _PROCESS_INFORMATION()

    if env is not None:
        envbuf = ""
        for k, v in env.iteritems():
            envbuf += "%s=%s\0" % (k, v)
        envbuf += '\0'
    else:
        envbuf = None

    res = _CreateProcess(name, command_line, None, None, inherit, flags,
                         envbuf, start_dir, _byref(si), _byref(pi))

    if not res:
        raise _WinError()

    return _handle(pi.hProcess), _handle(
        pi.hThread), pi.dwProcessID, pi.dwThreadID
def exists(name):
	"""Validates the name of a netgroup"""

	try:
		## try to switch to 'str' object rather than unicode
		name = name.encode('utf8')
	except Exception as ex:
		## ignore
		pass

	host,user,domain = c_char_p(None),c_char_p(None),c_char_p(None)
	libc = CDLL('libc.so.6')
	libc.setnetgrent(name)

	try:
		while libc.getnetgrent(_byref(host), _byref(user), _byref(domain)):
			libc.endnetgrent()
			return True

		libc.endnetgrent()
		return False

	except Exception as ex:
		libc.endnetgrent()
		return False
Exemple #8
0
def exists(name):
    """Validates the name of a netgroup"""

    try:
        # Try to switch to 'str' object rather than unicode
        name = name.encode('utf8')
    except Exception as ex:
        # Ignore
        pass

    host, user, domain = c_char_p(None), c_char_p(None), c_char_p(None)
    libc = CDLL('libc.so.6')
    libc.setnetgrent(name)

    try:
        while libc.getnetgrent(_byref(host), _byref(user), _byref(domain)):
            libc.endnetgrent()
            return True

        libc.endnetgrent()
        return False

    except Exception as ex:
        libc.endnetgrent()
        return False
Exemple #9
0
def CreatePipe(attributes, size):
    read = _c_int()
    write = _c_int()

    res = _CreatePipe(_byref(read), _byref(write), None, size)

    if not res:
        raise _WinError()

    return _handle(read.value), _handle(write.value)
Exemple #10
0
def CreatePipe(attributes, size):
    read = _c_int()
    write = _c_int()

    res = _CreatePipe(_byref(read), _byref(write), None, size)

    if not res:
        raise _WinError()

    return _handle(read.value), _handle(write.value)
Exemple #11
0
    def __init__(self, _context=None, factoryname=None, properties=None):
        """
		Initializes a new instance of the Context class, using one of the
		available backends.

		returns: type=iio.Context
			An new instance of this class

		In case _context is set:
		  It copies the passed existing context.
		In case _context and factoryname are None:
		  This function will create a network context if the IIOD_REMOTE
		  environment variable is set to the hostname where the IIOD server runs.
		  If set to an empty string, the server will be discovered using ZeroConf.
		  If the environment variable is not set, a local context will be created instead.
		In case factoryname is set:
		  It creates a context running this backend factory with the
		  dictionary 'properties'.
		"""
        self._context = None

        if _context:
            self._context = _context
        elif factoryname is None:
            self._context = _new_default()
        elif isinstance(_context, str):
            self._context = _new_uri(_context.encode('ascii'))
        else:
            envz = bytes()
            if properties:
                for k, v in properties.items():
                    envz += b'%s=%s\0' % (k.encode('utf8'), v.encode('utf8'))
            self._context = _new_context(factoryname, envz, len(envz))

        self._attrs = {}
        for x in range(0, _get_attrs_count(self._context)):
            str1 = c_char_p()
            str2 = c_char_p()
            _get_attr(self._context, x, _byref(str1), _byref(str2))
            self._attrs[str1.value] = str2.value

        # TODO(pcercuei): Use a dictionary for the devices.
        self._devices = [ Trigger(dev) if _d_is_trigger(dev) else Device(self, dev) for dev in \
          [ _get_device(self._context, x) for x in range(0, _devices_count(self._context)) ]]
        self._name = _get_name(self._context)
        self._description = _get_description(self._context)
        self._xml = _get_xml(self._context)

        major = c_uint()
        minor = c_uint()
        buf = create_string_buffer(8)
        _get_version(self._context, _byref(major), _byref(minor), buf)
        self._version = (major.value, minor.value, buf.value)
Exemple #12
0
    def line_at(self, y: int, text: str, tail: int = 0) -> None:

        y += self._buffer_info.dwCursorPosition.Y - self._range_height
        n = len(text)

        written = _DWORD()
        _WriteConsoleOutputCharacterW(self._output, text, n, _Coord(0, y),
                                      _byref(written))

        if tail <= 0:
            return

        _FillConsoleOutputCharacterW(self._output, self._fill_char, tail,
                                     _Coord(n, y), _byref(written))
Exemple #13
0
    def _init_fpga(self):
        """
        Initialize FPGA handle with driver library.
        """
        # Set FPGA handle to default value
        self._fpga_handle = _c_int(-1)  # PCI_BAR_HANDLE_INIT

        # Attach FPGA
        fpga_pci_attach = self._fpga_library.fpga_pci_attach
        fpga_pci_attach.restype = _c_int  # return code
        fpga_pci_attach.argtypes = (
            _c_int,  # slot_id
            _c_int,  # pf_id
            _c_int,  # bar_id
            _c_uint32,  # flags
            _POINTER(_c_int)  # handle
        )

        if fpga_pci_attach(
                self._fpga_slot_id,
                0,  # FPGA_APP_PF
                0,  # APP_PF_BAR0
                0,
                _byref(self._fpga_handle)):
            raise RuntimeError("Unable to attach to the AFI on slot ID %s" %
                               self._fpga_slot_id)
Exemple #14
0
    def _get_trigger(self):
        value = _Device()
        _d_get_trigger(self._device, _byref(value))

        for dev in self.ctx()._devices:
            if value == dev._device:
                return dev
        return None
Exemple #15
0
def differential_flux(model, momentum, theta, phi=0., altitude=0., latitude=None):
    """Generic interface to a flux model.
    """
    
    if not (latitude is None):
        latitude = _byref(c_double(latitude))
	
    return _libflux.differential_flux(model, c_double(momentum), c_double(theta), c_double(phi), c_double(altitude), latitude)
Exemple #16
0
	def _get_trigger(self):
		value = _Device()
		_d_get_trigger(self._device, _byref(value))

		for dev in self.ctx()._devices:
			if value == dev._device:
				return dev
		return None
Exemple #17
0
   def __init__(self, _context=None):
      """
      Initializes a new instance of the Context class, using the local or the network backend of the IIO library.

      returns: type=iio.Context
         An new instance of this class

      This function will create a network context if the IIOD_REMOTE
      environment variable is set to the hostname where the IIOD server runs.
      If set to an empty string, the server will be discovered using ZeroConf.
      If the environment variable is not set, a local context will be created instead.
      """
      self._context = None

      try:
          if(_context is None):
              self._context = _new_default()
          elif type(_context) is str or type(_context) is unicode:
              self._context = _new_uri(_context.encode('ascii'))
          else:
              self._context = _context
      except:
          print("Could not create context")

      try:
          self._attrs = {}
          for x in range(0, _get_attrs_count(self._context)):
              str1 = c_char_p()
              str2 = c_char_p()
              _get_attr(self._context, x, _byref(str1), _byref(str2))
              self._attrs[str1.value.decode('ascii')] = str2.value.decode('ascii')
      except:
          print("Could not get attributes")

      #TODO(pcercuei): Use a dictionary for the devices.
      self._devices = [ Trigger(dev) if _d_is_trigger(dev) else Device(self, dev) for dev in \
            [ _get_device(self._context, x) for x in range(0, _devices_count(self._context)) ]]
      self._name = _get_name(self._context).decode('ascii')
      self._description = _get_description(self._context).decode('ascii')
      self._xml = _get_xml(self._context).decode('ascii')

      major = c_uint()
      minor = c_uint()
      buf = create_string_buffer(8)
      _get_version(self._context, _byref(major), _byref(minor), buf)
      self._version = (major.value, minor.value, buf.value.decode('ascii') )
Exemple #18
0
def GetExitCodeProcess(handle):
    code = _c_int()

    res = _GetExitCodeProcess(int(handle), _byref(code))

    if not res:
        raise _WinError()

    return code.value
Exemple #19
0
def GetExitCodeProcess(handle):
    code = _c_int()
    
    res = _GetExitCodeProcess(handle.handle, _byref(code))

    if not res:
        raise WindowsError("Error")

    return code.value
Exemple #20
0
def GetExitCodeProcess(handle):
    code = _c_int()

    res = _GetExitCodeProcess(handle.handle, _byref(code))

    if not res:
        raise WindowsError("Error")

    return code.value
Exemple #21
0
def GetExitCodeProcess(handle):
    code = _c_int()

    res = _GetExitCodeProcess(int(handle), _byref(code))

    if not res:
        raise _WinError()

    return code.value
Exemple #22
0
    def _get_trigger(self):
        value = _DevicePtr()
        _d_get_trigger(self._device, _byref(value))
        trig = Trigger(value.contents)

        for dev in self.ctx.devices:
            if trig.id == dev.id:
                return dev
        return None
Exemple #23
0
    def shutdown(self) -> None:

        self._shutdown_signal.set()

        input_record = _InputRecord(EventType=0x1, KeyEvent=_KeyEventRecord(
            wVirtualKeyCode=0xff,
            wVirtualScanCode=0xffff,
        ))
        written = _DWORD()
        _WriteConsoleInputW(self._handle, input_record, 1, _byref(written))
Exemple #24
0
def DuplicateHandle(source_process, source, target_process, access, inherit, options=0):
    target = _c_int()

    res = _DuplicateHandle(int(source_process), int(source), int(target_process),
                           _byref(target),
                           access, inherit, options)

    if not res:
        raise _WinError()

    return _handle(target.value)
Exemple #25
0
def getgroup(name):
    '''
    getgroup(netgroupName)

    Retrieve a netgroup using NSS routines
    Returns a list of matching (host,user,domain) tuples
    '''
    host,user,domain = c_char_p(None),c_char_p(None),c_char_p(None)

    libc = CDLL(_libc_name)

    libc.setnetgrent(name)

    try:
        groups = []
        while libc.getnetgrent(_byref(host), _byref(user), _byref(domain)):
            groups.append( (host.value,user.value,domain.value) )
        return groups

    finally:
        libc.endnetgrent()
Exemple #26
0
def getgroup(name):
    '''
    getgroup(netgroupName)

    Retrieve a netgroup using NSS routines
    Returns a list of matching (host,user,domain) tuples
    '''
    host, user, domain = c_char_p(None), c_char_p(None), c_char_p(None)

    libc = CDLL(_libc_name)

    libc.setnetgrent(name)

    try:
        groups = []
        while libc.getnetgrent(_byref(host), _byref(user), _byref(domain)):
            groups.append((host.value, user.value, domain.value))
        return groups

    finally:
        libc.endnetgrent()
Exemple #27
0
    def reg_read(self, reg):
        """
        Read the content of a register of this device.

        :param reg: type=int
            The register address

        returns: type=int
            The value of the register
        """
        value = c_uint()
        _d_reg_read(self._device, reg, _byref(value))
        return value.value
Exemple #28
0
def scan_contexts():
	d = dict()
	ptr = _POINTER(_ContextInfoPtr)()

	ctx = _create_scan_context(None, 0)
	nb = _get_context_info_list(ctx, _byref(ptr));

	for i in range(0, nb):
		d[_context_info_get_uri(ptr[i])] = _context_info_get_description(ptr[i])

	_context_info_list_free(ptr)
	_destroy_scan_context(ctx)
	return d
Exemple #29
0
def scan_contexts():
	d = dict()
	ptr = _POINTER(_ContextInfoPtr)()

	ctx = _create_scan_context(None, 0)
	nb = _get_context_info_list(ctx, _byref(ptr));

	for i in range(0, nb):
		d[_context_info_get_uri(ptr[i]).decode('ascii')] = _context_info_get_description(ptr[i]).decode('ascii')

	_context_info_list_free(ptr)
	_destroy_scan_context(ctx)
	return d
Exemple #30
0
    def __init__(self, _context=None):
        """
        Initialize a new instance of the Context class, using the local or the network backend of the IIO library.

        returns: type=iio.Context
            An new instance of this class

        This function will create a network context if the IIOD_REMOTE
        environment variable is set to the hostname where the IIOD server runs.
        If set to an empty string, the server will be discovered using ZeroConf.
        If the environment variable is not set, a local context will be created instead.
        """
        self._context = None

        if _context is None:
            self._context = _new_default()
        elif _isstring(_context):
            self._context = _new_uri(_context.encode("ascii"))
        else:
            self._context = _context

        self._attrs = {}
        for index in range(0, _get_attrs_count(self._context)):
            str1 = c_char_p()
            str2 = c_char_p()
            _get_attr(self._context, index, _byref(str1), _byref(str2))
            self._attrs[str1.value.decode("ascii")] = str2.value.decode(
                "ascii")

        self._name = _get_name(self._context).decode("ascii")
        self._description = _get_description(self._context).decode("ascii")
        self._xml = _get_xml(self._context).decode("ascii")

        major = c_uint()
        minor = c_uint()
        buf = create_string_buffer(8)
        _get_version(self._context, _byref(major), _byref(minor), buf)
        self._version = (major.value, minor.value, buf.value.decode("ascii"))
Exemple #31
0
	def reg_read(self, reg):
		"""
		Read the content of a register of this device.

		parameters:
			reg: type=int
				The register address

		returns: type=int
			The value of the register
		"""
		value = c_uint()
		_d_reg_read(self._device, reg, _byref(value))
		return value.value
Exemple #32
0
    def __init__(self) -> None:

        self._range_height = 0
        self._fill_char = ' '

        self._executor = None

        self._output = None
        self._saved_output_mode = None
        self._buffer_info = _ConsoleScreenBufferInfo()

        self._input_handler = None
        self._input_future = None

        self._executor = _Executor(max_workers=1)

        input_ = _CreateFileW('CONIN$', 0xc0000000, 0x3,
                              _byref(_SecurityAttributes(None, True)),
                              3, 0x80, None)

        self._output = _CreateFileW('CONOUT$', 0xc0000000, 0x3,
                                    _byref(_SecurityAttributes(None, True)),
                                    3, 0x80, None)

        mode = _DWORD()
        _GetConsoleMode(self._output, _byref(mode))
        self._saved_output_mode = mode.value

        _SetConsoleMode(self._output, self._saved_output_mode | 0x0018)

        self._update_buffer_info()

        self._input_handler = _ConsoleInputHandler(input_, close=True)

        loop = _asyncio.get_event_loop()
        self._input_future = loop.run_in_executor(self._executor,
                                                  self._input_handler.handle)
Exemple #33
0
def scan_contexts():
    """Scan Context."""
    scan_ctx = dict()
    ptr = _POINTER(_ContextInfoPtr)()

    ctx = _create_scan_context(None, 0)
    ctx_nb = _get_context_info_list(ctx, _byref(ptr))

    for i in range(0, ctx_nb):
        scan_ctx[_context_info_get_uri(
            ptr[i]).decode("ascii")] = _context_info_get_description(
                ptr[i]).decode("ascii")

    _context_info_list_free(ptr)
    _destroy_scan_context(ctx)
    return scan_ctx
Exemple #34
0
def DuplicateHandle(source_process,
                    source,
                    target_process,
                    access,
                    inherit,
                    options=0):
    target = _c_int()

    res = _DuplicateHandle(int(source_process), int(source),
                           int(target_process), _byref(target), access,
                           inherit, options)

    if not res:
        raise _WinError()

    return _handle(target.value)
Exemple #35
0
    def read_register(self, register_offset):
        """
        Read register.

        This method is intended to be called directly, use
        "read_register_callback" to instantiate
        "accelize_drm.DrmManager".

        Args:
            register_offset (int): Register offset.

        Returns:
            int: 32 bits register value.
        """
        register_value = _c_uint32(0)
        self._read_register_callback(register_offset, _byref(register_value))
        return register_value.value
Exemple #36
0
    def __init__(self, handle, close=False) -> None:

        self._handle = handle
        self._close = close
        self._saved_mode = None
        self._callback = None
        self._callback_lock = None
        self._shutdown_signal = None

        mode = _DWORD()
        _GetConsoleMode(self._handle, _byref(mode))
        self._saved_mode = mode.value

        _SetConsoleMode(self._handle, self._saved_mode & ~0x0007 | 0x0018)

        self._callback_lock = _threading.Lock()
        self._shutdown_signal = _threading.Event()
Exemple #37
0
   def _get_trigger(self):
      value = _Device()
      try:
          _d_get_trigger(self._device, _byref(value))
      except:
          print("Couldn't get device trigger")

      for dev in self.ctx()._devices:
         if value == dev._device:
            return dev
      return None

      try:
          trigger = property(_get_trigger, _set_trigger, None, \
          "Contains the configured trigger for this IIO device.\n\ttype=iio.Trigger")
      except:
          print("Could not get the device trigger")
Exemple #38
0
    def handle(self) -> None:

        # noinspection PyTypeChecker,PyCallingNonCallable
        buffer = (_InputRecord * 100)()
        read = _DWORD()

        while not self._shutdown_signal.is_set():

            _ReadConsoleInputW(self._handle, buffer, len(buffer), _byref(read))

            if self._shutdown_signal.is_set():
                break

            for input_record in buffer[:read.value]:

                if input_record.EventType != 0x0001:
                    continue

                key_event = input_record.KeyEvent
                if not key_event.bKeyDown:
                    continue

                vk = key_event.wVirtualKeyCode
                if vk == 0x1b:
                    event = _events.QuitEvent()

                elif vk == 0x26:
                    event = _events.UpNavEvent()

                elif vk == 0x28:
                    event = _events.DownNavEvent()

                else:
                    continue

                with self._callback_lock:
                    if self._callback is None:
                        continue

                    loop, callback = self._callback

                loop.call_soon_threadsafe(callback, event)
Exemple #39
0
    def _update_buffer_info(self) -> None:

        _GetConsoleScreenBufferInfo(self._output, _byref(self._buffer_info))
Exemple #40
0
def _get_lib_version():
    major = c_uint()
    minor = c_uint()
    buf = create_string_buffer(8)
    _get_library_version(_byref(major), _byref(minor), buf)
    return (major.value, minor.value, buf.value.decode("ascii"))
Exemple #41
0
def _get_lib_version():
	major = c_uint()
	minor = c_uint()
	buf = create_string_buffer(8)
	_get_library_version(_byref(major), _byref(minor), buf)
	return (major.value, minor.value, buf.value )