Exemplo n.º 1
0
 def createWorkspace(self, name, desc, dbtype=DBTYPE.COUCHDB):
     workspace = Workspace(name, desc)
     try:
         dbConnector = self.dbManager.createDb(name, dbtype)
     except restkit.Unauthorized:
         raise WorkspaceException(
             (
                 "You're not authorized to create workspaces\n"
                 "Make sure you're an admin and add your credentials"
                 "to your user configuration "
                 "file in $HOME/.faraday/config/user.xml\n"
                 "For example: "
                 "<couch_uri>http://john:[email protected]:5984</couch_uri>"
             )
         )
     except Exception as e:
         raise WorkspaceException(str(e))
     if dbConnector:
         self.closeWorkspace()
         self.mappersManager.createMappers(dbConnector)
         self.mappersManager.save(workspace)
         self.setActiveWorkspace(workspace)
         notification_center.workspaceChanged(workspace, self.getWorkspaceType(name))
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         return workspace
     return False
Exemplo n.º 2
0
 def openWorkspace(self, name):
     """Open a workspace by name. Returns the workspace. Raises an
     WorkspaceException if something went wrong along the way.
     """
     if name not in self.getWorkspacesNames():
         raise WorkspaceException("Workspace %s wasn't found" % name)
     self.closeWorkspace()
     try:
         dbConnector = self.dbManager.getConnector(name)
     except restkit.Unauthorized:
         raise WorkspaceException(
             (
                 "You're not authorized to access this workspace\n"
                 "Add your credentials to your user configuration "
                 "file in $HOME/.faraday/config/user.xml\n"
                 "For example: "
                 "<couch_uri>http://john:[email protected]:5984</couch_uri>"
             )
         )
     except Exception as e:
         notification_center.CouchDBConnectionProblem(e)
         raise WorkspaceException(str(e))
     self.mappersManager.createMappers(dbConnector)
     workspace = self.mappersManager.getMapper(Workspace.__name__).find(name)
     if not workspace:
         raise WorkspaceException(
             ("Error loading workspace.\n" "You should try opening faraday " "with the '--update' option")
         )
     self.setActiveWorkspace(workspace)
     notification_center.workspaceChanged(workspace, self.getWorkspaceType(name))
     notification_center.workspaceLoad(workspace.getHosts())
     self.changesManager.watch(self.mappersManager, dbConnector)
     return workspace
Exemplo n.º 3
0
 def openWorkspace(self, name):
     """Open a workspace by name. Returns the workspace. Raises an
     WorkspaceException if something went wrong along the way.
     """
     if name not in self.getWorkspacesNames():
         raise WorkspaceException("Workspace %s wasn't found" % name)
     self.closeWorkspace()
     try:
         dbConnector = self.dbManager.getConnector(name)
     except restkit.Unauthorized:
         raise WorkspaceException(
             ("You're not authorized to access this workspace\n"
              "Add your credentials to your user configuration "
              "file in $HOME/.faraday/config/user.xml\n"
              "For example: "
              "<couch_uri>http://john:[email protected]:5984</couch_uri>"))
     except Exception as e:
         notification_center.CouchDBConnectionProblem(e)
         raise WorkspaceException(str(e))
     self.mappersManager.createMappers(dbConnector)
     workspace = self.mappersManager.getMapper(
         Workspace.__name__).find(name)
     if not workspace:
         raise WorkspaceException(("Error loading workspace.\n"
                                   "You should try opening faraday "
                                   "with the '--update' option"))
     self.setActiveWorkspace(workspace)
     notification_center.workspaceChanged(workspace,
                                          self.getWorkspaceType(name))
     notification_center.workspaceLoad(workspace.getHosts())
     self.changesManager.watch(self.mappersManager, dbConnector)
     return workspace
Exemplo n.º 4
0
 def createWorkspace(self, name, desc, dbtype=DBTYPE.COUCHDB):
     workspace = Workspace(name, desc)
     try:
         dbConnector = self.dbManager.createDb(name, dbtype)
     except restkit.Unauthorized:
         raise WorkspaceException(
             ("You're not authorized to create workspaces\n"
              "Make sure you're an admin and add your credentials"
              "to your user configuration "
              "file in $HOME/.faraday/config/user.xml\n"
              "For example: "
              "<couch_uri>http://john:[email protected]:5984</couch_uri>"))
     except Exception as e:
         raise WorkspaceException(str(e))
     if dbConnector:
         self.closeWorkspace()
         self.mappersManager.createMappers(dbConnector)
         self.mappersManager.save(workspace)
         self.setActiveWorkspace(workspace)
         notification_center.workspaceChanged(workspace,
                                              self.getWorkspaceType(name))
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         return workspace
     return False
Exemplo n.º 5
0
 def load(self):
                                                    
     files = os.listdir(self._path)
     files = filter(lambda f: f.endswith(".json") and f not in
             self._persistence_excluded_filenames, files)
     modelobjectcontainer = self.getContainee()
     for filename in files:
         newHost = self.__loadHostFromFile(filename)
         modelobjectcontainer[newHost.getID()] = newHost
     notifier.workspaceLoad(self.getAllHosts())
Exemplo n.º 6
0
    def load(self):

        files = os.listdir(self._path)
        files = filter(
            lambda f: f.endswith(".json") and f not in self.
            _persistence_excluded_filenames, files)
        modelobjectcontainer = self.getContainee()
        for filename in files:
            newHost = self.__loadHostFromFile(filename)
            modelobjectcontainer[newHost.getID()] = newHost
        notifier.workspaceLoad(self.getAllHosts())
