Skip to content

Commit

Permalink
Merge pull request FPGAwars#93 from Obijuan/develop
Browse files Browse the repository at this point in the history
Option -n added
  • Loading branch information
Juan Gonzalez-Gomez committed May 8, 2016
2 parents edfa9de + fbc6286 commit f747f02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
9 changes: 6 additions & 3 deletions apio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,18 @@ def init(ctx, board, project_dir):
help='Copy the selected example files.')
@click.option('--project-dir', type=unicode, metavar='PATH',
help='Set the target directory for the examples')
def examples(ctx, list, dir, files, project_dir):
@click.option('-n', '--sayno', is_flag=True,
help='Automatically answer NO to all the questions')
def examples(ctx, list, dir, files, project_dir, sayno):
"""Manage default verilog examples.\n
Install with `apio install examples`"""

if list:
Examples().list_examples()
elif dir:
Examples().copy_example_dir(dir, project_dir)
Examples().copy_example_dir(dir, project_dir, sayno)
elif files:
Examples().copy_example_files(files, project_dir)
Examples().copy_example_files(files, project_dir, sayno)
else:
click.secho(ctx.get_help())
click.secho(Examples().examples_of_use_cad())
Expand Down
32 changes: 21 additions & 11 deletions apio/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def list_examples(self):
click.secho('Please run:\n'
' apio install examples', fg='yellow')

def copy_example_dir(self, example, project_dir):
def copy_example_dir(self, example, project_dir, sayno):
if isdir(self.examples_dir):

# -- Target dir not specified
Expand All @@ -65,13 +65,17 @@ def copy_example_dir(self, example, project_dir):

if isdir(local_example_path):
if isdir(example_path):
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)

# -- If sayno, do not copy anythin
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',
Expand All @@ -85,7 +89,7 @@ def copy_example_dir(self, example, project_dir):
click.secho('Please run:\n'
' apio install examples', fg='yellow')

def copy_example_files(self, example, project_dir):
def copy_example_files(self, example, project_dir, sayno):
if isdir(self.examples_dir):

if project_dir is not None:
Expand All @@ -96,21 +100,27 @@ def copy_example_files(self, example, project_dir):
local_example_path = join(self.examples_dir, example)

if isdir(local_example_path):
self._copy_files(example, local_example_path, 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')

def _copy_files(self, example, src_path, dest_path):
def _copy_files(self, example, src_path, dest_path, sayno):
click.secho('Copying ' + example + ' example files ...')
example_files = glob.glob(join(src_path, '*'))
for f in example_files:
filename = basename(f)
if filename != 'info':
if isfile(join(dest_path, filename)):

# -- If sayno, do not copy the file. Move to the next
if sayno:
continue

click.secho(
'Warning: ' + filename + ' file already exists',
fg='yellow')
Expand Down

0 comments on commit f747f02

Please sign in to comment.