Ejemplo n.º 1
0
    def _generate_project(self, toolchain_file, parameters):
        '''runs CMake to generate Makefiles or Project'''
        # Obtain generator
        settings = self.hive_disk_image.settings
        generator = settings.cmake.generator

        # Define toolchain if necessary, for arduino or cross building
        toolchain = '' if not toolchain_file else '-DCMAKE_TOOLCHAIN_FILE=%s' % toolchain_file

        # Define command to run
        parameters = ' '.join(parameters)
        cmake_rel_path = os.path.relpath(self.bii_paths.cmake,
                                         self.bii_paths.build)
        command = ('"%s" %s -G "%s" -Wno-dev %s %s' % (cmake_command(
            self.bii_paths), toolchain, generator, parameters, cmake_rel_path))
        self.user_io.out.write('Running: %s\n' % command)

        if 'NMake' in generator:
            # VS specific: it is neccesary to call vcvarall
            self.user_io.out.warn(
                'NMake generator must run in a shell with compiler defined.\n'
                'It might not work if not')
            command = command_with_vcvars(generator, self.bii_paths.build,
                                          command)

        retcode, cmake_output = execute(command,
                                        self.user_io,
                                        cwd=self.bii_paths.build)
        if 'Does not match the generator used previously' in cmake_output:
            try:
                self.user_io.out.warn(
                    'Previous generator does not match. Deleting build folder '
                    'and trying again')
                self.hive_disk_image.delete_build_folder()
            except Exception as e:
                self.user_io.out.warn('Could not complete deletion %s' %
                                      str(e))
            self.user_io.out.warn('Running cmake again')
            retcode, cmake_output = execute(command,
                                            self.user_io,
                                            cwd=self.bii_paths.build)
        if retcode != 0:
            logger.error(cmake_output)
            raise BiiException('CMake failed')

        if 'Eclipse' in self.hive_disk_image.settings.cmake.generator:
            ide = Eclipse(self.bii_paths)
            ide.configure_project()
            self.user_io.out.success(
                'Eclipse project in %s\n'
                'Open eclipse, select "File > Import > General > '
                'Existing project into Workspace" '
                'and select folder\n' % self.bii_paths.project_root)
Ejemplo n.º 2
0
    def ssh(self):
        user, ip, _ = self._rpi_settings

        command = ('ssh %s@%s' % (user, ip))
        self.user_io.out.info('Connecting with %s\n' % command)
        _, out = execute(command, self.user_io)
        self.user_io.out.info("%s" % out)
Ejemplo n.º 3
0
    def upload(self, firmware):
        '''Uploading the firmware to Arduino'''
        self.bii.user_io.out.write('Uploading...')
        build_command = 'make' if sys.platform != 'win32' else 'mingw32-make'
        if platform.system() == 'Linux':
            build_command = " sudo %s" % build_command
        build_command = "%s %s-upload" % (build_command, firmware)
        # This is needed for Arduino Leonardo boards
        # see:http://nicholaskell.wordpress.com/2012/08/11/arduino-leonardo-upload-from-makefile/
        arduino_settings = self.settings
        if arduino_settings.board == "leonardo":
            import serial
            import time
            ser = serial.Serial(
                port=arduino_settings.port,
                baudrate=1200,
                parity=serial.PARITY_NONE,
                stopbits=serial.STOPBITS_ONE,
                bytesize=serial.EIGHTBITS
            )
            while not ser.isOpen():
                pass
            ser.close()
            time.sleep(2)

        hive_paths = HivePaths(self.bii.current_folder)
        retcode, out = execute(build_command, self.bii.user_io, cwd=hive_paths.build)
        errors = out.strip().split(os.linesep)
        if retcode != 0 or 'Error' in errors[-1]:
            logger.error(out)
            raise BiiException('Upload failed')
        return True
Ejemplo n.º 4
0
    def upload(self, firmware):
        '''Uploading the firmware to Arduino'''
        self.bii.user_io.out.write('Uploading...')
        build_command = 'make' if sys.platform != 'win32' else 'mingw32-make'
        if platform.system() == 'Linux':
            build_command = " sudo %s" % build_command
        build_command = "%s %s-upload" % (build_command, firmware)
        # This is needed for Arduino Leonardo boards
        # see:http://nicholaskell.wordpress.com/2012/08/11/arduino-leonardo-upload-from-makefile/
        arduino_settings = self.settings
        if arduino_settings.board == "leonardo":
            import serial
            import time
            ser = serial.Serial(port=arduino_settings.port,
                                baudrate=1200,
                                parity=serial.PARITY_NONE,
                                stopbits=serial.STOPBITS_ONE,
                                bytesize=serial.EIGHTBITS)
            while not ser.isOpen():
                pass
            ser.close()
            time.sleep(2)

        hive_paths = HivePaths(self.bii.current_folder)
        retcode, out = execute(build_command,
                               self.bii.user_io,
                               cwd=hive_paths.build)
        errors = out.strip().split(os.linesep)
        if retcode != 0 or 'Error' in errors[-1]:
            logger.error(out)
            raise BiiException('Upload failed')
        return True
