How to use the tockloader.helpers function in tockloader

To help you get started, we’ve selected a few tockloader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tock / tockloader / tockloader / bootloader_serial.py View on Github external
ports = sorted(list(serial.tools.list_ports.grep(device_name)))
		if must_match and os.path.exists(device_name):
			# In the most specific case a user specified a full path that exists
			# and we should use that specific serial port. We treat this as a
			# special case because something like `/dev/ttyUSB5` will also match
			# `/dev/ttyUSB55`, but it is clear that user expected to use the
			# serial port specified by the full path.
			index = 0
			ports = [serial.tools.list_ports_common.ListPortInfo(device_name)]
		elif len(ports) == 1:
			# Easy case, use the one that matches.
			index = 0
		elif len(ports) > 1:
			# If we get multiple matches then we ask the user to choose from a
			# list.
			index = helpers.menu(ports,
				                 return_type='index',
				                 title='Multiple serial port options found. Which would you like to use?')
		elif must_match:
			# If we get here, then the user did not specify a full path to a
			# serial port, and we couldn't find anything on the board that
			# matches what they specified (which may have just been a short
			# name). Since the user put in the effort of specifically choosing a
			# port, we error here rather than just (arbitrarily) choosing
			# something they didn't specify.
			raise TockLoaderException('Could not find a board matching "{}".'.format(device_name))
		else:
			# Just find any port and use the first one.
			ports = list(serial.tools.list_ports.comports())
			# Macs will report Bluetooth devices with serial, which is
			# almost certainly never what you want, so drop those.
			ports = [p for p in ports if 'Bluetooth-Incoming-Port' not in p[0]]
github tock / tockloader / tockloader / main.py View on Github external
# Search for ".tab" files
		tab_names = glob.glob('./**/*.tab', recursive=True)
		if len(tab_names) == 0:
			raise TockLoaderException('No TAB files found.')

		logging.info('Using: {}'.format(tab_names))

	# Concatenate the binaries.
	tabs = []
	for tab_name in tab_names:
		# Check if this is a TAB locally, or if we should check for it
		# on a remote hosting server.
		if not urllib.parse.urlparse(tab_name).scheme and not os.path.exists(tab_name):
			logging.info('Could not find TAB named "{}" locally.'.format(tab_name))
			response = helpers.menu(['No', 'Yes'],
				return_type='index',
				prompt='Would you like to check the online TAB repository for that app? ')
			if response == 0:
				# User said no, skip this tab_name.
				continue
			else:
				# User said yes, create that URL and try to load the TAB.
				tab_name = 'https://www.tockos.org/assets/tabs/{}.tab'.format(tab_name)

		try:
			tabs.append(TAB(tab_name, args))
		except Exception as e:
			if args.debug:
				logging.debug('Exception: {}'.format(e))
			logging.error('Error opening and reading "{}"'.format(tab_name))
github tock / tockloader / tockloader / bootloader_serial.py View on Github external
# Just find any port and use the first one.
			ports = list(serial.tools.list_ports.comports())
			# Macs will report Bluetooth devices with serial, which is
			# almost certainly never what you want, so drop those.
			ports = [p for p in ports if 'Bluetooth-Incoming-Port' not in p[0]]

			if len(ports) == 0:
				raise TockLoaderException('No serial ports found. Is the board connected?')

			logging.info('No serial port with device name "{}" found.'.format(device_name))
			logging.info('Found {} serial port{}.'.format(len(ports), ('s', '')[len(ports) == 1]))

			if len(ports) == 1:
				index = 0
			else:
				index = helpers.menu(ports,
					                 return_type='index',
					                 title='Multiple serial port options found. Which would you like to use?')

		logging.info('Using "{}".'.format(ports[index]))
		port = ports[index][0]
		helpers.set_terminal_title_from_port_info(ports[index])

		# Open the actual serial port
		self.sp = serial.Serial()
		self.sp.port = port
		self.sp.baudrate = 115200
		self.sp.parity=serial.PARITY_NONE
		self.sp.stopbits=1
		self.sp.xonxoff=0
		self.sp.rtscts=0
		self.sp.timeout=0.5
github tock / tockloader / tockloader / tockloader.py View on Github external
# Get a list of installed apps
			apps = self._extract_all_app_headers()

			# If the user didn't specify an app list...
			if len(app_names) == 0:
				if len(apps) == 0:
					raise TockLoaderException('No apps are installed on the board')
				elif len(apps) == 1:
					# If there's only one app, delete it
					app_names = [apps[0].get_name()]
					logging.info('Only one app on board.')
				else:
					options = ['** Delete all']
					options.extend([app.get_name() for app in apps])
					name = helpers.menu(options,
							return_type='value',
							prompt='Select app to uninstall ',
							title='There are multiple apps currently on the board:')
					if name == '** Delete all':
						app_names = [app.get_name() for app in apps]
					else:
						app_names = [name]

			logging.status('Attempting to uninstall:')
			for app_name in app_names:
				logging.status('  - {}'.format(app_name))

			# Remove the apps if they are there
			removed = False
			keep_apps = []
			for app in apps: