Esempio n. 1
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
Esempio n. 2
0
    def get_symlink_target(self, path_parts, rev):
        """Return the target of the symbolic link versioned at PATH_PARTS
        in REV, or None if that object is not a symlink."""

        path = self._getpath(path_parts)
        rev = self._getrev(rev)
        path_type = self.itemtype(path_parts, rev)  # does auth-check
        fsroot = self._getroot(rev)

        # Symlinks must be files with the svn:special property set on them
        # and with file contents which read "link SOME_PATH".
        if path_type != vclib.FILE:
            return None
        props = fs.node_proplist(fsroot, path)
        if core.SVN_PROP_SPECIAL not in props:
            return None
        pathspec = ""
        # FIXME: We're being a touch sloppy here, only checking the first
        # line of the file.
        stream = fs.file_contents(fsroot, path)
        try:
            pathspec, eof = core.svn_stream_readline(stream, b"\n")
        finally:
            core.svn_stream_close(stream)
        if pathspec[:5] != "link ":
            return None
        return pathspec[5:]
Esempio n. 3
0
 def setupClass(cls):
     svn_fs._import_svn()
     core.apr_initialize()
     pool = core.svn_pool_create(None)
     dumpstream = None
     cls.repos_path = tempfile.mkdtemp(prefix='svn-tmp')
     shutil.rmtree(cls.repos_path)
     dumpfile = open(os.path.join(os.path.split(__file__)[0], 'svn.dump'))
     try:
         r = repos.svn_repos_create(cls.repos_path, '', '', None, None,
                                    pool)
         if hasattr(repos, 'svn_repos_load_fs2'):
             repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                      repos.svn_repos_load_uuid_default, '',
                                      0, 0, None, pool)
         else:
             dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
             repos.svn_repos_load_fs(r, dumpstream, None,
                                     repos.svn_repos_load_uuid_default, '',
                                     None, None, pool)
     finally:
         if dumpstream:
             core.svn_stream_close(dumpstream)
         core.svn_pool_destroy(pool)
         core.apr_terminate()
