예제 #1
0
 def setUp(self):
     TestCaseInTempDir.setUp(self)
     t = transport.get_transport_from_path('.')
     t.mkdir('.bzr')
     self.sub_transport = t.clone('.bzr')
     self.lockable = self.get_lockable()
     self.lockable.create_lock()
예제 #2
0
 def setUp(self):
     super(TestLockableFiles_TransportLock, self).setUp()
     t = transport.get_transport_from_path('.')
     t.mkdir('.bzr')
     self.sub_transport = t.clone('.bzr')
     self.lockable = self.get_lockable()
     self.lockable.create_lock()
 def setUp(self):
     super(TestLockableFiles_TransportLock, self).setUp()
     t = transport.get_transport_from_path('.')
     t.mkdir('.bzr')
     self.sub_transport = t.clone('.bzr')
     self.lockable = self.get_lockable()
     self.lockable.create_lock()
예제 #4
0
 def start_server(self, backing_server=None):
     """Setup the Chroot on backing_server."""
     if backing_server is not None:
         self.backing_transport = transport.get_transport_from_url(
             backing_server.get_url())
     else:
         self.backing_transport = transport.get_transport_from_path('.')
     super(TestingChrootServer, self).start_server()
 def setUp(self):
     super(TestLockableFiles_LockDir, self).setUp()
     self.transport = transport.get_transport_from_path('.')
     self.lockable = self.get_lockable()
     # the lock creation here sets mode - test_permissions on branch
     # tests that implicitly, but it might be a good idea to factor
     # out the mode checking logic and have it applied to loackable files
     # directly. RBC 20060418
     self.lockable.create_lock()
예제 #6
0
 def setUp(self):
     super(TestLockableFiles_LockDir, self).setUp()
     self.transport = transport.get_transport_from_path('.')
     self.lockable = self.get_lockable()
     # the lock creation here sets mode - test_permissions on branch
     # tests that implicitly, but it might be a good idea to factor
     # out the mode checking logic and have it applied to loackable files
     # directly. RBC 20060418
     self.lockable.create_lock()
예제 #7
0
 def start_server(self, backing_server=None):
     """Setup the Chroot on backing_server."""
     if backing_server is not None:
         self.backing_transport = transport.get_transport_from_url(
             backing_server.get_url())
     else:
         self.backing_transport = transport.get_transport_from_path('.')
     self.backing_transport.clone('added-by-filter').ensure_base()
     self.filter_func = lambda x: 'added-by-filter/' + x
     super(TestingPathFilteringServer, self).start_server()
예제 #8
0
 def do_POST(self):
     """Hand the request off to a smart server instance."""
     backing = transport.get_transport_from_path(
         self.server.test_case_server._home_dir)
     chroot_server = chroot.ChrootServer(backing)
     chroot_server.start_server()
     try:
         t = transport.get_transport_from_url(chroot_server.get_url())
         self.do_POST_inner(t)
     finally:
         chroot_server.stop_server()
예제 #9
0
 def setUp(self):
     super(TestLockableFiles_RemoteLockDir, self).setUp()
     # can only get a RemoteLockDir with some RemoteObject...
     # use a branch as thats what we want. These mixin tests test the end
     # to end behaviour, so stubbing out the backend and simulating would
     # defeat the purpose. We test the protocol implementation separately
     # in test_remote and test_smart as usual.
     b = self.make_branch('foo')
     self.addCleanup(b.bzrdir.transport.disconnect)
     self.transport = transport.get_transport_from_path('.')
     self.lockable = self.get_lockable()
 def setUp(self):
     super(TestLockableFiles_RemoteLockDir, self).setUp()
     # can only get a RemoteLockDir with some RemoteObject...
     # use a branch as thats what we want. These mixin tests test the end
     # to end behaviour, so stubbing out the backend and simulating would
     # defeat the purpose. We test the protocol implementation separately
     # in test_remote and test_smart as usual.
     b = self.make_branch('foo')
     self.addCleanup(b.bzrdir.transport.disconnect)
     self.transport = transport.get_transport_from_path('.')
     self.lockable = self.get_lockable()
예제 #11
0
 def do_POST(self):
     """Hand the request off to a smart server instance."""
     backing = transport.get_transport_from_path(
         self.server.test_case_server._home_dir)
     chroot_server = chroot.ChrootServer(backing)
     chroot_server.start_server()
     try:
         t = transport.get_transport_from_url(chroot_server.get_url())
         self.do_POST_inner(t)
     finally:
         chroot_server.stop_server()
예제 #12
0
    def put(self, filename, source_transport=None):
        """Put `filename` into the store.

        :param filename: The name of the file to store (must be a filename,
            not a path).
        :param source_transport: The transport to look for the file on,
            defaulting to ``get_transport('.')``.
        """
        if source_transport is None:
            source_transport = get_transport_from_path('.')
        remote_name = self._getRemoteName(filename)
        local_file = source_transport.get(filename)
        self._transport.create_prefix()
        try:
            self._transport.put_file(remote_name, local_file)
        finally:
            local_file.close()
