Esempio n. 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
Esempio n. 2
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
Esempio n. 3
0
    def create_ini(self, board, project_dir='', sayyes=False):
        """Creates a new apio project file"""

        project_dir = util.check_dir(project_dir)

        ini_path = util.safe_join(project_dir, PROJECT_FILENAME)

        # Check board
        boards = Resources().boards
        if board not in boards.keys():
            click.secho(
                'Error: no such board \'{}\''.format(board),
                fg='red')
            sys.exit(1)

        if isfile(ini_path):
            # -- If sayyes, skip the question
            if sayyes:
                self._create_ini_file(board, ini_path, PROJECT_FILENAME)
            else:
                click.secho(
                    'Warning: {} file already exists'.format(PROJECT_FILENAME),
                    fg='yellow')
                if click.confirm('Do you want to replace it?'):
                    self._create_ini_file(board, ini_path, PROJECT_FILENAME)
                else:
                    click.secho('Abort!', fg='red')
        else:
            self._create_ini_file(board, ini_path, PROJECT_FILENAME)
Esempio n. 4
0
    def create_sconstruct(self, project_dir='', sayyes=False):
        """Creates a default SConstruct file"""

        project_dir = util.check_dir(project_dir)

        sconstruct_name = 'SConstruct'
        sconstruct_path = util.safe_join(project_dir, sconstruct_name)
        local_sconstruct_path = util.safe_join(
            util.get_folder('resources'), sconstruct_name)

        if isfile(sconstruct_path):
            # -- If sayyes, skip the question
            if sayyes:
                self._copy_sconstruct_file(sconstruct_name, sconstruct_path,
                                           local_sconstruct_path)
            else:
                click.secho(
                    'Warning: {} file already exists'.format(sconstruct_name),
                    fg='yellow')

                if click.confirm('Do you want to replace it?'):
                    self._copy_sconstruct_file(sconstruct_name,
                                               sconstruct_path,
                                               local_sconstruct_path)
                else:
                    click.secho('Abort!', fg='red')

        else:
            self._copy_sconstruct_file(sconstruct_name, sconstruct_path,
                                       local_sconstruct_path)
Esempio n. 5
0
    def copy_example_dir(self, example, project_dir, sayno):
        if isdir(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:
            click.secho('Error: examples are not installed', fg='red')
            click.secho('Please run:\n'
                        '   apio install examples',
                        fg='yellow')
            return 1
        return 0
Esempio n. 6
0
    def __init__(self, project_dir=''):
        self.profile = Profile()
        self.resources = Resources()

        if project_dir is not None:
            # Move to project dir
            project_dir = util.check_dir(project_dir)
            os.chdir(project_dir)
Esempio n. 7
0
    def __init__(self, project_dir=''):
        self.profile = Profile()
        self.resources = Resources()

        if project_dir is not None:
            # Move to project dir
            project_dir = util.check_dir(project_dir)
            os.chdir(project_dir)
Esempio n. 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
Esempio n. 9
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
Esempio n. 10
0
    def copy_example_files(self, example, project_dir, sayno):
        if isdir(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:
            click.secho('Error: examples are not installed', fg='red')
            click.secho('Please run:\n'
                        '   apio install examples',
                        fg='yellow')
            return 1
        return 0