Esempio n. 4
0
 def create_file(self, file_name, content, author, comment):
     """
     Creates a file in the SVN repository with the given
     name and content (text). Returns the committed revision
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     rev = fs.youngest_rev(fs_ptr)
     # Create and SVN transaction
     txn = fs.begin_txn(fs_ptr, rev)
     txn_root = fs.txn_root(txn)
     # Create a file in the root transaction
     fs.make_file(txn_root, file_name)
     stream = fs.apply_text(txn_root, file_name, None)
     core.svn_stream_write(stream, "%s\n" % content)
     core.svn_stream_close(stream)
     # Now set the properties svn:log and svn:author to
     # the newly created node (file)
     fs.change_txn_prop(txn, 'svn:author', author)
     fs.change_txn_prop(txn, 'svn:log', comment)
     # Commit the transaction
     fs.commit_txn(txn)
     # Add teh file to the list of created files
     self.files.append(file_name)
     # Returns therevision number
     return rev + 1
Esempio n. 5
0
    def save(self, req, text, comment):
        """
        Save the specified text into this document.
        """
        if not isinstance(self.node.repos, SubversionRepository):
            raise TracError("The '%s' repository is not supported" % type(self.node.repos))

        from svn import core as _core
        from svn import fs as _fs
        from svn import repos as _repos

        repos = self.node.repos.repos #.repos
        revnum = self.node._requested_rev
        author = req.authname
        message = 'Edited %s' % self.base[1:]
        if comment:
            message += ' (%s)' % comment

        pool = _core.Pool()
        fs_txn = _repos.fs_begin_txn_for_commit(repos, revnum, author, message, pool)
        fs_root = _fs.svn_fs_txn_root(fs_txn, pool)
        if hasattr(self.node, '_scoped_svn_path'):
            fs_path = self.node._scoped_svn_path
        else:
            fs_path = self.node._scoped_path_utf8
        stream = _fs.svn_fs_apply_text(fs_root, fs_path, None, pool)
        _core.svn_stream_write(stream, text)
        _core.svn_stream_close(stream) 
        return _repos.fs_commit_txn(repos, fs_txn, pool)
Esempio n. 6
0
    def setUp(self):
        dumpfile = open(os.path.join(os.path.split(__file__)[0],
                                     'svnrepos.dump'))

        svn_fs._import_svn()
        core.apr_initialize()
        pool = core.svn_pool_create(None)
        dumpstream = None
        try:
            if os.path.exists(REPOS_PATH):
                print 'trouble ahead with db/rep-cache.db... see #8278'
            r = repos.svn_repos_create(REPOS_PATH, '', '', None, None, pool)
            if hasattr(repos, 'svn_repos_load_fs2'):
                repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                        repos.svn_repos_load_uuid_default, '',
                                        0, 0, None, pool)
            else:
                dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
                repos.svn_repos_load_fs(r, dumpstream, None,
                                        repos.svn_repos_load_uuid_default, '',
                                        None, None, pool)
        finally:
            if dumpstream:
                core.svn_stream_close(dumpstream)
            core.svn_pool_destroy(pool)
            core.apr_terminate()
Esempio n. 7
0
    def setUp(self):
        dumpfile = open(
            os.path.join(os.path.split(__file__)[0], 'svnrepos.dump'))

        svn_fs._import_svn()
        core.apr_initialize()
        pool = core.svn_pool_create(None)
        dumpstream = None
        try:
            if os.path.exists(REPOS_PATH):
                print 'trouble ahead with db/rep-cache.db... see #8278'
            r = repos.svn_repos_create(REPOS_PATH, '', '', None, None, pool)
            if hasattr(repos, 'svn_repos_load_fs2'):
                repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                         repos.svn_repos_load_uuid_default, '',
                                         0, 0, None, pool)
            else:
                dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
                repos.svn_repos_load_fs(r, dumpstream, None,
                                        repos.svn_repos_load_uuid_default, '',
                                        None, None, pool)
        finally:
            if dumpstream:
                core.svn_stream_close(dumpstream)
            core.svn_pool_destroy(pool)
            core.apr_terminate()
Esempio n. 8
0
  def get_symlink_target(self, path_parts, rev):
    """Return the target of the symbolic link versioned at PATH_PARTS
    in REV, or None if that object is not a symlink."""

    path = self._getpath(path_parts)
    rev = self._getrev(rev)
    path_type = self.itemtype(path_parts, rev)  # does auth-check
    fsroot = self._getroot(rev)

    # Symlinks must be files with the svn:special property set on them
    # and with file contents which read "link SOME_PATH".
    if path_type != vclib.FILE:
      return None
    props = fs.node_proplist(fsroot, path)
    if not props.has_key(core.SVN_PROP_SPECIAL):
      return None
    pathspec = ''
    ### FIXME: We're being a touch sloppy here, only checking the first line
    ### of the file.
    stream = fs.file_contents(fsroot, path)
    try:
      pathspec, eof = core.svn_stream_readline(stream, '\n')
    finally:
      core.svn_stream_close(stream)
    if pathspec[:5] != 'link ':
      return None
    return pathspec[5:]
Esempio n. 9
0
def cat_to_tempfile(svnrepos, path, rev):
    """Check out file revision to temporary file"""
    temp = tempfile.mktemp()
    stream = core.svn_stream_from_aprfile(temp)
    url = svnrepos._geturl(path)
    client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev), svnrepos.ctx)
    core.svn_stream_close(stream)
    return temp
Esempio n. 10
0
def cat_to_tempfile(svnrepos, path, rev):
    """Check out file revision to temporary file"""
    temp = tempfile.mktemp()
    stream = core.svn_stream_from_aprfile(temp)
    url = svnrepos._geturl(path)
    client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev),
                          svnrepos.ctx)
    core.svn_stream_close(stream)
    return temp
Esempio n. 11
0
def temp_checkout(svnrepos, path, rev, pool):
  """Check out file revision to temporary file"""
  temp = tempfile.mktemp()
  stream = core.svn_stream_from_aprfile(temp, pool)
  url = svnrepos.rootpath + (path and '/' + path)
  client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev),
                        svnrepos.ctx, pool)
  core.svn_stream_close(stream)
  return temp
Esempio n. 12
0
def dump_file_blob(root, full_path, pool):
    stream_length = svn_fs_file_length(root, full_path, pool)
    stream = svn_fs_file_contents(root, full_path, pool)
    sys.stdout.write("data %s\n" % stream_length)
    sys.stdout.flush()
    ostream = svn_stream_for_stdout(pool)
    svn_stream_copy(stream, ostream, pool)
    svn_stream_close(ostream)
    sys.stdout.write("\n")
Esempio n. 13
0
def temp_checkout(svnrepos, path, rev, pool):
    """Check out file revision to temporary file"""
    temp = tempfile.mktemp()
    stream = core.svn_stream_from_aprfile(temp, pool)
    url = svnrepos.rootpath + (path and '/' + path)
    client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev),
                          svnrepos.ctx, pool)
    core.svn_stream_close(stream)
    return temp
Esempio n. 14
0
 def file_contents(self, path):
     """
     Return a string with the content of a file.
     """
     contents = svn_fs_file_contents(self.root, path)
     length = int(svn_fs_file_length(self.root, path))
     data = svn_stream_read(contents, length)
     svn_stream_close(contents)
     return data
Esempio n. 15
0
def dump_file_blob(root, full_path, pool):
    stream_length = svn_fs_file_length(root, full_path, pool)
    stream = svn_fs_file_contents(root, full_path, pool)
    sys.stdout.write("data %s\n" % stream_length)
    sys.stdout.flush()
    ostream = svn_stream_for_stdout(pool)
    svn_stream_copy(stream, ostream, pool)
    svn_stream_close(ostream)
    sys.stdout.write("\n")
Esempio n. 16
0
 def openfile(self, path_parts, rev):
   rev = self._getrev(rev)
   url = self.rootpath
   if len(path_parts):
     url = self.rootpath + '/' + self._getpath(path_parts)
   tmp_file = tempfile.mktemp()
   stream = core.svn_stream_from_aprfile(tmp_file, self.pool)
   ### rev here should be the last history revision of the URL
   client.svn_client_cat(core.Stream(stream), url,
                         _rev2optrev(rev), self.ctx, self.pool)
   core.svn_stream_close(stream)
   return SelfCleanFP(tmp_file), rev
 def openfile(self, path_parts, rev):
   path = self._getpath(path_parts)
   if self.itemtype(path_parts, rev) != vclib.FILE:  # does auth-check
     raise vclib.Error("Path '%s' is not a file." % path)
   rev = self._getrev(rev)
   url = self._geturl(path)
   tmp_file = tempfile.mktemp()
   stream = core.svn_stream_from_aprfile(tmp_file)
   ### rev here should be the last history revision of the URL
   client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev), self.ctx)
   core.svn_stream_close(stream)
   return SelfCleanFP(tmp_file), self._get_last_history_rev(path_parts, rev)
Esempio n. 18
0
 def openfile(self, path_parts, rev):
     rev = self._getrev(rev)
     url = self.rootpath
     if len(path_parts):
         url = self.rootpath + '/' + self._getpath(path_parts)
     tmp_file = tempfile.mktemp()
     stream = core.svn_stream_from_aprfile(tmp_file, self.pool)
     ### rev here should be the last history revision of the URL
     client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev),
                           self.ctx, self.pool)
     core.svn_stream_close(stream)
     return SelfCleanFP(tmp_file), rev
Esempio n. 19
0
 def _dump_contents(self, file, root, path, pool=None):
   fp = builtins.open(file, 'wb') # avoid namespace clash with
                                  # trimmed-down svn_fs_open()
   if path is not None:
     stream = file_contents(root, path, pool)
     try:
       while True:
         chunk = _svncore.svn_stream_read(stream, _svncore.SVN_STREAM_CHUNK_SIZE)
         if not chunk:
           break
         fp.write(chunk)
     finally:
       _svncore.svn_stream_close(stream)
   fp.close()
Esempio n. 20
0
 def _dump_contents(self, file, root, path, pool=None):
   fp = builtins.open(file, 'wb') # avoid namespace clash with
                                  # trimmed-down svn_fs_open()
   if path is not None:
     stream = file_contents(root, path, pool)
     try:
       while True:
         chunk = _svncore.svn_stream_read(stream, _svncore.SVN_STREAM_CHUNK_SIZE)
         if not chunk:
           break
         fp.write(chunk)
     finally:
       _svncore.svn_stream_close(stream)
   fp.close()
Esempio n. 21
0
 def openfile(self, path_parts, rev, options):
     path = self._getpath(path_parts)
     if self.itemtype(path_parts, rev) != vclib.FILE:  # does auth-check
         raise vclib.Error("Path '%s' is not a file." % path)
     rev = self._getrev(rev)
     url = self._geturl(path)
     tmp_file = tempfile.mktemp()
     stream = core.svn_stream_from_aprfile(tmp_file)
     ### rev here should be the last history revision of the URL
     client.svn_client_cat(core.Stream(stream), url, _rev2optrev(rev),
                           self.ctx)
     core.svn_stream_close(stream)
     return SelfCleanFP(tmp_file), self._get_last_history_rev(
         path_parts, rev)
Esempio n. 22
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN repository
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
Esempio n. 23
0
 def retrieve_file(self, file_name, rev=None):
     """
     Retrieves the given file name, at the specified revision or
     the latest available from the SVN repository
     """
     assert self.svn_repos is not None, "SVN repository not set..."
     # Get an SVN file system pointer
     fs_ptr = repos.fs(self.svn_repos)
     if rev is None:
         rev = fs.youngest_rev(fs_ptr)
     root = fs.revision_root(fs_ptr, rev)
     stream = fs.file_contents(root, file_name)
     svn_file = core.Stream(stream)
     core.svn_stream_close(stream)
     return svn_file
Esempio n. 24
0
 def itemreadme(self, path_parts, rev):
   path = self._getpath(path_parts)
   path_type = self.itemtype(path_parts, rev)  # does auth-check
   rev = self._getrev(rev)
   fsroot = self._getroot(rev)
   try:
     contenido = fs.file_contents(fsroot, path + '/Readme.md')
   except Exception:
     return None 
   texto = ""
   while 1:
     # int() waiting for proper fix http://trac.edgewall.org/ticket/10722
     data = core.svn_stream_read(contenido, int(core.SVN_STREAM_CHUNK_SIZE))
     texto = texto + data
     if len(data) < core.SVN_STREAM_CHUNK_SIZE:
         break
   core.svn_stream_close(contenido)
   return texto
Esempio n. 25
0
def temp_checkout(svnrepos, path, rev):
  """Check out file revision to temporary file"""
  temp = tempfile.mktemp()
  fp = open(temp, 'wb')
  try:
    root = svnrepos._getroot(rev)
    stream = fs.file_contents(root, path)
    try:
      while 1:
        chunk = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
        if not chunk:
          break
        fp.write(chunk)
    finally:
      core.svn_stream_close(stream)
  finally:
    fp.close()
  return temp
Esempio n. 26
0
def temp_checkout(svnrepos, path, rev):
  """Check out file revision to temporary file"""
  temp = tempfile.mktemp()
  fp = open(temp, 'wb')
  try:
    root = svnrepos._getroot(rev)
    stream = fs.file_contents(root, path)
    try:
      while 1:
        chunk = core.svn_stream_read(stream, core.SVN_STREAM_CHUNK_SIZE)
        if not chunk:
          break
        fp.write(chunk)
    finally:
      core.svn_stream_close(stream)
  finally:
    fp.close()
  return temp
Esempio n. 27
0
    def setUp(self):
        dumpfile = open(
            os.path.join(os.path.split(__file__)[0], 'svnrepos.dump'))

        core.apr_initialize()
        pool = core.svn_pool_create(None)
        dumpstream = None
        try:
            r = repos.svn_repos_create(REPOS_PATH, '', '', None, None, pool)
            if hasattr(repos, 'svn_repos_load_fs2'):
                repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                         repos.svn_repos_load_uuid_default, '',
                                         0, 0, None, pool)
            else:
                dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
                repos.svn_repos_load_fs(r, dumpstream, None,
                                        repos.svn_repos_load_uuid_default, '',
                                        None, None, pool)
        finally:
            if dumpstream:
                core.svn_stream_close(dumpstream)
            core.svn_pool_destroy(pool)
            core.apr_terminate()
Esempio n. 28
0
    def setUp(self):
        dumpfile = open(os.path.join(os.path.split(__file__)[0],
                                     'svnrepos.dump'))

        core.apr_initialize()
        pool = core.svn_pool_create(None)
        dumpstream = None
        try:
            r = repos.svn_repos_create(REPOS_PATH, '', '', None, None, pool)
            if hasattr(repos, 'svn_repos_load_fs2'):
                repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                        repos.svn_repos_load_uuid_default, '',
                                        0, 0, None, pool)
            else:
                dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
                repos.svn_repos_load_fs(r, dumpstream, None,
                                        repos.svn_repos_load_uuid_default, '',
                                        None, None, pool)
        finally:
            if dumpstream:
                core.svn_stream_close(dumpstream)
            core.svn_pool_destroy(pool)
            core.apr_terminate()
 def setupClass(cls):
     svn_fs._import_svn()
     core.apr_initialize()
     pool = core.svn_pool_create(None)
     dumpstream = None
     cls.repos_path = tempfile.mkdtemp(prefix='svn-tmp')
     shutil.rmtree(cls.repos_path)
     dumpfile = open(os.path.join(os.path.split(__file__)[0], 'svn.dump'))
     try:
         r = repos.svn_repos_create(cls.repos_path, '', '', None, None, pool)
         if hasattr(repos, 'svn_repos_load_fs2'):
             repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
                                     repos.svn_repos_load_uuid_default, '',
                                     0, 0, None, pool)
         else:
             dumpstream = core.svn_stream_from_aprfile(dumpfile, pool)
             repos.svn_repos_load_fs(r, dumpstream, None,
                                     repos.svn_repos_load_uuid_default, '',
                                     None, None, pool)
     finally:
         if dumpstream:
             core.svn_stream_close(dumpstream)
         core.svn_pool_destroy(pool)
         core.apr_terminate()
Esempio n. 30
0
 def close(self):
     return core.svn_stream_close(self._stream)
Esempio n. 31
0
 def close(self):
   return core.svn_stream_close(self._stream)