示例#1
0
    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
示例#2
0
 def test_get_cmd_by_name(self):
     # generally this isn't run, it's here to make sure that the
     # first pass is run here but then the subclasses of these tests
     # HAVE to implement this check explicitly so that any accidental
     # name changes within the main class will be picked up, as it
     # can have consequences when used by users.
     self.assertEqual(get_cmd_by_name(self.cmdcls.name), self.cmdcls)
     raise NotImplementedError
示例#3
0
 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
示例#4
0
 def test_get_cmd_by_name(self):
     # generally this isn't run, it's here to make sure that the
     # first pass is run here but then the subclasses of these tests
     # HAVE to implement this check explicitly so that any accidental
     # name changes within the main class will be picked up, as it
     # can have consequences when used by users.
     self.assertEqual(get_cmd_by_name(self.cmdcls.name), self.cmdcls)
     raise NotImplementedError
示例#5
0
    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)
示例#6
0
 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)
示例#7
0
    def test_register_avail(self):
        class TestCmd(BaseCmd):
            marker = '.testmarker'
            name = 'test_cmd'

            @classmethod
            def available(self):
                return True
        core.register_cmd(TestCmd)
        self.assertEqual(core._cmd_classes.get('.testmarker'), TestCmd)
        self.assertEqual(core.get_cmd_by_name('test_cmd'), TestCmd)
        core.register_cmd(TestCmd)
        self.assertEqual(len(core._cmd_classes), 1)
示例#8
0
    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)
示例#9
0
    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
示例#10
0
    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
示例#11
0
    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
示例#12
0
    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 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(workspace_obj.get('storage'))
        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)
示例#14
0
    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
示例#15
0
    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()
示例#16
0
    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
示例#17
0
 def test_get_cmd_by_name(self):
     self.assertEqual(get_cmd_by_name('git'), self.cmdcls)
示例#18
0
 def test_get_cmd_by_name(self):
     self.assertEqual(get_cmd_by_name('mercurial'), self.cmdcls)
示例#19
0
 def hasDVCS(self, local_workspace_dir):
     workspace = CmdWorkspace(local_workspace_dir,
                              get_cmd_by_name(self._git_implementation))
     return workspace.cmd is not None
示例#20
0
 def test_get_cmd_by_name(self):
     self.assertEqual(get_cmd_by_name('mercurial'), self.cmdcls)
示例#21
0
 def test_get_cmd_by_name(self):
     self.assertEqual(get_cmd_by_name('git'), self.cmdcls)