Esempio n. 1
0
    def initialize_on_transport(self, transport):
        """See ControlDir.initialize_on_transport()."""
        from . import lazy_check_versions
        lazy_check_versions()
        from breezy.transport.local import LocalTransport
        import os
        import subvertpy
        from subvertpy import repos
        ERR_REPOS_BAD_ARGS = getattr(subvertpy, "ERR_REPOS_BAD_ARGS", 165002)
        # For subvertpy < 0.8.6

        if not isinstance(transport, LocalTransport):
            raise UninitializableOnRemoteTransports(self)

        local_path = transport.local_abspath(".").rstrip("/").encode(
            osutils._fs_enc)
        assert type(local_path) == str
        try:
            repos.create(local_path)
        except subvertpy.SubversionException, (_, num):
            if num == subvertpy.ERR_DIR_NOT_EMPTY:
                raise errors.BzrError("Directory is not empty")
            if num == ERR_REPOS_BAD_ARGS:
                raise errors.AlreadyControlDirError(local_path)
            raise
Esempio n. 2
0
    def make_repository(self, relpath, allow_revprop_changes=True):
        """Create a repository.

        :return: Handle to the repository.
        """
        abspath = os.path.join(self.test_dir, relpath)

        repos.create(abspath)

        if allow_revprop_changes:
            if sys.platform == 'win32':
                revprop_hook = os.path.join(abspath, "hooks",
                        "pre-revprop-change.bat")
                f = open(revprop_hook, 'w')
                try:
                    f.write("exit 0\n")
                finally:
                    f.close()
            else:
                revprop_hook = os.path.join(abspath, "hooks",
                        "pre-revprop-change")
                f = open(revprop_hook, 'w')
                try:
                    f.write("#!/bin/sh\n")
                finally:
                    f.close()
                os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)

        if sys.platform == 'win32':
            return 'file:%s' % urllib.pathname2url(abspath)
        else:
            return "file://%s" % abspath
Esempio n. 3
0
    def initialize_on_transport(self, transport):
        """See ControlDir.initialize_on_transport()."""
        from . import lazy_check_versions
        lazy_check_versions()
        from breezy.transport.local import LocalTransport
        import os
        import subvertpy
        from subvertpy import repos
        # For subvertpy < 0.8.6
        ERR_REPOS_BAD_ARGS = getattr(subvertpy, "ERR_REPOS_BAD_ARGS", 165002)

        if not isinstance(transport, LocalTransport):
            raise UninitializableOnRemoteTransports(self)

        local_path = transport.local_abspath(".").rstrip("/").encode(
            osutils._fs_enc)
        try:
            repos.create(local_path)
        except subvertpy.SubversionException as e:
            if e.args[1] == subvertpy.ERR_DIR_NOT_EMPTY:
                raise errors.BzrError("Directory is not empty")
            if e.args[1] == ERR_REPOS_BAD_ARGS:
                raise errors.AlreadyControlDirError(local_path)
            raise
        # All revision property changes
        revprop_hook = os.path.join(local_path, b"hooks",
                                    b"pre-revprop-change")
        open(revprop_hook, 'w').write("#!/bin/sh")
        os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0o111)
        return self.open(transport, _found=True)
Esempio n. 4
0
    def make_repository(self, relpath, allow_revprop_changes=True):
        """Create a repository.

        :return: Handle to the repository.
        """
        abspath = os.path.join(self.test_dir, relpath)

        repos.create(abspath)

        if allow_revprop_changes:
            if sys.platform == 'win32':
                revprop_hook = os.path.join(abspath, "hooks",
                        "pre-revprop-change.bat")
                f = open(revprop_hook, 'w')
                try:
                    f.write("exit 0\n")
                finally:
                    f.close()
            else:
                revprop_hook = os.path.join(abspath, "hooks",
                        "pre-revprop-change")
                f = open(revprop_hook, 'w')
                try:
                    f.write("#!/bin/sh\n")
                finally:
                    f.close()
                os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)

        if sys.platform == 'win32':
            return 'file:%s' % urllib.pathname2url(abspath)
        else:
            return "file://%s" % abspath
