forked from utahta/pythonbrew
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse.py
More file actions
36 lines (29 loc) · 1.08 KB
/
use.py
File metadata and controls
36 lines (29 loc) · 1.08 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
import os
import sys
from pythonbrew.basecommand import Command
from pythonbrew.define import PATH_PYTHONS, PATH_HOME_ETC_TEMP
from pythonbrew.util import Package
from pythonbrew.log import logger
class UseCommand(Command):
name = "use"
usage = "%prog VERSION"
summary = "Use the specified python in current shell"
def run_command(self, options, args):
if not args:
self.parser.print_help()
sys.exit(1)
pkg = Package(args[0])
pkgname = pkg.name
pkgdir = os.path.join(PATH_PYTHONS, pkgname)
if not os.path.isdir(pkgdir):
logger.error("`%s` is not installed." % pkgname)
sys.exit(1)
pkgbin = os.path.join(pkgdir,'bin')
pkglib = os.path.join(pkgdir,'lib')
self._set_temp(pkgbin, pkglib)
logger.info("Using `%s`" % pkgname)
def _set_temp(self, bin_path, lib_path):
fp = open(PATH_HOME_ETC_TEMP, 'w')
fp.write('deactivate &> /dev/null\nPATH_PYTHONBREW_TEMP="%s"\nPATH_PYTHONBREW_TEMP_LIB="%s"\n' % (bin_path, lib_path))
fp.close()
UseCommand()