Introduce proper XHTML boilerplate into the cvs2svn webpages.
[cvs2svn.git] / cvs2svn_lib / context.py
blob8e6480eca38bde02996cedadba8315f48a96d73f
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2006 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
22 from boolean import *
23 import config
24 from log import Log
27 class Ctx:
28 """Session state for this run of cvs2svn. For example, run-time
29 options are stored here. This class is a Borg, see
30 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531."""
32 __shared_state = { }
34 def __init__(self):
35 self.__dict__ = self.__shared_state
36 if self.__dict__:
37 return
38 # Else, initialize to defaults.
39 self.target = None
40 self.dumpfile = config.DUMPFILE
41 self.tmpdir = '.'
42 self.verbose = 0
43 self.quiet = 0
44 self.prune = 1
45 self.existing_svnrepos = 0
46 self.dump_only = 0
47 self.dry_run = 0
48 self.trunk_only = 0
49 self.trunk_base = "trunk"
50 self.tags_base = "tags"
51 self.branches_base = "branches"
52 self.encoding = ["ascii"]
53 self.mime_types_file = None
54 self.auto_props_file = None
55 self.auto_props_ignore_case = False
56 self.no_default_eol = 0
57 self.eol_from_mime_type = 0
58 self.keywords_off = 0
59 self.use_cvs = None
60 self.svnadmin = "svnadmin"
61 self.username = None
62 self.print_help = 0
63 self.skip_cleanup = 0
64 self.bdb_txn_nosync = 0
65 self.fs_type = None
66 self.forced_branches = []
67 self.forced_tags = []
68 self.excludes = []
69 self.symbol_transforms = []
70 self.svn_property_setters = []
72 def get_temp_filename(self, basename):
73 return os.path.join(self.tmpdir, basename)
75 def to_utf8(self, value, mode='replace'):
76 """Encode (as Unicode) VALUE, trying the encodings in self.encoding
77 as valid source encodings. Raise UnicodeError on failure of all
78 source encodings."""
80 ### FIXME: The 'replace' default mode should be an option,
81 ### like --encoding is.
82 for encoding in self.encoding:
83 try:
84 return unicode(value, encoding, mode).encode('utf8')
85 except UnicodeError:
86 Log().write(Log.VERBOSE, "Encoding '%s' failed for string '%s'"
87 % (encoding, value))
88 raise UnicodeError