Esempio n. 5
0
 def test_load_fs_invalid(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     dumpfile = b"Malformed"
     feedback = BytesIO()
     self.assertRaises(
         SubversionException, r.load_fs, BytesIO(dumpfile),
         feedback, repos.LOAD_UUID_DEFAULT)
Esempio n. 6
0
 def test_capability(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     if repos.api_version() < (1, 5):
         self.assertRaises(NotImplementedError, r.has_capability,
                           "mergeinfo")
     else:
         self.assertIsInstance(r.has_capability("mergeinfo"), bool)
Esempio n. 7
0
    def test_load_fs(self):
        r = repos.create(os.path.join(self.test_dir, "foo"))
        dumpfile = textwrap.dedent("""\
        SVN-fs-dump-format-version: 2

        UUID: 38f0a982-fd1f-4e00-aa6b-a20720f4b9ca

        Revision-number: 0
        Prop-content-length: 56
        Content-length: 56

        K 8
        svn:date
        V 27
        2011-08-26T13:08:30.187858Z
        PROPS-END
        """).encode("ascii")
        feedback = BytesIO()
        r.load_fs(BytesIO(dumpfile), feedback, repos.LOAD_UUID_DEFAULT)
        self.assertEqual(r.fs().get_uuid(), "38f0a982-fd1f-4e00-aa6b-a20720f4b9ca")
Esempio n. 8
0
    def test_load_fs(self):
        r = repos.create(os.path.join(self.test_dir, "foo"))
        dumpfile = textwrap.dedent("""\
        SVN-fs-dump-format-version: 2

        UUID: 38f0a982-fd1f-4e00-aa6b-a20720f4b9ca

        Revision-number: 0
        Prop-content-length: 56
        Content-length: 56

        K 8
        svn:date
        V 27
        2011-08-26T13:08:30.187858Z
        PROPS-END
        """)
        feedback = StringIO()
        r.load_fs(StringIO(dumpfile), feedback, repos.LOAD_UUID_DEFAULT)
        self.assertEqual(r.fs().get_uuid(),
                         "38f0a982-fd1f-4e00-aa6b-a20720f4b9ca")
Esempio n. 9
0
def load_dumpfile(dumpfile, outputdir, feedback_stream=None):
    """Load a Subversion dump file.

    :param dumpfile: Path to dump file.
    :param outputdir: Directory in which Subversion repository should be
        created.
    """
    if feedback_stream is None:

        class NullStream(object):
            def read(self):
                return

            def write(self, data):
                return

            def close(self):
                return

        feedback_stream = NullStream()
    r = repos.create(outputdir)
    if dumpfile.endswith(".gz"):
        import gzip
        file = gzip.GzipFile(dumpfile, mode='rb')
    elif dumpfile.endswith(".bz2"):
        import bz2
        file = bz2.BZ2File(dumpfile, mode='rb')
    else:
        file = open(dumpfile, 'rb')
    try:
        try:
            r.load_fs(file, feedback_stream, repos.LOAD_UUID_DEFAULT)
        except SubversionException as e:
            if e.args[1] == ERR_STREAM_MALFORMED_DATA:
                raise NotDumpFile(dumpfile)
            raise
    finally:
        file.close()
    return r
Esempio n. 10
0
def create_and_load(repopath, dumpfd):
    ''' create a new repository at repopath and load the given dump into it '''
    repo = repos.create(repopath)

    with open(os.path.join(repopath, 'db', 'fsfs.conf'), 'w') as f:
        f.write(textwrap.dedent("""\
        # config settings for svn repos to try and speed up the testsuite
        [rep-sharing]
        enable-rep-sharing = false
        [deltification]
        enable-dir-deltification = false
        enable-props-deltification = false
        [compression]
        compression-level=1
        """))

    nullfd = open(os.devnull, 'w')

    try:
        repo.load_fs(dumpfd, nullfd, repos.LOAD_UUID_FORCE)
    finally:
        dumpfd.close()
        nullfd.close()
Esempio n. 11
0
#!/usr/bin/python
# Demonstrates how to do a new commit using Subvertpy

import os
from cStringIO import StringIO
from subvertpy import delta, repos
from subvertpy.ra import RemoteAccess, Auth, get_username_provider

# Create a repository
repos.create("tmprepo")

# Connect to the "remote" repository using the file transport.
# Note that a username provider needs to be provided, so that Subversion
# knows who to record as the author of new commits made over this connection.
repo_url = "file://%s" % os.path.abspath("tmprepo")
conn = RemoteAccess(repo_url, auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(StringIO("new file contents"), txdelta)
file.close()
Esempio n. 12
0
 def test_pack_fs(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     if repos.api_version() < (1, 6):
         self.assertRaises(NotImplementedError, r.pack_fs)
     else:
         r.pack_fs()
Esempio n. 13
0
 def test_is_dir(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual(True, root.is_dir(""))
     self.assertEqual(False, root.is_dir("nonexistant"))
Esempio n. 14
0
 def test_uuid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(36, len(repos.Repository("foo").fs().get_uuid()))
Esempio n. 15
0
 def test_rev_props(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(["svn:date"], list(repos.Repository("foo").fs().revision_proplist(0).keys()))
Esempio n. 16
0
 def test_youngest_rev(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(0, repos.Repository("foo").fs().youngest_revision())
Esempio n. 17
0
 def test_is_file(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual(False, root.is_file(""))
     self.assertEqual(False, root.is_file("nonexistant"))
Esempio n. 18
0
 def test_uuid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertIsInstance(repos.Repository("foo").fs().get_uuid(), str)
Esempio n. 19
0
 def test_rev_props(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(
         ["svn:date"],
         repos.Repository("foo").fs().revision_proplist(0).keys())
Esempio n. 20
0
 def test_pack_fs(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     r.pack_fs()
Esempio n. 21
0
 def test_paths_changed(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual({}, root.paths_changed())
Esempio n. 22
0
 def test_pack_fs(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     r.pack_fs()
Esempio n. 23
0
 def test_rev_root_invalid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertRaises(SubversionException, repos.Repository("foo").fs().revision_root, 1)
Esempio n. 24
0
 def create(cls, path):
     """ Create a new Repository and return it. """
     return repos.create(path)
Esempio n. 25
0
 def test_open(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     repos.Repository("foo")
Esempio n. 26
0
 def test_is_file(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual(False, root.is_file(""))
Esempio n. 27
0
 def create(cls, path):
     """ Create a new Repository and return it. """
     return repos.create(path)
Esempio n. 28
0
 def test_rev_root_invalid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertRaises(SubversionException,
                       repos.Repository("foo").fs().revision_root, 1)
Esempio n. 29
0
 def test_create(self):
     repos.create(os.path.join(self.test_dir, "foo"))
Esempio n. 30
0
 def test_paths_changed(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual({}, root.paths_changed())
Esempio n. 31
0
 def test_capability(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     if repos.api_version() < (1, 5):
         self.assertRaises(NotImplementedError, r.has_capability, "mergeinfo")
     else:
         self.assertIsInstance(r.has_capability("mergeinfo"), bool)
Esempio n. 32
0
 def test_create(self):
     repos.create(os.path.join(self.test_dir, "foo"))
Esempio n. 33
0
 def test_verify_fs(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     f = BytesIO()
     r.verify_fs(f, 0, 0)
     self.assertEqual(b'* Verified revision 0.\n', f.getvalue())
Esempio n. 34
0
 def test_verify_fs(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     f = StringIO()
     r.verify_fs(f, 0, 0)
     self.assertEqual('* Verified revision 0.\n', f.getvalue())
Esempio n. 35
0
 def test_open(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     repos.Repository("foo")
Esempio n. 36
0
 def test_uuid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertIsInstance(repos.Repository("foo").fs().get_uuid(), str)
Esempio n. 37
0
 def test_uuid(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(36, len(repos.Repository("foo").fs().get_uuid()))
Esempio n. 38
0
 def test_rev_root(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertTrue(
         repos.Repository("foo").fs().revision_root(0) is not None)
Esempio n. 39
0
#!/usr/bin/python
# Demonstrates how to do a new commit using Subvertpy

import os
from cStringIO import StringIO
from subvertpy import delta, repos
from subvertpy.ra import RemoteAccess, Auth, get_username_provider

# Create a repository
repos.create("tmprepo")

# Connect to the "remote" repository using the file transport. 
# Note that a username provider needs to be provided, so that Subversion
# knows who to record as the author of new commits made over this connection.
repo_url = "file://%s" % os.path.abspath("tmprepo")
conn = RemoteAccess(repo_url,
                    auth=Auth([get_username_provider()]))

# Simple commit that adds a directory
editor = conn.get_commit_editor({"svn:log": "Commit message"})
root = editor.open_root()
# Add a directory
dir = root.add_directory("somedir")
dir.close()
# Add and edit a file
file = root.add_file("somefile")
# Set the svn:executable attribute
file.change_prop("svn:executable", "*")
# Obtain a textdelta handler and send the new file contents
txdelta = file.apply_textdelta()
delta.send_stream(StringIO("new file contents"), txdelta)
Esempio n. 40
0
 def test_youngest_rev(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertEqual(0, repos.Repository("foo").fs().youngest_revision())
Esempio n. 41
0
 def test_is_dir(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     root = repos.Repository("foo").fs().revision_root(0)
     self.assertEqual(True, root.is_dir(""))
Esempio n. 42
0
def create_repo(tmp_path, repo_name="tmprepo"):
    repo_path = os.path.join(tmp_path, repo_name)
    repos.create(repo_path)
    return f"file://{repo_path}"
Esempio n. 43
0
 def test_rev_root(self):
     repos.create(os.path.join(self.test_dir, "foo"))
     self.assertTrue(repos.Repository("foo").fs().revision_root(0) is not None)
Esempio n. 44
0
 def test_load_fs_invalid(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     dumpfile = b"Malformed"
     feedback = BytesIO()
     self.assertRaises(SubversionException, r.load_fs, BytesIO(dumpfile),
         feedback, repos.LOAD_UUID_DEFAULT)
Esempio n. 45
0
 def test_capability(self):
     r = repos.create(os.path.join(self.test_dir, "foo"))
     self.assertIsInstance(r.has_capability("mergeinfo"), bool)