def valid_arduino_sdk_version(sdk_path, biiout=None):
    """Returns None or version supported as string
    Parameters:
        sdk_path: BASE_FOLDER[/Arduino.app/Contents/Resources/Java]
    """
    path_version = os.path.join(sdk_path, "lib", "version.txt")
    if not os.path.exists(path_version):
        return None

    with open(path_version) as versiontxt:
        data = versiontxt.read()

    if OSInfo.is_linux():
        if _incompatible_avr_gcc_version_in_path():
            if biiout:
                biiout.warn("There isn't a fully compatible version of gcc-avr"
                          " so it can fail compiling some modules like WiFi.h\n"
                          "It's not a biicode issue, official arduino SDK will fail too. "
                          "More information is available here: http://goo.gl/AldCzv\n"
                          "You can solve this issue by uninstalling apt-get version of gcc-avr:\n"
                          " $ sudo apt-get remove gcc-avr\n"
                          " $ bii setup:arduino\n"
                          " $ bii clean\n"
                          " $ bii arduino:configure\n")

    for version in ARDUINO_SDK_COMPATIBLE_VERSIONS:
        if version in data:
            return version

    return None
Beispiel #2
0
def valid_arduino_sdk_version(sdk_path, biiout=None):
    """Returns None or version supported as string
    Parameters:
        sdk_path: BASE_FOLDER[/Arduino.app/Contents/Resources/Java]
    """
    path_version = os.path.join(sdk_path, "lib", "version.txt")
    if not os.path.exists(path_version):
        return None

    with open(path_version) as versiontxt:
        data = versiontxt.read()

    if OSInfo.is_linux():
        if _incompatible_avr_gcc_version_in_path():
            if biiout:
                biiout.warn(
                    "There isn't a fully compatible version of gcc-avr"
                    " so it can fail compiling some modules like WiFi.h\n"
                    "It's not a biicode issue, official arduino SDK will fail too. "
                    "More information is available here: http://goo.gl/AldCzv\n"
                    "You can solve this issue by uninstalling apt-get version of gcc-avr:\n"
                    " $ sudo apt-get remove gcc-avr\n"
                    " $ bii setup:arduino\n"
                    " $ bii clean\n"
                    " $ bii arduino:configure\n")

    for version in ARDUINO_SDK_COMPATIBLE_VERSIONS:
        if version in data:
            return version

    return None
def _get_standard_path():
    if OSInfo.is_win():
        return 'C:/Program Files (x86)/Arduino'
    elif OSInfo.is_linux():
        return '/usr/share/arduino'
    elif OSInfo.is_mac():
        return '/Applications/Arduino.app/Contents/Resources/Java'
Beispiel #4
0
def _get_standard_path():
    if OSInfo.is_win():
        return 'C:/Program Files (x86)/Arduino'
    elif OSInfo.is_linux():
        return '/usr/share/arduino'
    elif OSInfo.is_mac():
        return '/Applications/Arduino.app/Contents/Resources/Java'
Beispiel #5
0
def _install_cmake(user_io, bii_paths):
    user_io.out.writeln('Downloading and installing CMake %s' % _CMAKE_VERSION, front=Color.GREEN)
    if OSInfo.is_win():
        return _install_cmake_win(user_io, bii_paths)
    elif OSInfo.is_mac():
        return _install_cmake_mac(user_io)
    elif OSInfo.is_linux():
        return _install_cmake_linux(user_io, bii_paths)
Beispiel #6
0
def _install_cmake(user_io, bii_paths):
    user_io.out.writeln('Downloading and installing CMake %s' % _CMAKE_VERSION,
                        front=Color.GREEN)
    if OSInfo.is_win():
        return _install_cmake_win(user_io, bii_paths)
    elif OSInfo.is_mac():
        return _install_cmake_mac(user_io)
    elif OSInfo.is_linux():
        return _install_cmake_linux(user_io, bii_paths)
Beispiel #7
0
    def upload(self, possible_firmwares):
        '''Uploading the firmware to Arduino'''
        firmware = _firmware_to_upload(self.bii, possible_firmwares)
        self.bii.user_io.out.writeln('Uploading...')

        build_command = 'make' if sys.platform != 'win32' else 'mingw32-make'
        if OSInfo.is_linux():
            build_command = "sudo %s" % build_command
        build_command = "%s %s-upload" % (build_command, firmware)
        self._execute_upload_command(build_command)
Beispiel #8
0
    def upload(self, possible_firmwares):
        '''Uploading the firmware to Arduino'''
        firmware = _firmware_to_upload(self.bii, possible_firmwares)
        self.bii.user_io.out.writeln('Uploading...')

        build_command = 'make' if sys.platform != 'win32' else 'mingw32-make'
        if OSInfo.is_linux():
            build_command = "sudo %s" % build_command
        build_command = "%s %s-upload" % (build_command, firmware)
        self._execute_upload_command(build_command)
