def test_pull_url_with_creds(self): workspace = CmdWorkspace(self.workspace_dir, self.cmd) cmd = self.TrapCmd(remote='http://example.com/') cmd.write_remote(workspace) workspace = CmdWorkspace(self.workspace_dir, cmd) result = cmd.pull(workspace, username='******', password='******') self.assertTrue( 'http://*****:*****@example.com/' in result[0] or 'http://*****:*****@example.com/' in result[1])
def test_cmd_new_clone(self): remote = 'http://example.com' self.cmd = DemoDvcsCmd(remote=remote) wks = CmdWorkspace(self.workspace_dir, self.cmd) self.assertEqual(self.cmd.queue, [ ['vcs', 'clone', remote, self.workspace_dir], ]) # emulate that creation, which our mocks don't do. os.mkdir(join(self.workspace_dir, self.wks_marker)) self.cmd = DemoDvcsCmd(remote=remote) wks = CmdWorkspace(self.workspace_dir, self.cmd) # nothing. self.assertEqual(self.cmd.queue, [])
def cloneWorkspace(self, remote_workspace_url, local_workspace_dir): # XXX target_dir is assumed to exist, so we can't just clone # but we have to instantiate that as a new repo, define the # remote and pull. # link self.linkWorkspaceDirToUrl( local_workspace_dir=local_workspace_dir, remote_workspace_url=remote_workspace_url, ) workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) # Another caveat: that workspace is possibly private. Acquire # temporary password. creds = self.requestTemporaryPassword(remote_workspace_url) if creds: result = workspace.cmd.pull(workspace, username=creds['user'], password=creds['key']) else: # no credentials logger.info('not using credentials as none are detected') result = workspace.cmd.pull(workspace) # TODO trap this result too? workspace.cmd.reset_to_remote(workspace) return result
def hasDVCS(self, local_workspace_dir): git_dir = os.path.join(local_workspace_dir, '.git') if os.path.isdir(git_dir): bob = get_cmd_by_name(self._git_implementation) workspace = CmdWorkspace(local_workspace_dir, bob) return workspace.cmd is not None else: return False
def test_clone(self): self.cmd.init_new(self.workspace) target = os.path.join(self.working_dir, 'new_target') # make a new workspace, currently unknown marker (vcs backend), # but soon to become git (see using git's cmd_table) workspace = CmdWorkspace(target) cmd = self.cmdcls(remote=self.workspace_dir) cmd.clone(workspace) self.assertTrue(isdir(join(target, self.marker)))
def test_cmd_pull(self): wks = self.make_workspace() # TODO make a remote sync workflow of sort self.cmd = DemoDvcsCmd(remote='http://example.com') wks = CmdWorkspace(self.workspace_dir, self.cmd) self.cmd.pull(wks) self.assertEqual(self.cmd.queue, [ ['vcs', 'pull'], ])
def commitFiles(self, message, files): workspace = CmdWorkspace(self._currentDirectory, get_cmd_by_name(self._git_implementation)()) cmd = workspace.cmd for fn in files: sout, serr = cmd.add(workspace, fn) # if serr has something we need to handle? # XXX committer will be a problem if unset in git. return cmd.commit(workspace, message)
def test_clone_with_fresh_workspace(self): self.cmd.init_new(self.workspace) target = os.path.join(self.working_dir, 'new_target') cmd = self.cmdcls(remote=self.workspace_dir) cmd.init_new = fail workspace = CmdWorkspace(target, cmd) # new workspace got cloned. self.assertTrue(isdir(join(target, self.marker))) # XXX verify contents. # of course, clone will fail. self.assertRaises(Exception, self.cmd.clone, self.workspace)
def linkWorkspaceDirToUrl(self): # links a non-pmr workspace dir to a remote workspace url. # prereq is that the remote must be new. cmd_cls = get_cmd_by_name(self._git_implementation) if cmd_cls is None: print('Remote storage format unsupported') # brand new command module for init. new_cmd = cmd_cls() workspace = CmdWorkspace(self._currentDirectory, new_cmd) # Add the remote using a new command cmd = cmd_cls(remote=self._currentURL) # Do the writing. cmd.write_remote(workspace)
def commitFiles(self, local_workspace_dir, message, files): workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) cmd = workspace.cmd if cmd is None: logger.info('skipping commit, no underlying repo detected') return logger.info('Using `%s` for committing files.', cmd.__class__.__name__) for fn in files: sout, serr = cmd.add(workspace, fn) # if serr has something we need to handle? # XXX committer will be a problem if unset in git. return cmd.commit(workspace, message)
def pullFromRemote(self, local_workspace_dir): workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) cmd = workspace.cmd remote_workspace_url = cmd.read_remote(workspace) creds = self.requestTemporaryPassword(remote_workspace_url) stdout, stderr = cmd.pull(workspace, username=creds['user'], password=creds['key']) if stdout: logger.info(stdout) if stderr: logger.info(stderr) return stdout, stderr
def pushToRemote(self, credit, remote_workspace_url=None): workspace = CmdWorkspace(self._currentDirectory, get_cmd_by_name(self._git_implementation)()) cmd = workspace.cmd if remote_workspace_url is None: remote_workspace_url = cmd.read_remote(workspace) stderr, stdout = cmd.push(workspace, username=credit['user'], password=credit['key']) if stdout: print(stdout) if stderr: print(stderr) return stdout, stderr
def pullFromRemote(self, credit): workspace = CmdWorkspace(self._currentDirectory, get_cmd_by_name(self._git_implementation)()) cmd = workspace.cmd remote_workspace_url = cmd.read_remote(workspace) if credit: stdout, stderr = cmd.pull(workspace, username=credit['user'], password=credit['key']) else: stdout, stderr = cmd.pull(workspace) if stdout: print(stdout) if stderr: print(stderr) return stdout, stderr
def linkWorkspaceDirToUrl(self, local_workspace_dir, remote_workspace_url): # links a non-pmr workspace dir to a remote workspace url. # prereq is that the remote must be new. workspace_obj = self.getObjectInfo(remote_workspace_url) cmd_cls = get_cmd_by_name(self._git_implementation) if cmd_cls is None: raise PMRToolError('Remote storage format unsupported', 'The remote storage `%(storage)s` is not one of the ones that ' 'the MAP Client currently supports.' % workspace_obj) # brand new command module for init. new_cmd = cmd_cls() workspace = CmdWorkspace(local_workspace_dir, new_cmd) # Add the remote using a new command cmd = cmd_cls(remote=remote_workspace_url) # Do the writing. cmd.write_remote(workspace)
def pushToRemote(self, local_workspace_dir, remote_workspace_url=None): workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) cmd = workspace.cmd if remote_workspace_url is None: remote_workspace_url = cmd.read_remote(workspace) # Acquire temporary creds creds = self.requestTemporaryPassword(remote_workspace_url) stdout, stderr = cmd.push(workspace, username=creds['user'], password=creds['key']) if stdout: logger.info(stdout) if stderr: logger.error(stderr) # raise PMRToolError('Error pushing changes to PMR', # 'The command line tool gave us this error message:\n\n' + # stderr) return stdout, stderr
def addFileToIndexer(self, local_workspace_dir, workspace_file): """ Add the given workspace file in the remote workspace to the indexer for ontological searching. """ if not self.hasAccess(): return workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) cmd = workspace.cmd remote_workspace_url = cmd.read_remote(workspace) target = '/'.join([remote_workspace_url, 'rdf_indexer']) # {u'fields': {u'paths': {u'items': None, u'error': None, u'description': u'Paths that will be indexed as RDF.', u'value': u'', u'klass': u'textarea-widget list-field'}}, u'actions': {u'apply': {u'title': u'Apply'}, u'export_rdf': {u'title': u'Apply Changes and Export To RDF Store'}}} session = self.make_session() r = session.post(target, data=make_form_request('export_rdf', paths=[workspace_file], ), allow_redirects=False) r.raise_for_status() return r.json()
def cloneWorkspace(self, credit): # XXX target_dir is assumed to exist, so we can't just clone # but we have to instantiate that as a new repo, define the # remote and pull. # link self.linkWorkspaceDirToUrl() workspace = CmdWorkspace(self._currentDirectory, get_cmd_by_name(self._git_implementation)()) if credit: result = workspace.cmd.pull(workspace, username=credit['user'], password=credit['key']) else: # no credentials result = workspace.cmd.pull(workspace) print(self._currentDirectory) # TODO trap this result too? workspace.cmd.reset_to_remote(workspace) return result
def test_push_remote(self): self.cmd.init_new(self.workspace) helper = CoreTests() helper.workspace_dir = self.workspace_dir self.cmd.set_committer('Tester', '*****@*****.**') files = helper.add_files_nested(self.workspace) self.workspace.save(message='nested files') # define a remote remote = self._make_remote() self.cmd.remote = remote # add a file, using relative path fn = helper.write_file('Test content') self.workspace.add_file(basename(fn)) # make a commit, which should now push. self.workspace.save(message='single file') # Instantiate the remote for checking new_workspace = CmdWorkspace(remote, self.cmdcls()) stdout, stderr = self._call(self._log, (new_workspace, )) self.assertTrue('nested files' in stdout) self.assertTrue('single file' in stdout)
def test_cmd_workspace_no_marker_no_init(self): cmd = _DummyCmd() cmd.marker = None wks = CmdWorkspace(self.workspace_dir, cmd) self.assertEqual(cmd.result, [])
def test_cmd_workspace_no_marker_auto(self): wks = CmdWorkspace(self.workspace_dir, auto=True) self.assertTrue(wks.cmd is None)
def test_cmd_workspace(self): cmd = _DummyCmd() wks = CmdWorkspace(self.workspace_dir, cmd) self.assertEqual(cmd.result, ['init'])
def test_cmd_workspace_already_inited(self): cmd = _DummyCmd() os.mkdir(join(self.workspace_dir, _DummyCmd.marker)) wks = CmdWorkspace(self.workspace_dir, cmd) self.assertEqual(cmd.result, [])
def hasDVCS(self, local_workspace_dir): workspace = CmdWorkspace(local_workspace_dir, get_cmd_by_name(self._git_implementation)) return workspace.cmd is not None
def make_workspace(self): os.mkdir(join(self.workspace_dir, _DummyCmd.marker)) return CmdWorkspace(self.workspace_dir)
def setUp(self): super(MercurialDvcsCmdTestCase, self).setUp() self.cmd = MercurialDvcsCmd() self.workspace = CmdWorkspace(self.workspace_dir, self.cmd)
def setUp(self): super(DulwichDvcsCmdTestCase, self).setUp() self.cmd = DulwichDvcsCmd() self.workspace = CmdWorkspace(self.workspace_dir, self.cmd)
def test_auto_init(self): self.cmd.init_new(self.workspace) CmdWorkspace(self.workspace_dir) workspace = CmdWorkspace(self.workspace_dir, auto=True) self.assertTrue(isinstance(workspace.cmd, self.cmdcls))
def make_workspace(self): self.cmd = DemoDvcsCmd() os.mkdir(join(self.workspace_dir, self.wks_marker)) return CmdWorkspace(self.workspace_dir, self.cmd)
def test_cmd_new_init(self): self.cmd = DemoDvcsCmd() wks = CmdWorkspace(self.workspace_dir, self.cmd) self.assertEqual(self.cmd.queue, [ ['vcs', 'init', self.workspace_dir], ])