1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2007 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 """Access the CVS repository via CVS's 'cvs' command."""
20 from cvs2svn_lib
.common
import FatalError
21 from cvs2svn_lib
.process
import check_command_runs
22 from cvs2svn_lib
.process
import PipeStream
23 from cvs2svn_lib
.process
import CommandFailedException
24 from cvs2svn_lib
.revision_manager
import RevisionReader
27 class CVSRevisionReader(RevisionReader
):
28 """A RevisionReader that reads the contents via CVS."""
30 # Different versions of CVS support different global arguments.
31 # Here are the global arguments that we try to use, in order of
32 # decreasing preference:
33 _possible_global_arguments
= [
40 def __init__(self
, cvs_executable
):
41 self
.cvs_executable
= cvs_executable
43 for global_arguments
in self
._possible
_global
_arguments
:
45 self
._check
_cvs
_runs
(global_arguments
)
46 except CommandFailedException
, e
:
49 # Those global arguments were OK; use them for all CVS invocations.
50 self
.global_arguments
= global_arguments
55 'Please check that cvs is installed and in your PATH.' % (e
,)
58 def _check_cvs_runs(self
, global_arguments
):
59 """Check that CVS can be started.
61 Try running 'cvs --version' with the current setting for
62 self.cvs_executable and the specified global_arguments. If not
63 successful, raise a CommandFailedException."""
66 [self
.cvs_executable
] + global_arguments
+ ['--version'],
70 def get_content_stream(self
, cvs_rev
, suppress_keyword_substitution
=False):
71 project
= cvs_rev
.cvs_file
.project
74 ] + self
.global_arguments
+ [
75 '-d', project
.cvs_repository_root
,
80 if suppress_keyword_substitution
:
81 pipe_cmd
.append('-kk')
82 pipe_cmd
.append(project
.cvs_module
+ cvs_rev
.cvs_path
)
83 return PipeStream(pipe_cmd
)