예제 #13
0
    def put(self, filename, source_transport=None):
        """Put `filename` into the store.

        :param filename: The name of the file to store (must be a filename,
            not a path).
        :param source_transport: The transport to look for the file on,
            defaulting to ``get_transport('.')``.
        """
        if source_transport is None:
            source_transport = get_transport_from_path('.')
        remote_name = self._getRemoteName(filename)
        local_file = source_transport.get(filename)
        self._transport.create_prefix()
        try:
            self._transport.put_file(remote_name, local_file)
        finally:
            local_file.close()
예제 #14
0
    def fetch(self, filename, dest_transport=None):
        """Retrieve `filename` from the store.

        :param filename: The name of the file to retrieve (must be a filename,
            not a path).
        :param dest_transport: The transport to retrieve the file to,
            defaulting to ``get_transport_from_path('.')``.
        :return: A boolean, true if the file was found and retrieved, false
            otherwise.
        """
        if dest_transport is None:
            dest_transport = get_transport_from_path('.')
        remote_name = self._getRemoteName(filename)
        if self._transport.has(remote_name):
            dest_transport.put_file(filename, self._transport.get(remote_name))
            return True
        else:
            return False
예제 #15
0
    def pull(self,
             db_branch_id,
             target_path,
             required_format,
             needs_tree=False,
             stacked_on_url=None):
        """Pull down the Bazaar branch of an import to `target_path`.

        :return: A Bazaar branch for the code import corresponding to the
            database branch with id `db_branch_id`.
        """
        remote_url = self._getMirrorURL(db_branch_id)
        try:
            remote_bzr_dir = BzrDir.open(remote_url)
        except NotBranchError:
            local_branch = BzrDir.create_branch_and_repo(
                target_path, format=required_format)
            if needs_tree:
                local_branch.bzrdir.create_workingtree()
            if stacked_on_url:
                local_branch.set_stacked_on_url(stacked_on_url)
            return local_branch
        # The proper thing to do here would be to call
        # "remote_bzr_dir.sprout()".  But 2a fetch slowly checks which
        # revisions are in the ancestry of the tip of the remote branch, which
        # we strictly don't care about, so we just copy the whole thing down
        # at the vfs level.
        control_dir = remote_bzr_dir.root_transport.relpath(
            remote_bzr_dir.transport.abspath('.'))
        target = get_transport_from_path(target_path)
        target_control = target.clone(control_dir)
        target_control.create_prefix()
        remote_bzr_dir.transport.copy_tree_to_transport(target_control)
        local_bzr_dir = BzrDir.open_from_transport(target)
        if local_bzr_dir.needs_format_conversion(format=required_format):
            try:
                local_bzr_dir.root_transport.delete_tree('backup.bzr')
            except NoSuchFile:
                pass
            upgrade(target_path, required_format, clean_up=True)
        if needs_tree:
            local_bzr_dir.create_workingtree()
        return local_bzr_dir.open_branch()
예제 #16
0
    def fetch(self, filename, dest_transport=None):
        """Retrieve `filename` from the store.

        :param filename: The name of the file to retrieve (must be a filename,
            not a path).
        :param dest_transport: The transport to retrieve the file to,
            defaulting to ``get_transport_from_path('.')``.
        :return: A boolean, true if the file was found and retrieved, false
            otherwise.
        """
        if dest_transport is None:
            dest_transport = get_transport_from_path('.')
        remote_name = self._getRemoteName(filename)
        if self._transport.has(remote_name):
            dest_transport.put_file(
                filename, self._transport.get(remote_name))
            return True
        else:
            return False
예제 #17
0
    def pull(self, db_branch_id, target_path, required_format,
             needs_tree=False, stacked_on_url=None):
        """Pull down the Bazaar branch of an import to `target_path`.

        :return: A Bazaar branch for the code import corresponding to the
            database branch with id `db_branch_id`.
        """
        remote_url = self._getMirrorURL(db_branch_id)
        try:
            remote_bzr_dir = BzrDir.open(remote_url)
        except NotBranchError:
            local_branch = BzrDir.create_branch_and_repo(
                target_path, format=required_format)
            if needs_tree:
                local_branch.bzrdir.create_workingtree()
            if stacked_on_url:
                local_branch.set_stacked_on_url(stacked_on_url)
            return local_branch
        # The proper thing to do here would be to call
        # "remote_bzr_dir.sprout()".  But 2a fetch slowly checks which
        # revisions are in the ancestry of the tip of the remote branch, which
        # we strictly don't care about, so we just copy the whole thing down
        # at the vfs level.
        control_dir = remote_bzr_dir.root_transport.relpath(
            remote_bzr_dir.transport.abspath('.'))
        target = get_transport_from_path(target_path)
        target_control = target.clone(control_dir)
        target_control.create_prefix()
        remote_bzr_dir.transport.copy_tree_to_transport(target_control)
        local_bzr_dir = BzrDir.open_from_transport(target)
        if local_bzr_dir.needs_format_conversion(format=required_format):
            try:
                local_bzr_dir.root_transport.delete_tree('backup.bzr')
            except NoSuchFile:
                pass
            upgrade(target_path, required_format, clean_up=True)
        if needs_tree:
            local_bzr_dir.create_workingtree()
        return local_bzr_dir.open_branch()
