Add option for excluding paths from conversion
[cvs2svn.git] / cvs2svn_lib / cvs_revision_manager.py
blob0edc3fe061272e424e9ae7639b7c3a9848ff7eb7
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 """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 CommandFailedException
23 from cvs2svn_lib.revision_manager import RevisionReader
24 from cvs2svn_lib.abstract_rcs_revision_manager import AbstractRCSRevisionReader
27 class CVSRevisionReader(AbstractRCSRevisionReader):
28 """A RevisionReader that reads the contents via CVS."""
30 # Different versions of CVS support different global options. Here
31 # are the global options that we try to use, in order of decreasing
32 # preference:
33 _possible_global_options = [
34 ['-Q', '-R', '-f'],
35 ['-Q', '-R'],
36 ['-Q', '-f'],
37 ['-Q'],
38 ['-q', '-R', '-f'],
39 ['-q', '-R'],
40 ['-q', '-f'],
41 ['-q'],
44 def __init__(self, cvs_executable, global_options=None):
45 """Initialize a CVSRevisionReader.
47 CVS_EXECUTABLE is the CVS command (possibly including the full
48 path to the executable; otherwise it is sought in the $PATH).
49 GLOBAL_ARGUMENTS, if specified, should be a list of global options
50 that are passed to the CVS command before the subcommand. If
51 GLOBAL_ARGUMENTS is not specified, then each of the possibilities
52 listed in _possible_global_options is checked in order until one
53 is found that runs successfully and without any output to stderr."""
55 self.cvs_executable = cvs_executable
57 if global_options is None:
58 for global_options in self._possible_global_options:
59 try:
60 self._check_cvs_runs(global_options)
61 except CommandFailedException, e:
62 pass
63 else:
64 break
65 else:
66 raise FatalError(
67 '%s\n'
68 'Please check that cvs is installed and in your PATH.' % (e,)
70 else:
71 try:
72 self._check_cvs_runs(global_options)
73 except CommandFailedException, e:
74 raise FatalError(
75 '%s\n'
76 'Please check that cvs is installed and in your PATH and that\n'
77 'the global options that you specified (%r) are correct.'
78 % (e, global_options,)
81 # The global options were OK; use them for all CVS invocations.
82 self.global_options = global_options
84 def _check_cvs_runs(self, global_options):
85 """Check that CVS can be started.
87 Try running 'cvs --version' with the current setting for
88 self.cvs_executable and the specified global_options. If not
89 successful, raise a CommandFailedException."""
91 check_command_runs(
92 [self.cvs_executable] + global_options + ['--version'],
93 self.cvs_executable,
96 def get_pipe_command(self, cvs_rev, k_option):
97 project = cvs_rev.cvs_file.project
98 return [
99 self.cvs_executable
100 ] + self.global_options + [
101 '-d', ':local:' + project.cvs_repository_root,
102 'co',
103 '-r' + cvs_rev.rev,
104 '-p'
105 ] + k_option + [
106 project.cvs_module + cvs_rev.cvs_path