예제 #1
0
def install_generic_cmake(path: str, git_url: str, verbose: bool,
                          cmake_args: dict):
    """
    Installs the cmake project from the "git_url" into the given folder "path".

    This function first clones the repository which is given by the git url, then it enters this folder locally,
    creates a build folder and attempts to run a cmake installation process within this folder.
    The cmake_args can be used to pass additional options to the cmake build process.
    """
    # Cloning the repository
    name, folder_path = git_clone(path, git_url, verbose)

    arguments = ' '.join(
        ['-D{}={}'.format(key, value) for key, value in cmake_args.items()])
    build_command = 'mkdir build; cd build; cmake {} ..'.format(arguments)
    exit_code = execute_command(build_command, verbose, cwd=folder_path)
    if not exit_code:
        click.secho('Built "{}" sources'.format(name), fg='green')

    install_command = 'cd build; sudo make install'
    exit_code = execute_command(install_command, verbose, cwd=folder_path)
    if not exit_code:
        click.secho('Installed "{}" successfully!'.format(name),
                    bold=True,
                    fg='green')
    else:
        click.secho('Error installing "{}"!'.format(name), bold=True, fg='red')

    return folder_path
예제 #2
0
def git_clone(path: str,
              git_url: str,
              verbose: bool,
              branch: str = 'master') -> Tuple[str, str]:
    """Clones the repository from *git_url* into the given folder *path*

    The additional arg *verbose* is a boolean which controls whether the output of this operation is being written to
    stdout stream.

    :param path: The path of the folder into which the repository is supposed to be clonedS
    :param git_url: The string url of the git repository from which to clone
    :param verbose: Whether or not to print additional output to the stdout stream
    :param branch: The string name of the branch to be cloned. Default is master branch.

    :return: A tuple of two values, where the first one is the string name of the repository and the second is the
    string of the absolute path of the clones location within the filesystem.
    """
    # Here we are first extracting the name of the git repository, because that will also be the name of the folder
    # into which it was cloned into later on and this that will be important to actually enter this folder
    repository_name = get_repository_name(git_url)
    repository_path = os.path.join(path, repository_name)
    if verbose:
        click.secho('   Cloning git repository "{}"'.format(git_url))

    # Executing the clone command
    clone_command = 'git clone --single-branch --branch {} {}'.format(
        branch, git_url)
    exit_code = execute_command(clone_command, verbose, cwd=path)
    if not exit_code:
        click.secho('(+) Cloned repository "{}" ({})'.format(
            repository_name, repository_path),
                    fg='green')

    return repository_name, repository_path
예제 #3
0
def install_pcitools(path: str, verbose: bool = True) -> dict:
    """
    Installs the "pcitool" repository into the given *path*. Returns a dict which contains information about the
    installation process.

    The returned dict contains the following items:
    - success: boolean value of whether or not the installation succeeded
    - path: the string path of the file
    - git: the string URL of the git repository from which it was installed

    :param path: The string path of the folder into which to install this dependency
    :param verbose: Whether or not to produce verbose output. DEPRECATED: Uses config field to determine verbosity

    :return: A dict, which contains information about the installation process.
    """
    git_url = CONFIG['install']['pcitools_git']
    folder_path = install_generic_cmake(path, git_url, CONFIG.verbose(),
                                        {'CMAKE_INSTALL_PREFIX': '/usr'})

    # Also installing the driver!
    driver_path = os.path.join(folder_path, 'driver')
    output = None if verbose else subprocess.DEVNULL

    build_command = 'mkdir build; cd build; cmake -DCMAKE_INSTALL_PREFIX=/usr ..'
    exit_code = execute_command(build_command,
                                CONFIG.verbose(),
                                cwd=driver_path)
    if not exit_code:
        click.secho('Built "pcilib driver" sources', fg='green')

    install_command = 'cd build; sudo make install'
    exit_code = execute_command(install_command,
                                CONFIG.verbose(),
                                cwd=driver_path)
    if not exit_code:
        click.secho('Installed "pcilib driver" successfully!',
                    bold=True,
                    fg='green')

    # Activating the driver after it has been installed...
    activate_driver_command = 'sudo depmod -a'
    exit_code = execute_command(activate_driver_command, CONFIG.verbose())
    if not exit_code:
        click.secho('Activated driver!', bold=True, fg='green')

    return {'success': (not exit_code), 'path': folder_path, 'git': git_url}
예제 #4
0
def build_repository(suite: str, verbose: Optional[bool] = False):
    """Clones the remote repo, flashes the new configuration to the hardware and runs the test *suite*

    :param suite: the string name of the test suite which is supposed to be executed with the camera after the new
    configuration was flashed to the hardware.
    :param verbose: Whether or not additional console output is to be generated.

    :return: void
    """
    repository_path = clone_repository(verbose)

    try:
        # -- FLASHING THE BITFILE TO THE HARDWARE
        # For the flashing process there already exists an CLI command within this very application. So the simplest
        # thing is to just invoke this command to do the flashing process here.
        bitfile_path = os.path.join(repository_path, CONFIG.get_ci_bitfile_path())
        exit_code = execute_command('ufotest flash {}'.format(bitfile_path), True)
        if exit_code:
            # TODO: there seems to be a problem where the flash command does not reurn exit code 1 even with an error.
            click.secho('(+) There was a problem flashing the bitfile!')
            sys.exit(1)
        click.secho('(+) New bitfile flashed to the hardware', fg='green')

        # -- RUNNING THE TEST SUITE
        test_runner = TestRunner()
        test_runner.load()
        click.secho('    Tests have been loaded from memory')

        click.secho('    Running test suite: {}'.format(suite))
        test_report = test_runner.run_suite(suite)
        click.secho('(+) Test report saved to "{}"'.format(test_runner.folder_path), fg='green')

        # -- COPY THE BIT FILE INTO THE ARCHIVE
        bitfile_archive_path = os.path.join(test_runner.folder_path, 'snapshot.bit')
        shutil.copy(bitfile_path, bitfile_archive_path)
        click.secho('(+) Copied the used version of the bitfile: {}'.format(bitfile_archive_path), fg='green')

    except Exception as e:
        click.secho('[!] Exception: {}'.format(str(e)), fg='red')

    finally:
        # At the end it is important that we remove the cloned repo again, so that the next build process can clone the
        # new repo version into the same path.
        shutil.rmtree(repository_path)
        click.secho('(+) deleted repository folder: {}'.format(repository_path), fg='green')
예제 #5
0
def install_package(package_name: str, verbose=True):
    """
    Installs a system package with the given "package_name"
    """
    operating_system = CONFIG['install']['os']
    package_install_command = CONFIG['install'][operating_system][
        'package_install']

    click.secho('Installing package "{}"...'.format(package_name))

    command = '{} {}'.format(package_install_command, package_name)
    exit_code = execute_command(command, verbose)

    if not exit_code:
        click.secho('Successfully installed "{}"'.format(package_name),
                    fg='green')
        return True
    else:
        click.secho(
            'Encountered an error while installing "{}"'.format(package_name),
            fg='yellow')
        return False
예제 #6
0
def pci_write(addr: str, value: str):
    pci_command = 'pci -w {} {}'.format(addr, value)
    exit_code = execute_command(pci_command, verbose=False)
    if exit_code:
        click.secho('Command "{}" failed!'.format(pci_command), fg='red')