Make sure to close CVS repository files after parsing them.
[cvs2svn.git] / cvs2svn_lib / context.py
blob6f2bddc84755fb5ef38ad41def1b011308b09a05
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2009 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 """Store the context (options, etc) for a cvs2svn run."""
20 import os
21 import textwrap
23 from cvs2svn_lib import config
24 from cvs2svn_lib.common import CVSTextDecoder
25 from cvs2svn_lib.common import FatalError
28 class Ctx:
29 """Session state for this run of cvs2svn. For example, run-time
30 options are stored here. This class is a Borg (see
31 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531)."""
33 __shared_state = { }
35 def __init__(self):
36 self.__dict__ = self.__shared_state
37 if self.__dict__:
38 return
39 # Else, initialize to defaults.
40 self.set_defaults()
42 def set_defaults(self):
43 """Set all parameters to their default values."""
45 self.output_option = None
46 self.dry_run = False
47 self.revision_collector = None
48 self.revision_reader = None
49 self.svnadmin_executable = config.SVNADMIN_EXECUTABLE
50 self.trunk_only = False
51 self.include_empty_directories = False
52 self.prune = True
53 self.cvs_author_decoder = CVSTextDecoder(['ascii'])
54 self.cvs_log_decoder = CVSTextDecoder(['ascii'], eol_fix='\n')
55 self.cvs_filename_decoder = CVSTextDecoder(['ascii'])
56 self.decode_apple_single = False
57 self.symbol_info_filename = None
58 self.username = None
59 self.file_property_setters = []
60 self.revision_property_setters = []
61 self.tmpdir = None
62 self.skip_cleanup = False
63 self.keep_cvsignore = False
64 self.cross_project_commits = True
65 self.cross_branch_commits = True
66 self.retain_conflicting_attic_files = False
68 # textwrap.TextWrapper instance to be used for wrapping log messages:
69 self.text_wrapper = textwrap.TextWrapper(width=76, break_long_words=False)
71 self.initial_project_commit_message = (
72 'Standard project directories initialized by cvs2svn.'
74 self.post_commit_message = (
75 'This commit was generated by cvs2svn to compensate for '
76 'changes in r%(revnum)d, which included commits to RCS files '
77 'with non-trunk default branches.'
79 self.symbol_commit_message = (
80 "This commit was manufactured by cvs2svn to create %(symbol_type)s "
81 "'%(symbol_name)s'."
83 self.tie_tag_ancestry_message = (
84 "This commit was manufactured by cvs2svn to tie ancestry for "
85 "tag '%(symbol_name)s' back to the source branch."
89 def get_temp_filename(self, basename):
90 if self.tmpdir is None:
91 raise FatalError('Temporary directory has not been set!')
92 return os.path.join(self.tmpdir, basename)
94 def clean(self):
95 """Dispose of items in our dictionary that are not intended to
96 live past the end of a pass (identified by exactly one leading
97 underscore)."""
99 for attr in self.__dict__.keys():
100 if (attr.startswith('_') and not attr.startswith('__')
101 and not attr.startswith('_Ctx__')):
102 delattr(self, attr)