Ejemplo n.º 1
0
def symlink(src, dst):
    """
    Extended "os.symlink" that:
    - Autodetect if target is directory.
    - Ignore error if file already exists.
    - Ensure to link to real absolute path of the source.

    Args:
        src (path-like object): Source path.
        dst (path-like object): Destination path.
    """
    src = _realpath(_fsdecode(src))
    try:
        _symlink(src, _fsdecode(dst), target_is_directory=_isdir(src))
    except FileExistsError:
        pass
Ejemplo n.º 2
0
def yaml_write(data, path, **kwargs):
    """
    Write a YAML file

    Args:
        data (dict or list): data to serialize.
        path (path-like object): Path where save file.
        kwargs: "yaml.dump" kwargs.
    """
    with open(_fsdecode(path), 'wt') as file:
        _yaml_dump(data, file, Dumper=_Dumper, **kwargs)
Ejemplo n.º 3
0
def json_write(data, path, **kwargs):
    """
    Write a JSON file

    Args:
        data (dict or list): data to serialize.
        path (path-like object): Path where save file.
        kwargs: "json.dump" kwargs.
    """
    with open(_fsdecode(path), 'wt') as file:
        _json_dump(data, file, **kwargs)
Ejemplo n.º 4
0
def yaml_read(path):
    """
    Read a YAML file.

    Args:
        path (path-like object): Path to file to load.

    Returns:
        dict or list: Un-serialized content
    """
    with open(_fsdecode(path), 'rt') as file:
        return _yaml_load(file, Loader=_Loader)
Ejemplo n.º 5
0
def json_read(path, **kwargs):
    """
    Read a JSON file.

    Args:
        path (path-like object): Path to file to load.
        kwargs: "json.load" kwargs.

    Returns:
        dict or list: Un-serialized content
    """
    with open(_fsdecode(path), 'rt') as file:
        return _json_load(file, **kwargs)
Ejemplo n.º 6
0
def get_sources_dirs(*src):
    """
    Return sources directories.

    Args:
        *src: Directories paths.

    Returns:
        list of str: Sources directories
    """
    paths = [HOME_DIR, '.']
    paths.extend(src)
    return [_realpath(_fsdecode(path)) for path in paths if path]
Ejemplo n.º 7
0
def yaml_read(path):
    """
    Read a YAML file.

    Args:
        path (path-like object): Path to file to load.

    Returns:
        dict or list: Un-serialized content
    """
    path = _realpath(_fsdecode(path))
    with open(path, 'rt') as file:
        try:
            return _yaml_load(file, Loader=_Loader)

        except _YAMLError as exception:
            raise _ConfigurationException(
                f'Unable to read "{path}": {str(exception)}')
Ejemplo n.º 8
0
def json_read(path, **kwargs):
    """
    Read a JSON file.

    Args:
        path (path-like object): Path to file to load.
        kwargs: "json.load" kwargs.

    Returns:
        dict or list: Un-serialized content
    """
    path = _realpath(_fsdecode(path))
    with open(path, 'rt') as file:
        try:
            return _json_load(file, **kwargs)

        except _JSONDecodeError as exception:
            raise _ConfigurationException(
                f'Unable to read "{path}": {str(exception)}')
Ejemplo n.º 9
0
    def __init__(self,
                 fpga_slot_id=0,
                 fpga_image=None,
                 drm_ctrl_base_addr=0,
                 log_dir='.',
                 no_clear_fpga=False,
                 **kwargs):
        self._fpga_slot_id = fpga_slot_id
        self._fpga_image = fpga_image
        self._drm_ctrl_base_addr = drm_ctrl_base_addr
        self._log_dir = _realpath(_fsdecode(log_dir))
        for k, v in kwargs.items():
            setattr(self, k, v)

        # FPGA read/write low level functions ans associated locks
        self._fpga_read_register = None
        self._fpga_write_register = None
        self._fpga_register_lock = self._get_lock()
        self._fpga_read_register_lock = self._fpga_register_lock
        self._fpga_write_register_lock = self._fpga_register_lock

        if not no_clear_fpga:
            self.clear_fpga()

        # Device and library handles
        self._fpga_handle = None
        self._fpga_library = self._get_driver()

        # Initialize FPGA
        if fpga_image:
            self.program_fpga(fpga_image)

        with self._augment_exception('initialize'):
            self._init_fpga()

        # Call backs
        self._read_register_callback = self._get_read_register_callback()
        self._write_register_callback = self._get_write_register_callback()
Ejemplo n.º 10
0
    def _program_fpga(self, fpga_image):
        """
        Program the FPGA with the specified image.

        Args:
            fpga_image (str): FPGA image.
        """
        # Vitis does not reprogram a FPGA that has already the bitstream.
        # So to force it we write another bitstream first.
        clear_image = _join(SCRIPT_DIR, 'clear.awsxclbin')
        load_image = _run([
            self._xbutil, 'program', '-d',
            str(self._fpga_slot_id), '-p', clear_image
        ],
                          stderr=_STDOUT,
                          stdout=_PIPE,
                          universal_newlines=True,
                          check=False)
        if load_image.returncode:
            raise RuntimeError(load_image.stdout)
        print('Cleared AWS XRT slot #%d' % self._fpga_slot_id)

        # Now load the real image
        fpga_image = _realpath(_fsdecode(fpga_image))
        load_image = _run([
            self._xbutil, 'program', '-d',
            str(self._fpga_slot_id), '-p', fpga_image
        ],
                          stderr=_STDOUT,
                          stdout=_PIPE,
                          universal_newlines=True,
                          check=False)
        if load_image.returncode:
            raise RuntimeError(load_image.stdout)
        print('Programmed AWS XRT slot #%d with FPGA image %s' %
              (self._fpga_slot_id, fpga_image))