Exemple #1
0
    def copy_example_dir(self, example, project_dir, sayno):
        if util.check_package(
            self.name,
            self.version,
            self.spec_version,
            self.examples_dir
        ):
            project_dir = util.check_dir(project_dir)
            example_path = util.safe_join(project_dir, example)
            local_example_path = util.safe_join(self.examples_dir, example)

            if isdir(local_example_path):
                if isdir(example_path):

                    # -- If sayno, do not copy anything
                    if not sayno:
                        click.secho(
                            'Warning: ' + example +
                            ' directory already exists', fg='yellow')

                        if click.confirm('Do you want to replace it?'):
                            shutil.rmtree(example_path)
                            self._copy_dir(example, local_example_path,
                                           example_path)
                elif isfile(example_path):
                    click.secho(
                        'Warning: ' + example + ' is already a file',
                        fg='yellow')
                else:
                    self._copy_dir(example, local_example_path, example_path)
            else:
                click.secho(EXAMPLE_NOT_FOUND_MSG, fg='yellow')
        else:
            return 1
        return 0
Exemple #2
0
 def list_examples(self):
     if util.check_package(self.name, self.version, self.spec_version,
                           self.examples_dir):
         # examples = sorted(os.listdir(self.examples_dir))
         examples = [
             dirname(y).replace(self.examples_dir + sep, '')
             for x in os.walk(self.examples_dir)
             for y in glob.glob(util.safe_join(x[0], 'info'))
         ]
         click.secho('')
         for example in examples:
             example_dir = util.safe_join(self.examples_dir, example)
             if isdir(example_dir):
                 info_path = util.safe_join(example_dir, 'info')
                 info = ''
                 if isfile(info_path):
                     with codecs.open(info_path, 'r', 'utf-8') as info_file:
                         info = info_file.read().replace('\n', '')
                 click.secho(' ' + example, fg='blue', bold=True)
                 click.secho('-' * click.get_terminal_size()[0])
                 click.secho(' ' + info)
                 click.secho('')
         click.secho(EXAMPLE_DIR_FILE, fg='green')
         click.secho(EXAMPLE_OF_USE_CAD, fg='green')
     else:
         return 1
     return 0
Exemple #3
0
 def list_examples(self):
     if util.check_package(
         self.name,
         self.version,
         self.spec_version,
         self.examples_dir
     ):
         # examples = sorted(os.listdir(self.examples_dir))
         examples = [dirname(y).replace(self.examples_dir + sep, '')
                     for x in os.walk(self.examples_dir)
                     for y in glob.glob(util.safe_join(x[0], 'info'))]
         click.secho('')
         for example in examples:
             example_dir = util.safe_join(self.examples_dir, example)
             if isdir(example_dir):
                 info_path = util.safe_join(example_dir, 'info')
                 info = ''
                 if isfile(info_path):
                     with codecs.open(info_path, 'r', 'utf-8') as info_file:
                         info = info_file.read().replace('\n', '')
                 click.secho(' ' + example, fg='blue', bold=True)
                 click.secho('-' * click.get_terminal_size()[0])
                 click.secho(' ' + info)
                 click.secho('')
         click.secho(EXAMPLE_DIR_FILE, fg='green')
         click.secho(EXAMPLE_OF_USE_CAD, fg='green')
     else:
         return 1
     return 0
Exemple #4
0
    def copy_example_dir(self, example, project_dir, sayno):
        if util.check_package(self.name, self.version, self.spec_version,
                              self.examples_dir):
            project_dir = util.check_dir(project_dir)
            example_path = util.safe_join(project_dir, example)
            local_example_path = util.safe_join(self.examples_dir, example)

            if isdir(local_example_path):
                if isdir(example_path):

                    # -- If sayno, do not copy anything
                    if not sayno:
                        click.secho('Warning: ' + example +
                                    ' directory already exists',
                                    fg='yellow')

                        if click.confirm('Do you want to replace it?'):
                            shutil.rmtree(example_path)
                            self._copy_dir(example, local_example_path,
                                           example_path)
                elif isfile(example_path):
                    click.secho('Warning: ' + example + ' is already a file',
                                fg='yellow')
                else:
                    self._copy_dir(example, local_example_path, example_path)
            else:
                click.secho(EXAMPLE_NOT_FOUND_MSG, fg='yellow')
        else:
            return 1
        return 0
