summaryrefslogtreecommitdiff
path: root/distutils2/install.py
diff options
context:
space:
mode:
authorGael Pasgrimaud <gael@gawel.org>2011-01-29 17:25:43 +0100
committerGael Pasgrimaud <gael@gawel.org>2011-01-29 17:25:43 +0100
commit9f0dc9b6d29f30d21d4cd7e212fd74147240a18a (patch)
treefefa3c29f72c8d2d5afd3ad086a54c97a57f3daf /distutils2/install.py
parentd8f2dbd212feb1dbcacb9ea6e21cd65c1d455bf3 (diff)
downloaddisutils2-9f0dc9b6d29f30d21d4cd7e212fd74147240a18a.tar.gz
first implementation of the remove() method
Diffstat (limited to 'distutils2/install.py')
-rw-r--r--distutils2/install.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/distutils2/install.py b/distutils2/install.py
index 6cee781..ff79a61 100644
--- a/distutils2/install.py
+++ b/distutils2/install.py
@@ -2,10 +2,14 @@ from tempfile import mkdtemp
import logging
import shutil
import os
+import sys
+import stat
import errno
import itertools
+import tempfile
from distutils2._backport.pkgutil import get_distributions
+from distutils2._backport.pkgutil import get_distribution
from distutils2.depgraph import generate_graph
from distutils2.index import wrapper
from distutils2.index.errors import ProjectNotFound, ReleaseNotFound
@@ -208,10 +212,38 @@ def _update_infos(infos, new_infos):
infos[key].extend(new_infos[key])
-def remove(project_name):
+def remove(project_name, paths=sys.path):
"""Removes a single project from the installation"""
- pass
+ tmp = tempfile.mkdtemp(prefix=project_name+'-uninstall')
+ dist = get_distribution(project_name, paths=paths)
+ files = dist.get_installed_files(local=True)
+ rmdirs = []
+ rmfiles = []
+ try:
+ for file, md5, size in files:
+ if os.path.isfile(file):
+ dirname, filename = os.path.split(file)
+ tmpfile = os.path.join(tmp, filename)
+ try:
+ os.rename(file, tmpfile)
+ finally:
+ if not os.path.isfile(file):
+ os.rename(tmpfile, file)
+ if file not in rmfiles:
+ rmfiles.append(file)
+ if dirname not in rmdirs:
+ rmdirs.append(dirname)
+ except OSError:
+ os.rmdir(tmp)
+
+ for file in rmfiles:
+ os.remove(file)
+
+ for dirname in rmdirs:
+ if not os.listdir(dirname):
+ if bool(os.stat(dirname).st_mode & stat.S_IWUSR):
+ os.rmdir(dirname)