From 43a5109336ca2d19a982ddf79adde6932cc6b855 Mon Sep 17 00:00:00 2001 From: mhagger Date: Fri, 11 Jan 2013 20:14:25 +0000 Subject: [PATCH] By default, store temporary files in the standard location. Change the default for --tmpdir from "cvs2svn-tmp" to the result of tempfile.mkdtemp(), which follows the usual convention for temporary files (e.g., trying $TMPDIR, $TEMP, $TMP, then defaulting to a platform-specific standard location). Most of the effort of this patch is adjusting the documentation. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5416 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/bzr_run_options.py | 5 +++-- cvs2svn_lib/context.py | 5 ++++- cvs2svn_lib/git_run_options.py | 5 +++-- cvs2svn_lib/hg_run_options.py | 6 ++++-- cvs2svn_lib/main.py | 12 +++++++++++- cvs2svn_lib/run_options.py | 12 ++++++------ cvs2svn_lib/svn_run_options.py | 5 +++-- run-tests.py | 8 +++----- www/cvs2svn.html | 20 ++++++++++++-------- 9 files changed, 49 insertions(+), 29 deletions(-) diff --git a/cvs2svn_lib/bzr_run_options.py b/cvs2svn_lib/bzr_run_options.py index 36fb8759..569a28ea 100644 --- a/cvs2svn_lib/bzr_run_options.py +++ b/cvs2svn_lib/bzr_run_options.py @@ -16,6 +16,7 @@ """This module manages cvs2bzr run options.""" +import tempfile from cvs2svn_lib.common import FatalError from cvs2svn_lib.context import Ctx @@ -68,9 +69,9 @@ to create a local copy of a remote CVS repository. """ files = """\ -A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by +A directory under \\fI%s\\fR (or the directory specified by \\fB--tmpdir\\fR) is used as scratch space for temporary data files. -""" +""" % (tempfile.gettempdir(),) see_also = [ ('cvs', '1'), diff --git a/cvs2svn_lib/context.py b/cvs2svn_lib/context.py index e2000598..6f2bddc8 100644 --- a/cvs2svn_lib/context.py +++ b/cvs2svn_lib/context.py @@ -22,6 +22,7 @@ import textwrap from cvs2svn_lib import config from cvs2svn_lib.common import CVSTextDecoder +from cvs2svn_lib.common import FatalError class Ctx: @@ -57,7 +58,7 @@ class Ctx: self.username = None self.file_property_setters = [] self.revision_property_setters = [] - self.tmpdir = 'cvs2svn-tmp' + self.tmpdir = None self.skip_cleanup = False self.keep_cvsignore = False self.cross_project_commits = True @@ -86,6 +87,8 @@ class Ctx: def get_temp_filename(self, basename): + if self.tmpdir is None: + raise FatalError('Temporary directory has not been set!') return os.path.join(self.tmpdir, basename) def clean(self): diff --git a/cvs2svn_lib/git_run_options.py b/cvs2svn_lib/git_run_options.py index 097279b5..83cae21d 100644 --- a/cvs2svn_lib/git_run_options.py +++ b/cvs2svn_lib/git_run_options.py @@ -16,6 +16,7 @@ """This module manages cvs2git run options.""" +import tempfile from cvs2svn_lib.common import FatalError from cvs2svn_lib.context import Ctx @@ -68,9 +69,9 @@ to create a local copy of a remote CVS repository. """ files = """\ -A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by +A directory under \\fI%s\\fR (or the directory specified by \\fB--tmpdir\\fR) is used as scratch space for temporary data files. -""" +""" % (tempfile.gettempdir(),) see_also = [ ('cvs', '1'), diff --git a/cvs2svn_lib/hg_run_options.py b/cvs2svn_lib/hg_run_options.py index 20c4b967..819add97 100644 --- a/cvs2svn_lib/hg_run_options.py +++ b/cvs2svn_lib/hg_run_options.py @@ -14,6 +14,8 @@ # history and logs, available at http://cvs2svn.tigris.org/. # ==================================================================== +import tempfile + from cvs2svn_lib.context import Ctx from cvs2svn_lib.run_options import IncompatibleOption from cvs2svn_lib.dvcs_common import DVCSRunOptions @@ -57,9 +59,9 @@ independent Mercurial repositories with multiple runs of # XXX copied from svn_run_options.py files = """\ -A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by +A directory under \\fI%s\\fR (or the directory specified by \\fB--tmpdir\\fR) is used as scratch space for temporary data files. -""" +""" % (tempfile.gettempdir(),) # XXX the cvs2{svn,git,bzr,hg} man pages should probably reference # each other diff --git a/cvs2svn_lib/main.py b/cvs2svn_lib/main.py index 3f063c15..b4df8296 100644 --- a/cvs2svn_lib/main.py +++ b/cvs2svn_lib/main.py @@ -16,6 +16,7 @@ # ==================================================================== import os +import tempfile import errno import gc @@ -27,6 +28,7 @@ except ImportError: pass from cvs2svn_lib.common import FatalError +from cvs2svn_lib.log import logger from cvs2svn_lib.svn_run_options import SVNRunOptions from cvs2svn_lib.git_run_options import GitRunOptions from cvs2svn_lib.bzr_run_options import BzrRunOptions @@ -54,9 +56,17 @@ def main(progname, run_options, pass_manager): # Make sure the tmp directory exists. Note that we don't check if # it's empty -- we want to be able to use, for example, "." to hold # tempfiles. - if not os.path.exists(ctx.tmpdir): + if ctx.tmpdir is None: + ctx.tmpdir = tempfile.mkdtemp(prefix=('%s-' % (progname,))) erase_tmpdir = True + logger.quiet( + 'Writing temporary files to %r\n' + 'Be sure to use --tmpdir=%r if you need to resume this conversion.' + % (ctx.tmpdir, ctx.tmpdir,), + ) + elif not os.path.exists(ctx.tmpdir): os.mkdir(ctx.tmpdir) + erase_tmpdir = True elif not os.path.isdir(ctx.tmpdir): raise FatalError( "cvs2svn tried to use '%s' for temporary files, but that path\n" diff --git a/cvs2svn_lib/run_options.py b/cvs2svn_lib/run_options.py index 868147d2..853bfcf4 100644 --- a/cvs2svn_lib/run_options.py +++ b/cvs2svn_lib/run_options.py @@ -21,6 +21,7 @@ import re import optparse from optparse import OptionGroup import datetime +import tempfile import codecs import time @@ -707,13 +708,12 @@ class RunOptions(object): action='store', help=( 'directory to use for temporary data files ' - '(default "cvs2svn-tmp")' - ), + '(default is to create a temporary subdirectory under %r)' + ) % (tempfile.gettempdir(),), man_help=( - 'Set the \\fIpath\\fR to use for temporary data. Default ' - 'is a directory called \\fIcvs2svn-tmp\\fR under the current ' - 'directory.' - ), + 'Set the \\fIpath\\fR to use for temporary data. The default ' + 'is to create a temporary subdirectory under \\fI%s\\fR.' + ) % (tempfile.gettempdir(),), metavar='PATH', )) self.parser.set_default('co_executable', config.CO_EXECUTABLE) diff --git a/cvs2svn_lib/svn_run_options.py b/cvs2svn_lib/svn_run_options.py index e69fb713..a8aa03d4 100644 --- a/cvs2svn_lib/svn_run_options.py +++ b/cvs2svn_lib/svn_run_options.py @@ -16,6 +16,7 @@ """This module manages cvs2svn run options.""" +import tempfile import sys import optparse @@ -128,9 +129,9 @@ repository in a single run of cvs2svn, but only by using an """ files = """\ -A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by +A directory under \\fI%s\\fR (or the directory specified by \\fB--tmpdir\\fR) is used as scratch space for temporary data files. -""" +""" % (tempfile.gettempdir(),) see_also = [ ('cvs', '1'), diff --git a/run-tests.py b/run-tests.py index a67aed40..89fbfed0 100755 --- a/run-tests.py +++ b/run-tests.py @@ -546,11 +546,9 @@ class Conversion: assert not symbol_hints_file else: self.options_file = None - if tmp_dir != 'cvs2svn-tmp': - # Only include this argument if it differs from cvs2svn's default: - args.extend([ - '--tmpdir=%s' % tmp_dir, - ]) + args.extend([ + '--tmpdir=%s' % tmp_dir, + ]) if symbol_hints_file: self.symbol_hints_file = os.path.join(cvsrepos, symbol_hints_file) diff --git a/www/cvs2svn.html b/www/cvs2svn.html index bd6b1ceb..a699bd0d 100644 --- a/www/cvs2svn.html +++ b/www/cvs2svn.html @@ -1105,8 +1105,12 @@ project-id symbol conversion svn-path parent-lod-name --tmpdir=PATH Use the directory PATH for all of cvs2svn's temporary data - (which can be a lot of data). The default value is - cvs2svn-tmp in the current working directory. + (which can be a lot of data). The default is to store + the temporary data in a subdirectory under the platform's usual + place for temporary files (e.g., /tmp). Please note + that if you want to use the --passes feature, you have + to pass the same --tmpdir option at each + invocation. @@ -1251,13 +1255,13 @@ specify --options:

$ cvs2svn --options OPTIONSFILE -

As it works, cvs2svn will create many temporary files in a -temporary directory called "cvs2svn-tmp" (or the directory specified -with --tmpdir). This is normal. If the entire conversion is -successful, however, those tempfiles will be automatically removed. -If the conversion is not successful, or if you specify the +

As it works, cvs2svn creates many temporary files +(see --tmpdir). This is normal. After a pass completes +successfully, the temporary files that are no longer needed are +deleted automatically. If a pass fails, or if you specify the '--skip-cleanup' option, cvs2svn will leave the temporary files behind -for possible debugging.

+for possible debugging and/or resumption of the pass using +the --passes option.

-- 2.11.4.GIT