Beispiel #9
0
def get_arduino_download_url(version):
    if OSInfo.is_win():
        url = S3_URL + "arduino-%s-windows.zip" % version
    elif OSInfo.is_mac():
        url = S3_URL + "arduino-%s-macosx.zip" % version
    elif OSInfo.is_linux():
        if OSInfo.architecture() == "64bit":
            url = S3_URL + "arduino-%s-linux64.tgz" % version
        elif OSInfo.architecture() == "32bit":
            url = S3_URL + "arduino-%s-linux32.tgz" % version
    return url
Beispiel #10
0
def get_arduino_download_url(version):
    if OSInfo.is_win():
        url = S3_URL + "arduino-%s-windows.zip" % version
    elif OSInfo.is_mac():
        url = S3_URL + "arduino-%s-macosx.zip" % version
    elif OSInfo.is_linux():
        if OSInfo.architecture() == "64bit":
            url = S3_URL + "arduino-%s-linux64.tgz" % version
        elif OSInfo.architecture() == "32bit":
            url = S3_URL + "arduino-%s-linux32.tgz" % version
    return url
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')
Beispiel #12
0
    def settings(self, *parameters):
        '''Configure Raspberry Pi project settings'''
        parser = argparse.ArgumentParser(description=self.settings.__doc__,
                                         prog="bii %s:settings" % self.group)
        parser.add_argument('--user', help='Your RPi user session, e.g.: pi')
        parser.add_argument("--ip", help="Your RPi IP, e.g.: 50.1.2.3")
        parser.add_argument(
            "--directory",
            help="Directory where you'll send the binary files, e.g.: bin")
        args = parser.parse_args(*parameters)  # for -h

        settings = self.hive_disk_image.settings
        if any([args.user, args.ip, args.directory]):
            rpi_settings_args(args, settings)
        else:
            rpi_settings_wizard(self.user_io, settings)

        #Write to disk
        self.hive_disk_image.settings = settings
        self.user_io.out.info('Settings saved in:  %s' % self.paths.settings)

        toolchain_rpi_path = os.path.join(self.paths.bii,
                                          "rpi_toolchain.cmake")
        if not os.path.exists(toolchain_rpi_path):
            if OSInfo.is_linux():
                self.user_io.out.write('Creating toolchain for Raspberry PI\n',
                                       Color.BLUE)
                c_path, cpp_path = find_gnu_arm()
                if not c_path or not cpp_path:
                    self.user_io.out.error(
                        "Unable to find RPI cross-compilers.\n"
                        "Try executing bii setup:rpi")

                content = []
                content.append("INCLUDE(CMakeForceCompiler)")
                content.append("SET(CMAKE_SYSTEM_NAME Linux)")
                content.append("SET(CMAKE_SYSTEM_VERSION 1)")
                content.append("SET(CMAKE_C_COMPILER %s)" % c_path)
                content.append("SET(CMAKE_CXX_COMPILER %s)" % cpp_path)
                content = os.linesep.join(content)
                save_blob_if_modified(toolchain_rpi_path, Blob(content))

                self.user_io.out.success(
                    'Run "bii configure -t rpi" to activate it')
                self.user_io.out.success(
                    'Run "bii configure -t" to disable it')
            else:
                self.user_io.out.error(
                    "Toolchain for R-Pi only available in Linux now")
                self.user_io.out.error(
                    "You can try to define your own bii/rpi_toolchain.cmake")
Beispiel #13
0
def _get_cmake_download_url():
    if OSInfo.is_win():
        url = S3_URL + "cmake-%s-win32-x86.zip" % _CMAKE_VERSION
    elif OSInfo.is_mac():
        url = S3_URL + 'cmake-%s-Darwin64-universal.dmg' % _CMAKE_VERSION
    elif OSInfo.is_linux():
        import platform
        if OSInfo.architecture() == "64bit":
            url = S3_URL + "cmake-%s-Linux-64.tar.gz" % _CMAKE_VERSION
        elif OSInfo.architecture() == "32bit":
            url = S3_URL + "cmake-%s-Linux-i386.tar.gz" % _CMAKE_VERSION
        if platform.machine() == "armv6l" or platform.machine() == "armv7l":
            url = S3_URL + "cmake-%s-Linux-armv6.tar.gz" % _CMAKE_VERSION
    return url
