1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2008 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module contains class RepositoryDelegate."""
23 from cvs2svn_lib
.common
import CommandError
24 from cvs2svn_lib
.common
import FatalError
25 from cvs2svn_lib
.config
import DUMPFILE
26 from cvs2svn_lib
.context
import Ctx
27 from cvs2svn_lib
.dumpfile_delegate
import DumpfileDelegate
30 class RepositoryDelegate(DumpfileDelegate
):
31 """Creates a new Subversion Repository. DumpfileDelegate does all
32 of the heavy lifting."""
34 def __init__(self
, revision_reader
, target
):
37 # Since the output of this run is a repository, not a dumpfile,
38 # the temporary dumpfiles we create should go in the tmpdir. But
39 # since we delete it ourselves, we don't want to use
41 DumpfileDelegate
.__init
__(
42 self
, revision_reader
, Ctx().get_temp_filename(DUMPFILE
)
45 self
.dumpfile
= open(self
.dumpfile_path
, 'w+b')
46 self
.loader_pipe
= subprocess
.Popen(
47 [Ctx().svnadmin_executable
, 'load', '-q', self
.target
],
48 stdin
=subprocess
.PIPE
,
49 stdout
=subprocess
.PIPE
,
50 stderr
=subprocess
.PIPE
,
52 self
.loader_pipe
.stdout
.close()
54 self
._write
_dumpfile
_header
(self
.loader_pipe
.stdin
)
57 'svnadmin failed with the following output while '
58 'loading the dumpfile:\n%s'
59 % (self
.loader_pipe
.stderr
.read(),)
62 def start_commit(self
, revnum
, revprops
):
63 """Start a new commit."""
65 DumpfileDelegate
.start_commit(self
, revnum
, revprops
)
68 """Feed the revision stored in the dumpfile to the svnadmin load pipe."""
70 DumpfileDelegate
.end_commit(self
)
74 data
= self
.dumpfile
.read(128*1024) # Chunk size is arbitrary
78 self
.loader_pipe
.stdin
.write(data
)
80 raise FatalError("svnadmin failed with the following output "
81 "while loading the dumpfile:\n"
82 + self
.loader_pipe
.stderr
.read())
84 self
.dumpfile
.truncate()
90 self
.loader_pipe
.stdin
.close()
91 error_output
= self
.loader_pipe
.stderr
.read()
92 exit_status
= self
.loader_pipe
.wait()
95 raise CommandError('svnadmin load', exit_status
, error_output
)
96 os
.remove(self
.dumpfile_path
)