예제 #18
0
 def test_with_url(self):
     t = transport.get_transport_from_path("file:")
     self.assertIsInstance(t, local.LocalTransport)
     self.assertEquals(t.base.rstrip("/"),
         urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
예제 #19
0
def edit_commit_message_encoded(infotext,
                                ignoreline=DEFAULT_IGNORE_LINE,
                                start_message=None):
    """Let the user edit a commit message in a temp file.

    This is run if they don't give a message or
    message-containing file on the command line.

    :param infotext:    Text to be displayed at bottom of message
                        for the user's reference;
                        currently similar to 'bzr status'.
                        The string is already encoded

    :param ignoreline:  The separator to use above the infotext.

    :param start_message:   The text to place above the separator, if any.
                            This will not be removed from the message
                            after the user has edited it.
                            The string is already encoded

    :return:    commit message or None.
    """
    msgfilename = None
    try:
        msgfilename, hasinfo = _create_temp_file_with_commit_template(
            infotext, ignoreline, start_message)
        if not msgfilename:
            return None
        basename = osutils.basename(msgfilename)
        msg_transport = transport.get_transport_from_path(
            osutils.dirname(msgfilename))
        reference_content = msg_transport.get_bytes(basename)
        if not _run_editor(msgfilename):
            return None
        edited_content = msg_transport.get_bytes(basename)
        if edited_content == reference_content:
            if not ui.ui_factory.confirm_action(
                    u"Commit message was not edited, use anyway",
                    "bzrlib.msgeditor.unchanged", {}):
                # Returning "" makes cmd_commit raise 'empty commit message
                # specified' which is a reasonable error, given the user has
                # rejected using the unedited template.
                return ""
        started = False
        msg = []
        lastline, nlines = 0, 0
        # codecs.open() ALWAYS opens file in binary mode but we need text mode
        # 'rU' mode useful when bzr.exe used on Cygwin (bialix 20070430)
        f = file(msgfilename, 'rU')
        try:
            try:
                for line in codecs.getreader(osutils.get_user_encoding())(f):
                    stripped_line = line.strip()
                    # strip empty line before the log message starts
                    if not started:
                        if stripped_line != "":
                            started = True
                        else:
                            continue
                    # check for the ignore line only if there
                    # is additional information at the end
                    if hasinfo and stripped_line == ignoreline:
                        break
                    nlines += 1
                    # keep track of the last line that had some content
                    if stripped_line != "":
                        lastline = nlines
                    msg.append(line)
            except UnicodeDecodeError:
                raise BadCommitMessageEncoding()
        finally:
            f.close()

        if len(msg) == 0:
            return ""
        # delete empty lines at the end
        del msg[lastline:]
        # add a newline at the end, if needed
        if not msg[-1].endswith("\n"):
            return "%s%s" % ("".join(msg), "\n")
        else:
            return "".join(msg)
    finally:
        # delete the msg file in any case
        if msgfilename is not None:
            try:
                os.unlink(msgfilename)
            except IOError, e:
                trace.warning("failed to unlink %s: %s; ignored", msgfilename,
                              e)
예제 #20
0
 def test_with_url(self):
     t = transport.get_transport_from_path("file:")
     self.assertIsInstance(t, local.LocalTransport)
     self.assertEqual(
         t.base.rstrip("/"),
         urlutils.local_path_to_url(os.path.join(self.test_dir, "file:")))
 def __init__(self, directory, file_name, possible_transports=None):
     t = transport.get_transport_from_path(
         directory, possible_transports=possible_transports)
     super(VmStore, self).__init__(t, file_name)
     self.id = 'vm'
 def __init__(self, directory, file_name, possible_transports=None):
     t = transport.get_transport_from_path(
         directory, possible_transports=possible_transports)
     super(VmStore, self).__init__(t, file_name)
     self.id = 'vm'
예제 #23
0
 def get_store(self, path=u"."):
     t = transport.get_transport_from_path(path)
     return TextStore(t, compressed=True)
예제 #24
0
 def get_store(self, path=u'.'):
     t = transport.get_transport_from_path(path)
     return TextStore(t, compressed=True)