def _get_command_arguments(self, request): raw_arguments = self.get_request_param(request, 'args') if isinstance(raw_arguments, (str, unicode)): return normalize_all_command_arguments(raw_arguments.split(',')) elif isinstance(raw_arguments, (list, tuple)): return normalize_all_command_arguments(raw_arguments) else: return []
def main(): cli_manager = make_parser().parse_args() player_query = None group_query = None if cli_manager.player: player_query = ' '.join(cli_manager.player) elif cli_manager.group: group_query = ' '.join(cli_manager.group) elif os.path.isfile(LAST_DEVICE_FILE_LOCATION): with open(LAST_DEVICE_FILE_LOCATION, 'r') as fh: player_query = fh.readline() print('Searching Last Player:', player_query) else: print('Could not determine last device used! Player will be chosen at random.') try: device_manager = SonosDeviceManager(player_query, group_query) with open(LAST_DEVICE_FILE_LOCATION, 'w+') as fh: fh.write(device_manager.device.player_name) except exc.ControllerException as e: print(e) return else: print('Selected Group:', device_manager.device.group.label) print('Selected Player:', device_manager.device.player_name) command_args = normalize_all_command_arguments(cli_manager.args) try: result = device_manager.perform_command(cli_manager.command, *command_args) except exc.BadCommandException as e: print(e) return if not isinstance(result, (str, unicode)): result_output = pprint.pformat(result) else: result_output = result print('{command}: {value}'.format(command=cli_manager.command, value=result_output))