def __init__(self, args): self._original_excepthook = sys.excepthook self._configuration = CONF self._security_manager = SecurityManager() self._mappers_manager = MapperManager() self._changes_controller = ChangeController() self._db_manager = DbManager() self._model_controller = ModelController(self._security_manager, self._mappers_manager) self._plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins"), self._mappers_manager) self._reports_manager = ReportManager( 10, self._plugin_manager.createController("ReportManager")) self._workspace_manager = WorkspaceManager(self._db_manager, self._mappers_manager, self._changes_controller, self._reports_manager) self.gui_app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, args.gui) self.gui_app.setSplashImage( os.path.join(CONF.getImagePath(), "splash2.png"))
def process_workspaces(mappers_manager, plugin_manager, query, disable_polling): report_managers = [] controllers = [] for workspace in query.all(): pending_actions = Queue() plugin_controller = PluginController( 'PluginController', plugin_manager, mappers_manager, pending_actions ) mappers_manager.createMappers(workspace.name) controller = ModelController(mappers_manager, pending_actions) workspace_manager = WorkspaceManager(mappers_manager) setUpAPIs(controller, workspace_manager, hostname=None, port=None) controller.start() controllers.append(controller) report_manager = ReportManager( 0.1, workspace.name, plugin_controller, polling=not disable_polling ) report_managers.append(report_manager) report_manager.start() for report_manager in report_managers: report_manager.stop() for controller in controllers: controller.stop()
def testWatchReportPath(self): import os.path import os workspace_name = common.new_random_workspace_name() timer = 10 report_manager = ReportManager(timer, mock()) report_manager.watch(workspace_name) self.assertTrue(os.path.exists(os.path.join(CONF.getReportPath(), workspace_name)), 'Report directory not found')
def testWatchReportPath(self): import os.path import os workspace_name = common.new_random_workspace_name() timer = 10 report_manager = ReportManager(timer, mock()) report_manager.watch(workspace_name) self.assertTrue( os.path.exists(os.path.join(CONF.getReportPath(), workspace_name)), 'Report directory not found')
def openWorkspace(self, name): # The method openWorkspace can return a workspace or # raise en Exception. For now, just raise it to the caller if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager(10, name, self.plugin_controller) self.report_manager.start() except Exception as e: raise e return ws
def openWorkspace(self, name): """Open a workspace by name. Returns the workspace of raises an exception if for some reason it couldn't. """ if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager(10, name, self.plugin_controller) self.report_manager.start() except Exception as e: raise e return ws
def openDefaultWorkspace(self): """ Opens the default workspace (called 'untitled'). This method shouldn't fail, since the default workspace should be always available Returns the default workspace """ if self.report_manager: self.report_manager.stop() self.report_manager.join() ws = self.getWorkspaceManager().openDefaultWorkspace() self.report_manager = ReportManager(10, ws.name, self.plugin_controller) self.report_manager.start() return ws
def __init__(self, args): self._original_excepthook = sys.excepthook self._configuration = CONF self._security_manager = SecurityManager() self._mappers_manager = MapperManager() self._changes_controller = ChangeController() self._db_manager = DbManager() self._model_controller = ModelController(self._security_manager, self._mappers_manager) self._plugin_manager = PluginManager(os.path.join(CONF.getConfigPath(), "plugins"), self._mappers_manager) self._reports_manager = ReportManager(10, self._plugin_manager.createController("ReportManager")) self._workspace_manager = WorkspaceManager( self._db_manager, self._mappers_manager, self._changes_controller, self._reports_manager ) self.gui_app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, args.gui) self.gui_app.setSplashImage(os.path.join(CONF.getImagePath(), "splash2.png")) self.timer = TimerClass() self.timer.start()
def process_workspaces(mappers_manager, plugin_manager, query, disable_polling): report_managers = [] controllers = [] for workspace in query.all(): pending_actions = Queue() plugin_controller = PluginController('PluginController', plugin_manager, mappers_manager, pending_actions) mappers_manager.createMappers(workspace.name) controller = ModelController(mappers_manager, pending_actions) workspace_manager = WorkspaceManager(mappers_manager) setUpAPIs(controller, workspace_manager, hostname=None, port=None) controller.start() controllers.append(controller) report_manager = ReportManager(0.1, workspace.name, plugin_controller, polling=not disable_polling) report_managers.append(report_manager) report_manager.start()
def openWorkspace(self, name): # The method openWorkspace can return a workspace or # raise en Exception. For now, just raise it to the caller if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager( 10, name) self.report_manager.start() except Exception as e: raise e return ws
def openDefaultWorkspace(self): """ Opens the default workspace (called 'untitled'). This method shouldn't fail, since the default workspace should be always available Returns the default workspace """ if self.report_manager: self.report_manager.stop() self.report_manager.join() ws = self.getWorkspaceManager().openDefaultWorkspace() self.report_manager = ReportManager( 10, ws.name) self.report_manager.start() return ws
def openWorkspace(self, name): """Open a workspace by name. Returns the workspace of raises an exception if for some reason it couldn't. """ if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager( 10, name, self.plugin_controller ) self.report_manager.start() except Exception as e: raise e return ws
class FaradayUi(object): def __init__(self, model_controller, plugin_manager, workspace_manager, plugin_controller, gui="gtk"): self.model_controller = model_controller self.plugin_manager = plugin_manager self.workspace_manager = workspace_manager self.plugin_controller = plugin_controller self.report_manager = None def getModelController(self): return self.model_controller def getPluginManager(self): return self.plugin_manager def getWorkspaceManager(self): return self.workspace_manager def setSplashImage(self, ipath): pass def startSplashScreen(self): pass def stopSplashScreen(self): pass def splashMessage(self, message): pass def loadWorkspaces(self): pass def run(self, args): pass def quit(self): pass def postEvent(self, receiver, event): pass def createLoggerWidget(self): pass def openWorkspace(self, name): """Open a workspace by name. Returns the workspace of raises an exception if for some reason it couldn't. """ if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager( 10, name, self.plugin_controller ) self.report_manager.start() except Exception as e: raise e return ws
class FaradayUi(object): def __init__(self, model_controller=None, plugin_manager=None, workspace_manager=None, gui="qt3"): self.model_controller = model_controller self.plugin_manager = plugin_manager self.workspace_manager = workspace_manager self.report_manager = None def getModelController(self): return self.model_controller def getPluginManager(self): return self.plugin_manager def getWorkspaceManager(self): return self.workspace_manager def setSplashImage(self, ipath): pass def startSplashScreen(self): pass def stopSplashScreen(self): pass def splashMessage(self, message): pass def loadWorkspaces(self): pass def run(self, args): pass def quit(self): pass def postEvent(self, receiver, event): pass def createLoggerWidget(self): pass def openWorkspace(self, name): # The method openWorkspace can return a workspace or # raise en Exception. For now, just raise it to the caller if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager( 10, name) self.report_manager.start() except Exception as e: raise e return ws def openDefaultWorkspace(self): """ Opens the default workspace (called 'untitled'). This method shouldn't fail, since the default workspace should be always available Returns the default workspace """ if self.report_manager: self.report_manager.stop() self.report_manager.join() ws = self.getWorkspaceManager().openDefaultWorkspace() self.report_manager = ReportManager( 10, ws.name) self.report_manager.start() return ws
class FaradayUi(object): def __init__(self, model_controller, plugin_manager, workspace_manager, plugin_controller, gui="qt3"): self.model_controller = model_controller self.plugin_manager = plugin_manager self.workspace_manager = workspace_manager self.plugin_controller = plugin_controller self.report_manager = None def getModelController(self): return self.model_controller def getPluginManager(self): return self.plugin_manager def getWorkspaceManager(self): return self.workspace_manager def setSplashImage(self, ipath): pass def startSplashScreen(self): pass def stopSplashScreen(self): pass def splashMessage(self, message): pass def loadWorkspaces(self): pass def run(self, args): pass def quit(self): pass def postEvent(self, receiver, event): pass def createLoggerWidget(self): pass def openWorkspace(self, name): # The method openWorkspace can return a workspace or # raise en Exception. For now, just raise it to the caller if self.report_manager: self.report_manager.stop() self.report_manager.join() try: ws = self.getWorkspaceManager().openWorkspace(name) self.report_manager = ReportManager(10, name, self.plugin_controller) self.report_manager.start() except Exception as e: raise e return ws def openDefaultWorkspace(self): """ Opens the default workspace (called 'untitled'). This method shouldn't fail, since the default workspace should be always available Returns the default workspace """ if self.report_manager: self.report_manager.stop() self.report_manager.join() ws = self.getWorkspaceManager().openDefaultWorkspace() self.report_manager = ReportManager(10, ws.name, self.plugin_controller) self.report_manager.start() return ws
def testStartReportNoPathRunsException(self): report_manager = ReportManager(0, mock()) self.assertRaises(NoReportsWatchException, report_manager.startWatch)
class MainApplication(object): """ """ def __init__(self, args): self._original_excepthook = sys.excepthook self._configuration = CONF self._security_manager = SecurityManager() self._mappers_manager = MapperManager() self._changes_controller = ChangeController() self._db_manager = DbManager() self._model_controller = ModelController(self._security_manager, self._mappers_manager) self._plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins"), self._mappers_manager) self._reports_manager = ReportManager( 10, self._plugin_manager.createController("ReportManager")) self._workspace_manager = WorkspaceManager(self._db_manager, self._mappers_manager, self._changes_controller, self._reports_manager) self.gui_app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, args.gui) self.gui_app.setSplashImage( os.path.join(CONF.getImagePath(), "splash2.png")) def enableExceptHook(self): sys.excepthook = exception_handler installThreadExcepthook() def disableLogin(self): CONF.setAuth(sys.disablelogin) def start(self): try: self.gui_app.startSplashScreen() self.gui_app.splashMessage("Starting Faraday") signal.signal(signal.SIGINT, self.ctrlC) logged = True while True: username, password = "******", "password" if username is None and password is None: break result = self._security_manager.authenticateUser( username, password) if result == codes.successfulLogin: logged = True break if logged: model.api.devlog("Starting application...") model.api.devlog("Setting up remote API's...") # We need to create the last used workspace (or the default # workspace) before we start the model controller and the # report manager last_workspace = CONF.getLastWorkspace() if not self._workspace_manager.workspaceExists(last_workspace): getLogger(self).info( "Your last workspace (" + last_workspace + ") wasn't accessible, check configuration...") self._workspace_manager.openDefaultWorkspace() #self._workspace_manager.createWorkspace(last_workspace, 'default workspace, probably created already in couchb') else: self._workspace_manager.openWorkspace(last_workspace) model.api.setUpAPIs(self._model_controller, self._workspace_manager, CONF.getApiConInfoHost(), CONF.getApiConInfoPort()) model.guiapi.setUpGUIAPIs(self._model_controller) model.api.devlog("Starting model controller daemon...") self._model_controller.start() model.api.startAPIServer() restapi.startAPIs(self._plugin_manager, self._model_controller, self._mappers_manager, CONF.getApiConInfoHost(), CONF.getApiRestfulConInfoPort()) # Start report manager here getLogger(self).debug("Starting Reports Manager Thread") self._reports_manager.startWatch() model.api.devlog("Faraday ready...") model.api.__current_logged_user = username self.gui_app.splashMessage("Loading workspace... Please wait.") self.gui_app.loadWorkspaces() self.gui_app.stopSplashScreen() except Exception: print "There was an error while starting Faraday" print "-" * 50 traceback.print_exc() print "-" * 50 self.__exit(-1) if logged: exit_code = self.gui_app.run([]) #exit_code = self.app.exec_loop() else: exit_code = -1 return self.__exit(exit_code) def __exit(self, exit_code=0): """ Exits the application with the provided code. It also waits until all app threads end. """ model.api.devlog("Closing Faraday...") model.api.devlog("stopping model controller thread...") model.api.stopAPIServer() restapi.stopServer() self._reports_manager.stop() self._changes_controller.stop() self._model_controller.stop() self._model_controller.join() self.gui_app.quit() model.api.devlog("Waiting for controller threads to end...") return exit_code def quit(self): """ Redefined quit handler to nicely end up things """ self.gui_app.quit() def ctrlC(self, signal, frame): getLogger(self).info("Exiting...") self.__exit(exit_code=0) def getWorkspaceManager(self): return self._workspace_manager
class MainApplication(object): """ """ def __init__(self, args): self._original_excepthook = sys.excepthook self._configuration = CONF self._security_manager = SecurityManager() self._mappers_manager = MapperManager() self._changes_controller = ChangeController() self._db_manager = DbManager() self._model_controller = ModelController(self._security_manager, self._mappers_manager) self._plugin_manager = PluginManager(os.path.join(CONF.getConfigPath(), "plugins"), self._mappers_manager) self._reports_manager = ReportManager(10, self._plugin_manager.createController("ReportManager")) self._workspace_manager = WorkspaceManager( self._db_manager, self._mappers_manager, self._changes_controller, self._reports_manager ) self.gui_app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, args.gui) self.gui_app.setSplashImage(os.path.join(CONF.getImagePath(), "splash2.png")) self.timer = TimerClass() self.timer.start() def enableExceptHook(self): sys.excepthook = exception_handler installThreadExcepthook() def disableLogin(self): CONF.setAuth(sys.disablelogin) def start(self): try: self.gui_app.startSplashScreen() self.gui_app.splashMessage("Starting Faraday") signal.signal(signal.SIGINT, self.ctrlC) logged = True while True: username, password = "******", "password" if username is None and password is None: break result = self._security_manager.authenticateUser(username, password) if result == codes.successfulLogin: logged = True break if logged: model.api.devlog("Starting application...") model.api.devlog("Setting up remote API's...") # We need to create the last used workspace (or the default # workspace) before we start the model controller and the # report manager last_workspace = CONF.getLastWorkspace() try: if not self._workspace_manager.workspaceExists(last_workspace): getLogger(self).info( "Your last workspace (" + str(last_workspace) + ") wasn't accessible, check configuration..." ) self._workspace_manager.openDefaultWorkspace() # self._workspace_manager.createWorkspace(last_workspace, 'default workspace, probably created already in couchb') else: self._workspace_manager.openWorkspace(last_workspace) except restkit.errors.Unauthorized: print "You are trying to enter CouchDB with authentication" print "Add your credentials to your user configuration file in $HOME/.faraday/config/user.xml" print "For example: <couch_uri>http://john:[email protected]:5984</couch_uri>" return model.api.setUpAPIs( self._model_controller, self._workspace_manager, CONF.getApiConInfoHost(), CONF.getApiConInfoPort() ) model.guiapi.setUpGUIAPIs(self._model_controller) model.api.devlog("Starting model controller daemon...") self._model_controller.start() model.api.startAPIServer() restapi.startAPIs( self._plugin_manager, self._model_controller, self._mappers_manager, CONF.getApiConInfoHost(), CONF.getApiRestfulConInfoPort(), ) # Start report manager here getLogger(self).debug("Starting Reports Manager Thread") self._reports_manager.startWatch() model.api.devlog("Faraday ready...") model.api.__current_logged_user = username self.gui_app.splashMessage("Loading workspace... Please wait.") self.gui_app.loadWorkspaces() self.gui_app.stopSplashScreen() except Exception: print "There was an error while starting Faraday" print "-" * 50 traceback.print_exc() print "-" * 50 self.__exit(-1) if logged: exit_code = self.gui_app.run([]) # exit_code = self.app.exec_loop() else: exit_code = -1 return self.__exit(exit_code) def __exit(self, exit_code=0): """ Exits the application with the provided code. It also waits until all app threads end. """ model.api.devlog("Closing Faraday...") model.api.devlog("stopping model controller thread...") model.api.stopAPIServer() restapi.stopServer() self._reports_manager.stop() self._changes_controller.stop() self._model_controller.stop() self._model_controller.join() self.gui_app.quit() self.timer.stop() model.api.devlog("Waiting for controller threads to end...") return exit_code def quit(self): """ Redefined quit handler to nicely end up things """ self.gui_app.quit() def ctrlC(self, signal, frame): getLogger(self).info("Exiting...") self.__exit(exit_code=0) def getWorkspaceManager(self): return self._workspace_manager
def testCreateReportManager(self): timer = 10 report_manager = ReportManager(timer, mock()) self.assertIsNotNone(report_manager)