Ejemplo n.º 1
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path[-3:] != '.po' or not changed:
            # This is not a .po file, or it hasn't changed
            return

        try:
            # Read the file contents through a validating UTF-8 decoder
            subpool = core.svn_pool_create(self.pool)
            checker = MsgFmtChecker()
            try:
                stream = core.Stream(
                    fs.file_contents(self.txn_root, path, subpool))
                reader = codecs.getreader('UTF-8')(stream, 'strict')
                writer = codecs.getwriter('UTF-8')(checker, 'strict')
                while 1:
                    data = reader.read(core.SVN_STREAM_CHUNK_SIZE)
                    if not data:
                        break
                    writer.write(data)
                if not checker.close():
                    sys.exit("PO format check failed for '" + path + "'")
            except UnicodeError:
                sys.exit("PO file is not in UTF-8: '" + path + "'")
        finally:
            core.svn_pool_destroy(subpool)
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def get_content(self):
     if self.isdir:
         return None
     s = core.Stream(
         fs.file_contents(self.root, self.scoped_path, self.pool()))
     # Make sure the stream object references the pool to make sure the pool
     # is not destroyed before the stream object.
     s._pool = self.pool
     return s
Ejemplo n.º 5
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
Ejemplo n.º 6
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)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def close_file(self, file_baton, text_checksum):
        changed, path = file_baton
        if len(path) < 3 or path.lower()[-3:] != '.py' or not changed:
            # This is not a .py file, don't care about tabs
            # TODO - only look inside trunk
            return

        # Read the file contents through a tab-finder
        subpool = core.svn_pool_create(self.pool)

        stream = core.Stream(fs.file_contents(self.txn_root, path, subpool))

        data = stream.read()  # core.SVN_STREAM_CHUNK_SIZE)
        for line in data.splitlines():
            if _tabs.match(line):
                core.svn_pool_destroy(subpool)
                msg = (
                    "Python file contains lines that begin with tabs: '%s'\n"
                    "There may be others as well." % (path, ))
                sys.stderr.write(msg)
                sys.exit(1)

        core.svn_pool_destroy(subpool)
Ejemplo n.º 9
0
 def get_content(self):
     if self.isdir:
         return None
     return core.Stream(fs.file_contents(self.root, self.scoped_path))