Beispiel #14
0
def _get_cmake_download_url():
    if OSInfo.is_win():
        url = S3_URL + "cmake-%s-win32-x86.zip" % _CMAKE_VERSION
    elif OSInfo.is_mac():
        url = S3_URL + 'cmake-%s-Darwin64-universal.dmg' % _CMAKE_VERSION
    elif OSInfo.is_linux():
        import platform
        if OSInfo.architecture() == "64bit":
            url = S3_URL + "cmake-%s-Linux-64.tar.gz" % _CMAKE_VERSION
        elif OSInfo.architecture() == "32bit":
            url = S3_URL + "cmake-%s-Linux-i386.tar.gz" % _CMAKE_VERSION
        if platform.machine() == "armv6l" or platform.machine() == "armv7l":
            url = S3_URL + "cmake-%s-Linux-armv6.tar.gz" % _CMAKE_VERSION
    return url
Beispiel #15
0
    def rpi(self, *parameters):
        '''Setup cross compiler tools for Raspberry Pi (must be linux)'''
        parser = argparse.ArgumentParser(description=self.rpi.__doc__,
                                         prog="bii %s:rpi" % self.group)
        parser.add_argument("-i", "--interactive", default=False,
                            action='store_true',
                            help='Runs in interactive mode, can require user input')
        args = parser.parse_args(*parameters)

        if not OSInfo.is_linux():
            raise BiiException('You need to use a linux OS')

        # If we are installing c++ cross compiler... we need the other c++ tools
        install_gnu_arm(self.bii.user_io)
        self._setup_cpp(args.interactive)
Beispiel #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')
def install_gnu(user_io, optional):
    if _valid_gnu_version(user_io):
        return

    if OSInfo.is_mac():
        user_io.out.warn('A new window will open, please click on "Obtain Xcode" and install'
                         'Xcode from AppStore')
        os.system('xcode-select --install')
        user_io.request_string('Please press ENTER when finished installing cmake')
    elif OSInfo.is_linux():
        user_io.out.warn('Installing as "sudo", enter "sudo" password if requested')
        if OSInfo.is_debian_based_linux():
            os.system('sudo apt-get install build-essential')
        elif OSInfo.is_redhat_based_linux():
            os.system('sudo yum -y install wget make automake gcc gcc-c++ kernel-devel')
    else:
        return install_mingw(user_io, optional)
Beispiel #18
0
    def rpi(self, *parameters):
        '''Setup cross compiler tools for Raspberry Pi (must be linux)'''
        parser = argparse.ArgumentParser(description=self.rpi.__doc__,
                                         prog="bii %s:rpi" % self.group)
        parser.add_argument(
            "-i",
            "--interactive",
            default=False,
            action='store_true',
            help='Runs in interactive mode, can require user input')
        args = parser.parse_args(*parameters)

        if not OSInfo.is_linux():
            raise BiiException('You need to use a linux OS')

        # If we are installing c++ cross compiler... we need the other c++ tools
        install_gnu_arm(self.bii.user_io)
        self._setup_cpp(args.interactive)
Beispiel #19
0
    def settings(self, *parameters):
        '''Configure Raspberry Pi project settings'''
        parser = argparse.ArgumentParser(description=self.settings.__doc__,
                                         prog="bii %s:settings" % self.group)
        parser.add_argument('--user', help='Your RPi user session, e.g.: pi')
        parser.add_argument("--ip", help="Your RPi IP, e.g.: 50.1.2.3")
        parser.add_argument("--directory", help="Directory where you'll send the binary files, e.g.: bin")
        args = parser.parse_args(*parameters)  # for -h

        settings = self.hive_disk_image.settings
        if any([args.user, args.ip, args.directory]):
            rpi_settings_args(args, settings)
        else:
            rpi_settings_wizard(self.user_io, settings)

        #Write to disk
        self.hive_disk_image.settings = settings
        self.user_io.out.info('Settings saved in:  %s' % self.paths.settings)

        toolchain_rpi_path = os.path.join(self.paths.bii, "rpi_toolchain.cmake")
        if not os.path.exists(toolchain_rpi_path):
            if OSInfo.is_linux():
                self.user_io.out.write('Creating toolchain for Raspberry PI\n', Color.BLUE)
                c_path, cpp_path = find_gnu_arm()
                if not c_path or not cpp_path:
                    self.user_io.out.error("Unable to find RPI cross-compilers.\n"
                                           "Try executing bii setup:rpi")

                content = []
                content.append("INCLUDE(CMakeForceCompiler)")
                content.append("SET(CMAKE_SYSTEM_NAME Linux)")
                content.append("SET(CMAKE_SYSTEM_VERSION 1)")
                content.append("SET(CMAKE_C_COMPILER %s)" % c_path)
                content.append("SET(CMAKE_CXX_COMPILER %s)" % cpp_path)
                content = os.linesep.join(content)
                save_blob_if_modified(toolchain_rpi_path, Blob(content))

                self.user_io.out.success('Run "bii configure -t rpi" to activate it')
                self.user_io.out.success('Run "bii configure -t" to disable it')
            else:
                self.user_io.out.error("Toolchain for R-Pi only available in Linux now")
                self.user_io.out.error("You can try to define your own bii/rpi_toolchain.cmake")