Exemple #5
0
    def _serial_enable_windows(self):
        drivers_base_dir = util.get_package_dir('tools-drivers')
        drivers_bin_dir = util.safe_join(drivers_base_dir, 'bin')

        try:
            if util.check_package(
                self.name,
                self.version,
                self.spec_version,
                drivers_bin_dir
            ):
                click.secho('Launch drivers configuration tool')
                click.secho(SERIAL_INSTALL_DRIVER_INSTRUCTIONS, fg='yellow')
                result = util.exec_command(
                    util.safe_join(drivers_bin_dir, 'serial_install.exe'))
                click.secho('Serial drivers configuration finished',
                            fg='green')
            else:
                result = 1
        except Exception as e:
            click.secho('Error: ' + str(e), fg='red')
            result = 1

        if not isinstance(result, int):
            result = result.get('returncode')
        return result
Exemple #6
0
    def copy_example_files(self, example, project_dir, sayno):
        if util.check_package(self.name, self.version, self.spec_version,
                              self.examples_dir):
            project_dir = util.check_dir(project_dir)
            example_path = project_dir
            local_example_path = util.safe_join(self.examples_dir, example)

            if isdir(local_example_path):
                self._copy_files(example, local_example_path, example_path,
                                 sayno)
            else:
                click.secho(EXAMPLE_NOT_FOUND_MSG, fg='yellow')
        else:
            return 1
        return 0
Exemple #7
0
    def _run_command(self, command, silent=False):
        result = {}
        system_base_dir = util.get_package_dir('tools-system')
        system_bin_dir = util.safe_join(system_base_dir, 'bin')

        on_stdout = None if silent else self._on_stdout
        on_stderr = self._on_stderr

        if util.check_package(self.name, self.version, self.spec_version,
                              system_bin_dir):
            result = util.exec_command(util.safe_join(system_bin_dir,
                                                      command + self.ext),
                                       stdout=util.AsyncPipe(on_stdout),
                                       stderr=util.AsyncPipe(on_stderr))

        return result
Exemple #8
0
    def copy_example_files(self, example, project_dir, sayno):
        if util.check_package(
            self.name,
            self.version,
            self.spec_version,
            self.examples_dir
        ):
            project_dir = util.check_dir(project_dir)
            example_path = project_dir
            local_example_path = util.safe_join(self.examples_dir, example)

            if isdir(local_example_path):
                self._copy_files(example, local_example_path,
                                 example_path, sayno)
            else:
                click.secho(EXAMPLE_NOT_FOUND_MSG, fg='yellow')
        else:
            return 1
        return 0
Exemple #9
0
    def _run_command(self, command, silent=False):
        result = {}
        system_base_dir = util.get_package_dir('tools-system')
        system_bin_dir = util.safe_join(system_base_dir, 'bin')

        on_stdout = None if silent else self._on_stdout
        on_stderr = self._on_stderr

        if util.check_package(
            self.name,
            self.version,
            self.spec_version,
            system_bin_dir
        ):
            result = util.exec_command(
                util.safe_join(system_bin_dir, command + self.ext),
                stdout=util.AsyncPipe(on_stdout),
                stderr=util.AsyncPipe(on_stderr))

        return result
Exemple #10
0
    def _ftdi_enable_windows(self):
        drivers_base_dir = util.get_package_dir('tools-drivers')
        drivers_bin_dir = util.safe_join(drivers_base_dir, 'bin')
        drivers_share_dir = util.safe_join(drivers_base_dir, 'share')
        zadig_ini_path = util.safe_join(drivers_share_dir, 'zadig.ini')
        zadig_ini = 'zadig.ini'

        try:
            if util.check_package(
                self.name,
                self.version,
                self.spec_version,
                drivers_bin_dir
            ):
                click.secho('Launch drivers configuration tool')
                click.secho(FTDI_INSTALL_DRIVER_INSTRUCTIONS, fg='yellow')
                # Copy zadig.ini
                with open(zadig_ini, 'w') as ini_file:
                    with open(zadig_ini_path, 'r') as local_ini_file:
                        ini_file.write(local_ini_file.read())

                result = util.exec_command(
                    util.safe_join(drivers_bin_dir, 'zadig.exe'))
                click.secho('FTDI drivers configuration finished',
                            fg='green')
            else:
                result = 1
        except Exception as e:
            click.secho('Error: ' + str(e), fg='red')
            result = 1
        finally:
            # Remove zadig.ini
            if isfile(zadig_ini):
                os.remove(zadig_ini)

        if not isinstance(result, int):
            result = result.get('returncode')
        return result