forked from utahta/pythonbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.py
More file actions
39 lines (36 loc) · 1.49 KB
/
uninstall.py
File metadata and controls
39 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from pythonbrew.basecommand import Command
from pythonbrew.define import PATH_PYTHONS, PATH_BIN, PATH_VENVS
from pythonbrew.util import off, rm_r, Package, get_using_python_pkgname, unlink,\
is_installed
from pythonbrew.log import logger
class UninstallCommand(Command):
name = "uninstall"
usage = "%prog VERSION"
summary = "Uninstall the given version of python"
def run_command(self, options, args):
if args:
# Uninstall pythons
for arg in args:
pkg = Package(arg)
pkgname = pkg.name
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
venvpath = os.path.join(PATH_VENVS, pkgname)
if not is_installed(pkgname):
logger.error("`%s` is not installed." % pkgname)
continue
if get_using_python_pkgname() == pkgname:
off()
for d in os.listdir(PATH_BIN):
# remove symlink
path = os.path.join(PATH_BIN, d)
if os.path.islink(path):
basename = os.path.basename(os.path.realpath(path))
tgtpath = os.path.join(pkgpath, 'bin', basename)
if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath):
unlink(path)
rm_r(pkgpath)
rm_r(venvpath)
else:
self.parser.print_help()
UninstallCommand()