Exemplo n.º 7
0
 def createWorkspace(self, name, desc, dbtype=DBTYPE.FS):
     workspace = Workspace(name, desc)
     dbConnector = self.dbManager.createDb(name, dbtype)
     if dbConnector:
         self.closeWorkspace()
         self.mappersManager.createMappers(dbConnector)
         self.mappersManager.save(workspace)
         self.setActiveWorkspace(workspace)
         notification_center.workspaceChanged(workspace)
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         self.reportsManager.watch(name)
         return workspace
     return False
Exemplo n.º 8
0
 def openWorkspace(self, name):
     if name in self.getWorkspacesNames():
         self.closeWorkspace()
         dbConnector = self.dbManager.getConnector(name)
         self.mappersManager.createMappers(dbConnector)
         workspace = self.mappersManager.getMapper(Workspace.__name__).find(name)
         self.setActiveWorkspace(workspace)
         CONF.setLastWorkspace(name)
         CONF.saveConfig()
         notification_center.workspaceChanged(workspace)
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         self.reportsManager.watch(name)
         return workspace
     return None
Exemplo n.º 9
0
 def createWorkspace(self, name, desc, dbtype=DBTYPE.FS):
     workspace = Workspace(name, desc)
     dbConnector = self.dbManager.createDb(name, dbtype)
     if dbConnector:
         self.closeWorkspace()
         self.mappersManager.createMappers(dbConnector)
         self.mappersManager.save(workspace)
         self.setActiveWorkspace(workspace)
         CONF.setLastWorkspace(name)
         CONF.saveConfig()
         notification_center.workspaceChanged(workspace)
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         self.reportsManager.watch(name)
         return workspace
     return False
Exemplo n.º 10
0
 def openWorkspace(self, name):
     if name in self.getWorkspacesNames():
         self.closeWorkspace()
         dbConnector = self.dbManager.getConnector(name)
         self.mappersManager.createMappers(dbConnector)
         workspace = self.mappersManager.getMapper(Workspace.__name__).find(name)
         if not workspace:
             notification_center.showDialog(
                 "Error loading workspace.\nYou should try opening faraday with the '--update' option",
                 level="ERROR")
             return self.openDefaultWorkspace()
         self.setActiveWorkspace(workspace)
         CONF.setLastWorkspace(name)
         CONF.saveConfig()
         notification_center.workspaceChanged(workspace)
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         self.reportsManager.watch(name)
         return workspace
     return None
Exemplo n.º 11
0
 def openWorkspace(self, name):
     if name in self.getWorkspacesNames():
         self.closeWorkspace()
         dbConnector = self.dbManager.getConnector(name)
         self.mappersManager.createMappers(dbConnector)
         workspace = self.mappersManager.getMapper(Workspace.__name__).find(name)
         if not workspace:
             notification_center.showDialog(
                 "Error loading workspace.\nYou should try opening faraday with the '--update' option",
                 level="ERROR")
             return self.openDefaultWorkspace()
         self.setActiveWorkspace(workspace)
         CONF.setLastWorkspace(name)
         CONF.saveConfig()
         notification_center.workspaceChanged(workspace,self.getWorkspaceType(name))
         notification_center.workspaceLoad(workspace.getHosts())
         self.changesManager.watch(self.mappersManager, dbConnector)
         self.reportsManager.watch(name)
         return workspace
     return None
Exemplo n.º 12
0
            model.api.devlog("time to reconstruct: %s" % str(time.time() - t))
            t = time.time()

            self.container.clear()
            for k, v in hosts.items():
                if k is not "subs":
                    h = Host(name=None, dic=v)
                    self.container[k] = h
            model.api.devlog("time to fill container: %s" %
                             str(time.time() - t))
            t = time.time()
        except Exception, e:
            model.api.devlog("Exception during load: %s" % e)
        finally:
            self._model_controller.setSavingModel(False)
            notifier.workspaceLoad(self.getAllHosts())


class WorkspaceManager(object):
    """
    This handles all workspaces. It checks for existing workspaces inside
    the persistence directory.
    It is in charge of starting the WorkspacesAutoSaver to persist each workspace.
    This class stores information in $HOME/.faraday/config/workspacemanager.xml file
    to keep track of created workspaces to be able to load them
    """
    def __init__(self, model_controller, plugin_controller):
        self.active_workspace = None

        self._couchAvailable = False
        self.report_manager = ReportManager(10, plugin_controller)
Exemplo n.º 13
0
                leaf[key] = sub
            model.api.devlog("time to reconstruct: %s" % str(time.time() - t))
            t = time.time()

            self.container.clear()
            for k, v in hosts.items():
                if k is not "subs":
                    h = Host(name=None, dic=v)
                    self.container[k] = h
            model.api.devlog("time to fill container: %s" % str(time.time() - t))
            t = time.time()
        except Exception, e:
            model.api.devlog("Exception during load: %s" % e)
        finally:
            self._model_controller.setSavingModel(False)
            notifier.workspaceLoad(self.getAllHosts())


class WorkspaceManager(object):
    """
    This handles all workspaces. It checks for existing workspaces inside
    the persistence directory.
    It is in charge of starting the WorkspacesAutoSaver to persist each workspace.
    This class stores information in $HOME/.faraday/config/workspacemanager.xml file
    to keep track of created workspaces to be able to load them
    """
    def __init__(self, model_controller, plugin_controller):
        self.active_workspace = None
                                                                  
        self._couchAvailable  = False 
        self.report_manager = ReportManager(10, plugin_controller)