Import svntest.main.run_tests explicitly.
[cvs2svn.git] / cvs2svn_lib / main.py
blob5985a9d0c00461aaa6afcd128efd8a228956ba0d
1 #!/usr/bin/env python
2 # (Be in -*- python -*- mode.)
4 # ====================================================================
5 # Copyright (c) 2000-2007 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 os
19 import errno
20 import gc
22 try:
23 # Try to get access to a bunch of encodings for use with --encoding.
24 # See http://cjkpython.i18n.org/ for details.
25 import iconv_codec
26 except ImportError:
27 pass
29 from cvs2svn_lib.common import FatalError
30 from cvs2svn_lib.run_options import RunOptions
31 from cvs2svn_lib.context import Ctx
32 from cvs2svn_lib.pass_manager import PassManager
33 from cvs2svn_lib.passes import passes
36 def main(progname, cmd_args):
37 # Disable garbage collection, as we try not to create any circular
38 # data structures:
39 gc.disable()
41 # Convenience var, so we don't have to keep instantiating this Borg.
42 ctx = Ctx()
44 pass_manager = PassManager(passes)
46 run_options = RunOptions(progname, cmd_args, pass_manager)
48 # Make sure the tmp directory exists. Note that we don't check if
49 # it's empty -- we want to be able to use, for example, "." to hold
50 # tempfiles. But if we *did* want check if it were empty, we'd do
51 # something like os.stat(ctx.tmpdir)[stat.ST_NLINK], of course :-).
52 if not os.path.exists(ctx.tmpdir):
53 erase_tmpdir = True
54 os.mkdir(ctx.tmpdir)
55 elif not os.path.isdir(ctx.tmpdir):
56 raise FatalError(
57 "cvs2svn tried to use '%s' for temporary files, but that path\n"
58 " exists and is not a directory. Please make it be a directory,\n"
59 " or specify some other directory for temporary files."
60 % (ctx.tmpdir,))
61 else:
62 erase_tmpdir = False
64 # But do lock the tmpdir, to avoid process clash.
65 try:
66 os.mkdir(os.path.join(ctx.tmpdir, 'cvs2svn.lock'))
67 except OSError, e:
68 if e.errno == errno.EACCES:
69 raise FatalError("Permission denied:"
70 + " No write access to directory '%s'." % ctx.tmpdir)
71 if e.errno == errno.EEXIST:
72 raise FatalError(
73 "cvs2svn is using directory '%s' for temporary files, but\n"
74 " subdirectory '%s/cvs2svn.lock' exists, indicating that another\n"
75 " cvs2svn process is currently using '%s' as its temporary\n"
76 " workspace. If you are certain that is not the case,\n"
77 " then remove the '%s/cvs2svn.lock' subdirectory."
78 % (ctx.tmpdir, ctx.tmpdir, ctx.tmpdir, ctx.tmpdir,))
79 raise
81 try:
82 if run_options.profiling:
83 import hotshot
84 prof = hotshot.Profile('cvs2svn.hotshot')
85 prof.runcall(pass_manager.run, run_options)
86 prof.close()
87 else:
88 pass_manager.run(run_options)
89 finally:
90 try:
91 os.rmdir(os.path.join(ctx.tmpdir, 'cvs2svn.lock'))
92 except:
93 pass
95 if erase_tmpdir:
96 try:
97 os.rmdir(ctx.tmpdir)
98 except:
99 pass