diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-10-28 12:40:20 +0000 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2012-10-28 12:40:20 +0000 |
commit | 33d5e8b6021c1ae5470ce0ca67e0d94773e78d5a (patch) | |
tree | 1b4f0340479468f46b5cd8818ab08106bbc63ca0 /Lib/venv/__init__.py | |
parent | 977552178db004813dc15b170cb2ae9d157c1a4b (diff) | |
parent | ab3fb1d609ebfad0decdbdbbf741f6b4ad4575a7 (diff) | |
download | cpython-33d5e8b6021c1ae5470ce0ca67e0d94773e78d5a.tar.gz |
Closes #16340: Merged fix from 3.3.
Diffstat (limited to 'Lib/venv/__init__.py')
-rw-r--r-- | Lib/venv/__init__.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 3c0d7af903..1b91c22864 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -90,6 +90,14 @@ class EnvBuilder: self.setup_scripts(context) self.post_setup(context) + def clear_directory(self, path): + for fn in os.listdir(path): + fn = os.path.join(path, fn) + if os.path.islink(fn) or os.path.isfile(fn): + os.remove(fn) + elif os.path.isdir(fn): + shutil.rmtree(fn) + def ensure_directories(self, env_dir): """ Create the directories for the environment. @@ -101,11 +109,11 @@ class EnvBuilder: def create_if_needed(d): if not os.path.exists(d): os.makedirs(d) + elif os.path.islink(d) or os.path.isfile(d): + raise ValueError('Unable to create directory %r' % d) - if os.path.exists(env_dir) and not (self.clear or self.upgrade): - raise ValueError('Directory exists: %s' % env_dir) if os.path.exists(env_dir) and self.clear: - shutil.rmtree(env_dir) + self.clear_directory(env_dir) context = Context() context.env_dir = env_dir context.env_name = os.path.split(env_dir)[1] @@ -375,11 +383,10 @@ def main(args=None): 'when symlinks are not the default for ' 'the platform.') parser.add_argument('--clear', default=False, action='store_true', - dest='clear', help='Delete the environment ' - 'directory if it already ' - 'exists. If not specified and ' - 'the directory exists, an error' - ' is raised.') + dest='clear', help='Delete the contents of the ' + 'environment directory if it ' + 'already exists, before ' + 'environment creation.') parser.add_argument('--upgrade', default=False, action='store_true', dest='upgrade', help='Upgrade the environment ' 'directory to use this version ' |