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
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
def test_workspace_serialization(self): workspace = Workspace(name="workspace_test") workspace.setDescription("Some description") workspace.setCustomer("Infobyte") wserialized = self.wmapper.serialize(workspace) # if serialization fails, returns None self.assertNotEqual( wserialized, None, "Serialized workspace shouldn't be None") # we check the host attributes self.assertEquals( wserialized.get("_id"), workspace.getID(), "Serialized ID is not the same as workspace ID") self.assertEquals( wserialized.get("name"), workspace.getName(), "Serialized name is not the same as workspace name") self.assertEquals( wserialized.get("description"), workspace.getDescription(), "Serialized description is not the same as workspace description") self.assertEquals( wserialized.get("customer"), workspace.getCustomer(), "Serialized customer is not the same as workspace customer")
def testGetWorkspaceTypeFS(self): work = Workspace('testname') dbManager = mock() mappersManager = mock() changesController = mock() when(dbManager).getDbType('testname').thenReturn(DBTYPE.FS) workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock()) wtype = workspace_manager.getWorkspaceType(work.getName()) self.assertEquals(wtype, 'FS', 'Workspace type not returning correct value')
def openDefaultWorkspace(self): # This method opens the default workspace called 'untitled' if "untitled" not in self.getWorkspacesNames(): workspace = Workspace("untitled", "default workspace") dbConnector = self.dbManager.createDb(workspace.getName(), DBTYPE.FS) if self.active_workspace: self.closeWorkspace() self.mappersManager.createMappers(dbConnector) self.mappersManager.save(workspace) return self.openWorkspace("untitled")
def test_workspace_creation(self): workspace = Workspace(name="workspace_test") self.wmapper.save(workspace) w = self.wmapper.find(workspace.getID()) self.assertEquals( w, workspace, "Workspace retrieved should be the same as persisted") self.assertEquals( w.getID(), workspace.getID(), "Workspace retrieved's Id should be the same as persisted's Id")
def openDefaultWorkspace(self): #This method opens the default workspace called 'untitled' if 'untitled' not in self.getWorkspacesNames(): workspace = Workspace('untitled', 'default workspace') dbConnector = self.dbManager.createDb(workspace.getName(), DBTYPE.FS) if self.active_workspace: self.closeWorkspace() self.mappersManager.createMappers(dbConnector) self.mappersManager.save(workspace) return self.openWorkspace('untitled')
def post(self): user = users.get_current_user() name = self.request.get("name") ws = Workspace(user = user, name = unicode(name)) ws.put() backlog = Column(workspace = ws, name = u"Backlog", allow_create = True) backlog.put() for i in range(1, 5): c = Column(workspace = ws, name = u"Column %s" % i) c.put()
def test_workspace_create_and_delete(self): workspace = Workspace(name="workspace_test") self.wmapper.save(workspace) w_id = workspace.getID() self.assertNotEquals(self.wmapper.load(w_id), None, "Workspace should be saved") self.wmapper.delete(w_id) self.assertEquals(self.wmapper.find(w_id), None, "Workspace shouldn't exist anymore")
def testSetActiveWorkspace(self): work = Workspace('testname') dbManager = mock() mappersManager = mock() changesController = mock() workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock()) workspace_manager.setActiveWorkspace(work) self.assertEquals(workspace_manager.active_workspace, work, 'active workspace not set') self.assertTrue(workspace_manager.isActive(work.getName()), 'could not retrive as active workspace')
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
def testOpenWorkspaceChangesAndReportManagerWatch(self): reportManager = mock() dbManager = mock() mappersManager = mock() dbConnector = mock() mappers = mock() changesController = mock() workspaceMapper = mock() workspace = Workspace('test_workspace', 'a desc') when(dbManager).getAllDbNames().thenReturn(['test_workspace']) when(dbManager).getConnector('test_workspace').thenReturn(dbConnector) when(mappersManager).createMappers(dbConnector).thenReturn(True) when(mappersManager).getMapper( Workspace.__name__).thenReturn(workspaceMapper) when(workspaceMapper).find('test_workspace').thenReturn(workspace) workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, reportManager) opened_workspace = workspace_manager.openWorkspace('test_workspace') verify(reportManager).watch('test_workspace') verify(changesController).watch(mappersManager, dbConnector) self.assertEquals(opened_workspace.getName(), 'test_workspace')
def test_workspace_create_and_delete(self): workspace = Workspace(name="workspace_test") self.wmapper.save(workspace) w_id = workspace.getID() self.assertNotEquals( self.wmapper.load(w_id), None, "Workspace should be saved") self.wmapper.delete(w_id) self.assertEquals( self.wmapper.find(w_id), None, "Workspace shouldn't exist anymore")
def createWorkspace(self, name, desc, start_date=int(time.time() * 1000), finish_date=int(time.time() * 1000), customer=""): # XXX: DEPRECATE NEXT LINE workspace = Workspace(name, desc) try: create_workspace(name, description=desc, start_date=start_date, finish_date=finish_date, customer=customer) except 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)) self.mappersManager.createMappers(name) self.setActiveWorkspace(workspace) notification_center.workspaceChanged(workspace) return name
def __init__(self, config): self.config = config self.score_dir = config.get_argv().score_file self.benchmark_config = config.get_argv().benchmark_config self.task = Task(config) self.workspace = Workspace(config) self.ssh_user = config.get_value('User', 'SSH') self.ssh_passwd_file = config.get_value('PasswdFile', 'SSH') self.ssh_port = config.get_value('Port', 'SSH') self.subnet_ip = config.get_value('ip', 'Subnet') self.subnet_name = config.get_value('name', 'Subnet') self.mode = config.get_value('Mode') self.pwd = os.path.dirname(__file__) self.mq_tag = str(time.time()).replace('.', '_') self._benchmark_pressure_tag_id = None self.logs_dir = os.path.join(self.pwd, '../logs/') self.logger = logging.getLogger(__name__) self.lockfile = self.__lockfile() self.logger.setLevel(logging.DEBUG) handler = logging.FileHandler("log.txt") handler.setLevel(logging.DEBUG) formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) self.logger.addHandler(handler)
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
def post(self): user = users.get_current_user() name = self.request.get("name") ws = Workspace(user = user, name = unicode(name)) ws.put() backlog = Column(workspace = ws, name = u"Backlog", allow_create = True) backlog.put() for i in range(1, 5): c = Column(workspace = ws, name = u"Column %s" % i) c.put() data = {ws.id: ws.json} res = json.dumps(data, indent=4) self.error(200) self.response.out.write(res)
def delete(cls, user_name, id): workspace = Workspace.select().get(id) if workspace.user_name != user_name: raise ServerException('无权限') planners = WeeklyPlanner.select().filter( WeeklyPlanner.workspace_id == id).all() if len(planners) != 0: raise ServerException('存在计划,请先删除计划') workspace.delete() return True
def get(self, *args): if not len(args): user = users.get_current_user() workspaceList = Workspace.gql("WHERE user = :1", user) data = {} for w in workspaceList: data[w.id] = w.json res = json.dumps(data, indent=4) self.error(200) self.response.out.write(res) elif len(args) == 1: ws = Workspace.get("WHERE name = :1", args[0]) if not ws: self.response.out.write("{}") return data = {ws.id: ws.json} res = json.dumps(data, indent=4) self.error(200) self.response.out.write(res) return else: raise NotImplemented("WorkspaceQuery does not expect more than one parameter")
def get(self): user = users.get_current_user() if user: nickname = user.nickname() else: nickname = None workspaces = Workspace.gql("WHERE user = :1", user) params = { "sign_in_url": users.create_login_url("/"), "sign_out_url": users.create_logout_url("/"), "nickname": nickname, "workspaces": workspaces, "add_workspace_url": "/" } self.response.out.write(template.render("templates/main.html", params))
def save(cls, user_name, id, name): if id is not None: workspace = Workspace.select().get(id) workspace.name = name workspace.update() return id else: workspace = Workspace(user_name=user_name, name=name) workspace.insert() return Workspace.select().filter(Workspace.user_name == user_name, Workspace.name == name).first().id
def testRemoveWorkspace(self): dbManager = mock() mappersManager = mock() dbConnector = mock() mappers = mock() changesController = mock() workspace = Workspace('test_workspace', 'a desc') when(dbManager).removeDb('test_workspace').thenReturn(True) when(dbManager).getAllDbNames().thenReturn(['test_workspace']) workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock()) remove_ret = workspace_manager.removeWorkspace('test_workspace') verify(dbManager).removeDb('test_workspace') self.assertTrue(remove_ret, 'bbdd not removed')
def testOpenWorkspaceNoneExisting(self): dbManager = mock() mappersManager = mock() dbConnector = mock() mappers = mock() changesController = mock() workspace = Workspace('test_workspace', 'a desc') when(dbManager).getAllDbNames().thenReturn([]) workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock()) opened_workspace = workspace_manager.openWorkspace('test_workspace') verify(mappersManager, times=0).createMappers(dbConnector) verify(mappersManager, times=0).find('test_workspace') self.assertFalse(opened_workspace, 'Workspace retrieved but non existing')
def list(cls, user_name): workspaces = Workspace.select().filter( Workspace.user_name == user_name).order_by( Workspace.updated_at.desc()).all() workspace_ids = [workspace.id for workspace in workspaces] planners = WeeklyPlanner.select().filter( WeeklyPlanner.workspace_id.in_(workspace_ids)).all() planner_map = {} for planner in planners: if planner_map.get(planner.workspace_id, None) is None: planner_map[planner.workspace_id] = [planner.get_json()] else: planner_map[planner.workspace_id].append(planner.get_json()) results = [] for workspace in workspaces: result = workspace.get_json() result['planners'] = planner_map.get(workspace.id, []) results.append(result) return results
def testOpenWorkspaceSetsChangesCallback(self): dbManager = mock() mappersManager = mock() dbConnector = mock() mappers = mock() changesController = mock() workspaceMapper = mock() workspace = Workspace('test_workspace', 'a desc') when(dbManager).getConnector('test_workspace').thenReturn(dbConnector) when(mappersManager).getMapper( Workspace.__name__).thenReturn(workspaceMapper) when(dbManager).getAllDbNames().thenReturn(['test_workspace']) when(mappersManager).createMappers(dbConnector).thenReturn(True) when(workspaceMapper).find('test_workspace').thenReturn(workspace) workspace_manager = WorkspaceManager(dbManager, mappersManager, changesController, mock()) opened_workspace = workspace_manager.openWorkspace('test_workspace') verify(changesController).watch(mappersManager, dbConnector)
# Argos Application class ArgosApp(wx.App): def OnInit(self): return True app = ArgosApp(0) # The user can specify default colorblindness and palette shuffle modes with these environment variables colorblindness_option = os.environ.get('ARGOS_COLORBLINDNESS_MODE', 'default') palette_shuffle_option = os.environ.get('ARGOS_PALETTE_SHUFFLE_MODE', 'default') gui.autocoloring.BuildBrushes(colorblindness_option, palette_shuffle_option) # Preconfigure the workspace with options # Must be after wx.App is instantiated ws = Workspace() ws.SetPalette(colorblindness_option) ws.SetColorShuffleState(palette_shuffle_option) if args.resource_dir is not None: for rd in args.resource_dir: ws.AddUserResourceDir(rd) # Parse clock if args.clock is not None: select_clock = str(args.clock) else: select_clock = None # Determine start tick start_tick = None
logging.getLogger().addHandler(fileHandler) # Argos Application class ArgosApp(wx.App): def OnInit(self): return True app = ArgosApp(0) settings = ArgosSettings() # The user can specify default colorblindness and palette shuffle modes with these environment variables gui.autocoloring.BuildBrushes(settings.palette, settings.palette_shuffle) # Preconfigure the workspace with options # Must be after wx.App is instantiated ws = Workspace(settings) if args.resource_dir is not None: for rd in args.resource_dir: ws.AddUserResourceDir(rd) # Parse clock if args.clock is not None: select_clock = str(args.clock) else: select_clock = None # Determine start tick start_tick = None if args.start_tick is not None: start_tick = int(args.start_tick)
from model.workspace import Workspace from view.workspace import CabelFrame import wx # Create model w = Workspace() # Create view class CabelApp(wx.App): def OnInit(self): self.frame = CabelFrame(w) self.frame.Show() self.SetTopWindow(self.frame) return True app = CabelApp() # Show view app.MainLoop()