Ejemplo n.º 5
0
    def ssh(self):
        user, ip, _ = self._rpi_settings

        command = ('ssh %s@%s' % (user, ip))
        self.user_io.out.info('Connecting with %s\n' % command)
        _, out = execute(command, self.user_io)
        self.user_io.out.info("%s" % out)
Ejemplo n.º 6
0
def gnu_version(compiler):
    try:
        _, output = execute('%s --version' % compiler, ui=UserIO(out=BiiOutputStream()))
        installed_version = re.search("[0-9]\.[0-9]\.[0-9]", output).group()
    except:
        installed_version = ''
    if installed_version:
        return Version(installed_version)
Ejemplo n.º 7
0
    def _generate_project(self, toolchain_file, parameters):
        '''runs CMake to generate Makefiles or Project'''
        # Obtain generator
        settings = self.hive_disk_image.settings
        generator = settings.cmake.generator

        # Define toolchain if necessary, for arduino or cross building
        toolchain = '' if not toolchain_file else '-DCMAKE_TOOLCHAIN_FILE=%s' % toolchain_file

        # Define command to run
        parameters = ' '.join(parameters)
        cmake_rel_path = os.path.relpath(self.bii_paths.cmake, self.bii_paths.build)
        command = ('"%s" %s -G "%s" -Wno-dev %s %s'
                   % (cmake_command(self.bii_paths), toolchain, generator, parameters,
                      cmake_rel_path))
        self.user_io.out.write('Running: %s\n' % command)

        if 'NMake' in generator:
            # VS specific: it is neccesary to call vcvarall
            self.user_io.out.warn('NMake generator must run in a shell with compiler defined.\n'
                                  'It might not work if not')
            command = command_with_vcvars(generator, self.bii_paths.build, command)

        retcode, cmake_output = execute(command, self.user_io, cwd=self.bii_paths.build)
        if 'Does not match the generator used previously' in cmake_output:
            try:
                self.user_io.out.warn('Previous generator does not match. Deleting build folder '
                                      'and trying again')
                self.hive_disk_image.delete_build_folder()
            except Exception as e:
                self.user_io.out.warn('Could not complete deletion %s' % str(e))
            self.user_io.out.warn('Running cmake again')
            retcode, cmake_output = execute(command, self.user_io, cwd=self.bii_paths.build)
        if retcode != 0:
            logger.error(cmake_output)
            raise BiiException('CMake failed')

        if 'Eclipse' in self.hive_disk_image.settings.cmake.generator:
            ide = Eclipse(self.bii_paths)
            ide.configure_project()
            self.user_io.out.success('Eclipse project in %s\n'
                                     'Open eclipse, select "File > Import > General > '
                                     'Existing project into Workspace" '
                                     'and select folder\n' % self.bii_paths.project_root)
Ejemplo n.º 8
0
def execute_as(command, root=False):
    try:
        if root and sys.platform == "win32":
            os.startfile(command, "runas")
        else:
            ret_code, output = execute(command)
            return ret_code, output
    except Exception as e:
        print e
        return -1, ''
Ejemplo n.º 9
0
def _incompatible_avr_gcc_version_in_path():
    # Check avr-gcc in path and check version
    exit_code, output = execute("avr-gcc --version", UserIO(out=BiiOutputStream(StringIO())))
    if exit_code == 0:
        for compatible_version in ARDUINO_AVR_COMPATIBLE_VERSIONS:
            if compatible_version in output:
                return False
        return True
    else:  # Not found, so its ok
        return False
Ejemplo n.º 10
0
def execute_as(command, root=False):
    try:
        if root and sys.platform == "win32":
            os.startfile(command, "runas")
        else:
            ret_code, output = execute(command)
            return ret_code, output
    except Exception as e:
        print e
        return -1, ''
Ejemplo n.º 11
0
def _incompatible_avr_gcc_version_in_path():
    # Check avr-gcc in path and check version
    exit_code, output = execute("avr-gcc --version",
                                UserIO(out=BiiOutputStream(StringIO())))
    if exit_code == 0:
        for compatible_version in ARDUINO_AVR_COMPATIBLE_VERSIONS:
            if compatible_version in output:
                return False
        return True
    else:  # Not found, so its ok
        return False
