class Bii_GUI(Bii): def __init__(self, user_io, current_folder, biicode_folder): self.user_io = user_io self.current_folder = current_folder self.biicode_folder = biicode_folder toolcatalog = ToolCatalog(BiiCommand, tools=[SetupCommands, GuiArduinoToolChain]) self.executor = ToolExecutor(self, toolcatalog) self._user_cache = None self._biiapi = None def execute(self, argv): '''Executes user provided command. Eg. bii run:cpp''' errors = False try: if isinstance(argv, basestring): # To make tests easier to write argv = shlex.split(argv) self.executor.execute( argv) # Executor only raises not expected Exceptions except (KeyboardInterrupt, SystemExit) as e: logger.debug('Execution terminated: %s', e) errors = True except BiiException as e: errors = True self.user_io.out.write(str(e)) except Exception as e: tb = traceback.format_exc() self.user_io.out.debug(tb) errors = True self.user_io.out.write('Unexpected Exception\n %s' % e) return errors
class Bii_GUI(Bii): def __init__(self, user_io, current_folder, biicode_folder): self.user_io = user_io self.current_folder = current_folder self.biicode_folder = biicode_folder toolcatalog = ToolCatalog(BiiCommand, tools=[SetupCommands, GuiArduinoToolChain]) self.executor = ToolExecutor(self, toolcatalog) self._user_cache = None self._biiapi = None def execute(self, argv): '''Executes user provided command. Eg. bii run:cpp''' errors = False try: if isinstance(argv, basestring): # To make tests easier to write argv = shlex.split(argv) self.executor.execute(argv) # Executor only raises not expected Exceptions except (KeyboardInterrupt, SystemExit) as e: logger.debug('Execution terminated: %s', e) errors = True except BiiException as e: errors = True self.user_io.out.write(str(e)) except Exception as e: tb = traceback.format_exc() self.user_io.out.debug(tb) errors = True self.user_io.out.write('Unexpected Exception\n %s' % e) return errors
class Bii(object): '''Entry point class for bii executable''' def __init__(self, user_io, current_folder, user_biicode_folder): self.user_io = user_io self.bii_paths = BiiPaths(current_folder, user_biicode_folder) self.user_cache = UserCache(self.bii_paths.user_bii_home) toolcatalog = ToolCatalog(BiiCommand, tools=[ CPPToolChain, RPiToolChain, SetupCommands, ArduinoToolChain, NodeToolChain ]) self.executor = ToolExecutor(self, toolcatalog) self._biiapi = None @property def hive_disk_image(self): # not able to keep it persistent, as tests make a database locked operational error return HiveDiskImage(self.bii_paths, self.user_cache, self.user_io.out) @property def biiapi(self): if self._biiapi is None: from biicode.client.api.biiapi_proxy import BiiAPIProxy from biicode.client.api.biiapi_auth_manager import BiiApiAuthManager auth_manager = BiiApiAuthManager(self._restapi, self.user_io, self.user_cache.localdb) self._biiapi = BiiAPIProxy(self.user_cache.localdb, auth_manager, self.user_io) return self._biiapi @property def _restapi(self): return BiiRestApiClient(BII_RESTURL) def execute(self, argv): '''Executes user provided command. Eg. bii run:cpp''' errors = False try: if isinstance(argv, basestring): # To make tests easier to write argv = shlex.split(argv) self.executor.execute( argv) # Executor only raises not expected Exceptions except (KeyboardInterrupt, SystemExit) as e: logger.debug('Execution terminated: %s', e) errors = True except BiiException as e: errors = True self.user_io.out.error(str(e)) except Exception as e: tb = traceback.format_exc() logger.error(tb) errors = True self.user_io.out.error('Unexpected Exception\n %s' % e) self.user_io.out.error( 'Error executing command.\n' '\tCheck the documentation in http://docs.biicode.com\n' '\tor ask in the forum http://forum.biicode.com\n') return errors
class Bii(object): """Entry point class for bii executable""" def __init__(self, user_io, current_folder, user_biicode_folder): self.user_io = user_io self.bii_paths = BiiPaths(current_folder, user_biicode_folder) self.user_cache = UserCache(self.bii_paths.user_bii_home) toolcatalog = ToolCatalog( BiiCommand, tools=[CPPToolChain, RPiToolChain, SetupCommands, ArduinoToolChain, NodeToolChain] ) self.executor = ToolExecutor(self, toolcatalog) self._biiapi = None @property def hive_disk_image(self): # not able to keep it persistent, as tests make a database locked operational error return HiveDiskImage(self.bii_paths, self.user_cache, self.user_io.out) @property def biiapi(self): if self._biiapi is None: from biicode.client.api.biiapi_proxy import BiiAPIProxy from biicode.client.api.biiapi_auth_manager import BiiApiAuthManager auth_manager = BiiApiAuthManager(self._restapi, self.user_io, self.user_cache.localdb) self._biiapi = BiiAPIProxy(self.user_cache.localdb, auth_manager, self.user_io) return self._biiapi @property def _restapi(self): return BiiRestApiClient(BII_RESTURL) def execute(self, argv): """Executes user provided command. Eg. bii run:cpp""" errors = False try: if isinstance(argv, basestring): # To make tests easier to write argv = shlex.split(argv) self.executor.execute(argv) # Executor only raises not expected Exceptions except (KeyboardInterrupt, SystemExit) as e: logger.debug("Execution terminated: %s", e) errors = True except BiiException as e: errors = True self.user_io.out.error(str(e)) except Exception as e: tb = traceback.format_exc() logger.error(tb) errors = True self.user_io.out.error("Unexpected Exception\n %s" % e) self.user_io.out.error( "Error executing command.\n" "\tCheck the documentation in http://docs.biicode.com\n" "\tor ask in the forum http://forum.biicode.com\n" ) return errors
def test_tool_executor(self): bii = Bii(UserIO(out=BiiOutputStream()), "dummy_current_folder", "dummy_user_folder") toolcatalog = ToolCatalog(BiiCommand, tools=[CPPToolChain]) toolcatalog.print_help = Mock(return_value=True) tool = ToolExecutor(bii, toolcatalog) #Effective call tool._call_method = Mock(return_value=True) # --quiet argv = ["cpp:configure", "--quiet"] tool.execute(argv) self.assertEqual(bii.user_io.out.level, 2) # --verbose argv = ["cpp:configure", "--verbose"] tool.execute(argv) self.assertEqual(bii.user_io.out.level, 0) # --version argv = ["--version"] tool.execute(argv) self.assertIn("%s\n" % biicode.common.__version__, str(bii.user_io.out)) # --help argv = ["--help"] tool.execute(argv) toolcatalog.print_help.assert_called_with(bii.user_io.out, []) # Bad command argv = ["paspas"] self.assertRaises(ClientException, tool.execute, argv)