Beispiel #20
0
def unzip(filename, destination):
    import zipfile
    with zipfile.ZipFile(filename, "r") as z:
        if OSInfo.is_linux() or OSInfo.is_mac():
            for zinfo in z.filelist:
                zinfo.create_system = 3  # UNIX
        if OSInfo.is_mac():
            for thefile in z.filelist:
                name = thefile.filename
                perm = ((thefile.external_attr >> 16L) & 0777)
                if name.endswith('/'):
                    os.mkdir(os.path.join(destination, name), perm)
                else:
                    outfile = os.path.join(destination, name)
                    fh = os.open(outfile, os.O_CREAT | os.O_WRONLY, perm)
                    os.write(fh, z.read(name))
                    os.close(fh)
            z.close()
        else:
            z.extractall(destination)
Beispiel #21
0
def unzip(filename, destination):
    import zipfile
    with zipfile.ZipFile(filename, "r") as z:
        if OSInfo.is_linux() or OSInfo.is_mac():
            for zinfo in z.filelist:
                zinfo.create_system = 3  # UNIX
        if OSInfo.is_mac():
            for thefile in z.filelist:
                name = thefile.filename
                perm = ((thefile.external_attr >> 16L) & 0777)
                if name.endswith('/'):
                    os.mkdir(os.path.join(destination, name), perm)
                else:
                    outfile = os.path.join(destination, name)
                    fh = os.open(outfile, os.O_CREAT | os.O_WRONLY, perm)
                    os.write(fh, z.read(name))
                    os.close(fh)
            z.close()
        else:
            z.extractall(destination)
def install_gnu_arm(user_io):
    if not OSInfo.is_linux():
        raise ClientException("ARM Cross compile only works on Linux")

    install_linux_x32_compatibility(user_io)
    c_path, cpp_path = find_gnu_arm()
    if c_path is None or cpp_path is None:
        url = S3_URL + "raspberry_cross_compilers.tgz"
        filename = download(url, url.split("/")[-1])
        user_io.out.info("Unzipping arm gnu SDK")
        install_path = get_biicode_env_folder_path()
        if not os.path.exists(install_path):
            os.mkdir(install_path)
        decompress(filename, install_path)
        user_io.out.success('Installed GNU ARM compilers for RPI')
        # Try to find again
        c_path, cpp_path = find_gnu_arm()
    else:
        user_io.out.writeln('The arm gnu is already downloaded', front=Color.GREEN)
    return c_path, cpp_path
Beispiel #23
0
def install_gnu_arm(user_io):
    if not OSInfo.is_linux():
        raise ClientException("ARM Cross compile only works on Linux")

    install_linux_x32_compatibility(user_io)
    c_path, cpp_path = find_gnu_arm()
    if c_path is None or cpp_path is None:
        url = S3_URL + "raspberry_cross_compilers.tgz"
        filename = download(url, url.split("/")[-1])
        user_io.out.info("Unzipping arm gnu SDK")
        install_path = get_biicode_env_folder_path()
        if not os.path.exists(install_path):
            os.mkdir(install_path)
        decompress(filename, install_path)
        user_io.out.success('Installed GNU ARM compilers for RPI')
        # Try to find again
        c_path, cpp_path = find_gnu_arm()
    else:
        user_io.out.writeln('The arm gnu is already downloaded',
                            front=Color.GREEN)
    return c_path, cpp_path
Beispiel #24
0
def install_gnu(user_io, optional):
    if _valid_gnu_version(user_io):
        return

    if OSInfo.is_mac():
        user_io.out.warn(
            'A new window will open, please click on "Obtain Xcode" and install'
            'Xcode from AppStore')
        os.system('xcode-select --install')
        user_io.request_string(
            'Please press ENTER when finished installing cmake')
    elif OSInfo.is_linux():
        user_io.out.warn(
            'Installing as "sudo", enter "sudo" password if requested')
        if OSInfo.is_debian_based_linux():
            os.system('sudo apt-get install build-essential')
        elif OSInfo.is_redhat_based_linux():
            os.system(
                'sudo yum -y install wget make automake gcc gcc-c++ kernel-devel'
            )
    else:
        return install_mingw(user_io, optional)