Ejemplo n.º 12
0
def install_linux_x32_compatibility(user_io):
    if OSInfo.is_linux() and OSInfo.architecture() == Architecture("64bit"):
        cmd = "dpkg-query -S lib32z1"
        exit_code, _ = execute(cmd, UserIO(out=BiiOutputStream(StringIO())))
        if exit_code == 0:
            user_io.out.writeln('x86 compatibility for 64bits already installed',
                                front=Color.GREEN)
        else:
            user_io.out.writeln('Installing x86 compatibility for 64bits architecture...',
                                front=Color.GREEN)
            user_io.out.warn('Installing lib32z1 as "sudo", enter "sudo" password if requested')
            os.system('sudo apt-get install lib32z1')
Ejemplo n.º 13
0
    def sync_dinlib(self):
        """Synchronize Rpi OpenGLES shared libs to hive lib folder."""
        user, ip, _, _ = self._rpi_settings

        hive_lib_path = os.path.join(self.paths.hive, "lib")
        command = "rsync -chavzP {}@{}:'/opt/vc/lib/* /opt/vc/include' {}".format(user, ip,
                                                                                  hive_lib_path)

        rsync_status, _ = execute(command, self.user_io)
        if rsync_status:
            self.user_io.out.error("Cannot connect to RaspberryPi make sure that it is "
                                   "connected to the network.")
Ejemplo n.º 14
0
    def sync_dinlib(self):
        """Synchronize Rpi OpenGLES shared libs to hive lib folder."""
        user, ip, _, _ = self._rpi_settings

        hive_lib_path = os.path.join(self.paths.hive, "lib")
        command = "rsync -chavzP {}@{}:'/opt/vc/lib/* /opt/vc/include' {}".format(
            user, ip, hive_lib_path)

        rsync_status, _ = execute(command, self.user_io)
        if rsync_status:
            self.user_io.out.error(
                "Cannot connect to RaspberryPi make sure that it is "
                "connected to the network.")
Ejemplo n.º 15
0
    def send_sync(self):
        '''Send by rsync the bin folder into the specified directory.'''
        bin_dir = self.paths.bin
        user, ip, directory = self._rpi_settings
        rpi_directory = '%s/%s/' % (directory, self.paths.project_name)

        command = ('rsync -aq --rsync-path="mkdir -p ~/%s && rsync" -Pravdtze ssh %s/* %s@%s:%s'
                   % (rpi_directory, bin_dir, user, ip, rpi_directory))
        self.user_io.out.info('Sending with %s\n' % command)
        try:
            _, out = execute(command, self.user_io, cwd=bin_dir)
            if out:
                self.user_io.out.info("%s" % out)
        except Exception as e:
            raise ClientException('Sending bin folder\n'
                                  'ERROR: %s\n' % str(e))
Ejemplo n.º 16
0
def install_linux_x32_compatibility(user_io):
    if OSInfo.is_linux() and OSInfo.architecture() == Architecture("64bit"):
        cmd = "dpkg-query -S lib32z1"
        exit_code, _ = execute(cmd, UserIO(out=BiiOutputStream(StringIO())))
        if exit_code == 0:
            user_io.out.writeln(
                'x86 compatibility for 64bits already installed',
                front=Color.GREEN)
        else:
            user_io.out.writeln(
                'Installing x86 compatibility for 64bits architecture...',
                front=Color.GREEN)
            user_io.out.warn(
                'Installing lib32z1 as "sudo", enter "sudo" password if requested'
            )
            os.system('sudo apt-get install lib32z1')
Ejemplo n.º 17
0
    def send_sync(self):
        '''Send by rsync the bin folder into the specified directory.'''
        bin_dir = self.paths.bin
        user, ip, directory = self._rpi_settings
        rpi_directory = '%s/%s/' % (directory, self.paths.project_name)

        command = (
            'rsync -aq --rsync-path="mkdir -p ~/%s && rsync" -Pravdtze ssh %s/* %s@%s:%s'
            % (rpi_directory, bin_dir, user, ip, rpi_directory))
        self.user_io.out.info('Sending with %s\n' % command)
        try:
            _, out = execute(command, self.user_io, cwd=bin_dir)
            if out:
                self.user_io.out.info("%s" % out)
        except Exception as e:
            raise ClientException('Sending bin folder\n'
                                  'ERROR: %s\n' % str(e))