Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
def uninstall(self):
if isdir(util.safe_join(self.packages_dir, self.package_name)):
click.echo('Uninstalling %s package:' % click.style(
self.package, fg='cyan'))
shutil.rmtree(
util.safe_join(self.packages_dir, self.package_name))
click.secho(
"""Package \'{}\' has been """
"""successfully uninstalled!""".format(self.package),
fg='green')
else:
util.show_package_path_error(self.package)
self.profile.remove_package(self.package)
self.profile.save()
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:
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
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())
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
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