Update to r1393290 of svntest.
[cvs2svn.git] / cvs2hg
blobd048c9d4ea3566e4d0f1e0d1373d6e57064a78af
1 #!/usr/bin/env python
2 # (Be in -*- python -*- mode.)
4 # ====================================================================
5 # Copyright (c) 2000-2008 CollabNet. All rights reserved.
7 # This software is licensed as described in the file COPYING, which
8 # you should have received as part of this distribution. The terms
9 # are also available at http://subversion.tigris.org/license-1.html.
10 # If newer versions of this license are posted there, you may use a
11 # newer version instead, at your option.
13 # This software consists of voluntary contributions made by many
14 # individuals. For exact contribution history, see the revision
15 # history and logs, available at http://cvs2svn.tigris.org/.
16 # ====================================================================
18 import sys
20 # Make sure that a supported version of Python is being used. Do this
21 # as early as possible, using only code compatible with Python 1.5.2
22 # and Python 3.x before the check. Remember:
24 # Python 1.5.2 doesn't have sys.version_info or ''.join().
25 # Python 3.0 doesn't have string.join().
26 # There are plans to start deprecating the string formatting '%'
27 # operator in Python 3.1 (but we use it here anyway).
29 version_error = """\
30 ERROR: cvs2hg requires Python 2, version 2.4 or later; it does not
31 work with Python 3. You are currently using"""
33 version_advice = """\
34 Please restart cvs2hg using a different version of the Python
35 interpreter. Visit http://www.python.org or consult your local system
36 administrator if you need help.
38 HINT: If you already have a usable Python version installed, it might
39 be possible to invoke cvs2hg with the correct Python interpreter by
40 typing something like 'python2.5 """ + sys.argv[0] + """ [...]'.
41 """
43 try:
44 version = sys.version_info
45 except AttributeError:
46 # This is probably a pre-2.0 version of Python.
47 sys.stderr.write(version_error + '\n')
48 sys.stderr.write('-'*70 + '\n')
49 sys.stderr.write(sys.version + '\n')
50 sys.stderr.write('-'*70 + '\n')
51 sys.stderr.write(version_advice)
52 sys.exit(1)
54 if not ((2,4) <= version < (3,0)):
55 sys.stderr.write(
56 version_error + ' version %d.%d.%d.\n'
57 % (version[0], version[1], version[2],)
59 sys.stderr.write(version_advice)
60 sys.exit(1)
62 hg_required = "ERROR: cvs2hg requires Mercurial 1.1 or later.\n"
63 hg_missing = "(No Mercurial API found.)\n"
64 hg_version = "(Attempted to use the Mercurial %s API in\n%s.)\n"
67 import os
68 try:
69 import mercurial
70 from mercurial import context, __version__
71 context.memctx # ensure Mercurial >= 1.1
72 context.memfilectx
73 except ImportError:
74 sys.stderr.write(hg_required + hg_missing)
75 sys.exit(1)
76 except AttributeError:
77 sys.stderr.write(hg_required +
78 hg_version
79 % (__version__.version,
80 os.path.dirname(mercurial.__file__)))
81 sys.exit(1)
83 import os
85 from cvs2svn_lib.common import FatalException
86 from cvs2svn_lib.main import hg_main
89 try:
90 hg_main(os.path.basename(sys.argv[0]), sys.argv[1:])
91 except FatalException, e:
92 sys.stderr.write(str(e) + '\n')
93 sys.exit(1)