Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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')
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
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)
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)