Skip to content

Commit 04f4cd1

Browse files
committed
Improve venv command, log and bashrc
1 parent 12b392a commit 04f4cd1

23 files changed

Lines changed: 256 additions & 212 deletions

pythonbrew/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def main():
1515
if command not in command_dict:
1616
if command == 'clean':
1717
# note: for some time
18-
logger.info('\nDEPRECATION WARNING: `pythonbrew clean` has been renamed. Please run `pythonbrew cleanup` instead.\n')
18+
logger.log('\nDEPRECATION WARNING: `pythonbrew clean` has been renamed. Please run `pythonbrew cleanup` instead.\n')
1919
return
2020
parser.error("Unknown command: `%s`" % command)
2121
return

pythonbrew/commands/buildout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run_command(self, options, args):
2828
else:
2929
pkgname = get_using_python_pkgname()
3030
if not is_installed(pkgname):
31-
logger.info('%s is not installed.' % pkgname)
31+
logger.error('`%s` is not installed.' % pkgname)
3232
sys.exit(1)
3333
logger.info('Using %s' % pkgname)
3434

@@ -46,12 +46,12 @@ def run_command(self, options, args):
4646
logger.error("Failed to download. `%s`" % download_url)
4747
sys.exit(1)
4848

49-
# Using bootstrap.py
49+
# call bootstrap.py
5050
if subprocess.call([python, bootstrap, '-d']):
5151
logger.error('Failed to bootstrap.')
5252
sys.exit(1)
5353

54-
# Using buildout
54+
# call buildout
5555
subprocess.call(['./bin/buildout'])
5656

5757
BuildoutCommand()

pythonbrew/commands/help.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def run_command(self, options, args):
1717
command.parser.print_help()
1818
return
1919
parser.print_help()
20-
logger.info("\nCommands available:")
20+
logger.log("\nCommands available:")
2121
commands = [command_dict[key] for key in sorted(command_dict.keys())]
2222
for command in commands:
23-
logger.info(" %s: %s" % (command.name, command.summary))
24-
logger.info("\nFurther Instructions:")
25-
logger.info(" https://github.com/utahta/pythonbrew")
23+
logger.log(" %s: %s" % (command.name, command.summary))
24+
logger.log("\nFurther Instructions:")
25+
logger.log(" https://github.com/utahta/pythonbrew")
2626

2727
HelpCommand()

pythonbrew/commands/install.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import sys
12
from pythonbrew.basecommand import Command
2-
from pythonbrew.log import logger
33
from pythonbrew.installer.pythoninstaller import PythonInstaller,\
44
PythonInstallerMacOSX
55
from pythonbrew.util import is_macosx
@@ -63,22 +63,22 @@ def __init__(self):
6363
)
6464

6565
def run_command(self, options, args):
66-
if args:
67-
# installing python
68-
for arg in args:
69-
try:
70-
if is_macosx():
71-
p = PythonInstallerMacOSX(arg, options)
72-
else:
73-
p = PythonInstaller(arg, options)
74-
p.install()
75-
except UnknownVersionException:
76-
continue
77-
except AlreadyInstalledException:
78-
continue
79-
except NotSupportedVersionException:
80-
continue
81-
else:
82-
logger.info("Unknown python version.")
66+
if not args:
67+
self.parser.print_help()
68+
sys.exit(1)
69+
# installing python
70+
for arg in args:
71+
try:
72+
if is_macosx():
73+
p = PythonInstallerMacOSX(arg, options)
74+
else:
75+
p = PythonInstaller(arg, options)
76+
p.install()
77+
except UnknownVersionException:
78+
continue
79+
except AlreadyInstalledException:
80+
continue
81+
except NotSupportedVersionException:
82+
continue
8383

8484
InstallCommand()

pythonbrew/commands/list.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from pythonbrew.basecommand import Command
44
from pythonbrew.define import PYTHON_VERSION_URL, LATEST_VERSIONS_OF_PYTHON,\
55
PATH_PYTHONS
6-
from pythonbrew.util import Package, get_using_python_pkgname,\
7-
get_using_python_path
6+
from pythonbrew.util import Package, get_using_python_pkgname
87
from pythonbrew.log import logger
98

109
class ListCommand(Command):
@@ -36,18 +35,16 @@ def run_command(self, options, args):
3635
self.installed(options, args)
3736

3837
def installed(self, options, args):
39-
logger.info('# installed pythons')
38+
logger.log("# pythonbrew pythons")
4039
cur = get_using_python_pkgname()
4140
for d in sorted(os.listdir(PATH_PYTHONS)):
4241
if cur and cur == d:
43-
logger.info('%s (*)' % d)
42+
logger.log(' %s (*)' % d)
4443
else:
45-
logger.info('%s' % d)
46-
if not cur:
47-
logger.info('%s (*)' % get_using_python_path())
44+
logger.log(' %s' % d)
4845

4946
def available_install(self, options, args):
50-
logger.info('# available install pythons')
47+
logger.log('# Pythons')
5148
if args:
5249
pkg = Package(args[0])
5350
_re = re.compile(r"%s" % pkg.name)
@@ -57,12 +54,12 @@ def available_install(self, options, args):
5754
pkgs.append(pkgname)
5855
if pkgs:
5956
for pkgname in pkgs:
60-
logger.info("%s" % pkgname)
57+
logger.log("%s" % pkgname)
6158
else:
62-
logger.info("Python version not found. `%s`" % pkg.name)
59+
logger.error("Python version not found. `%s`" % pkg.name)
6360
else:
6461
for pkgname in self._get_packages_name(options):
65-
logger.info("%s" % pkgname)
62+
logger.log("%s" % pkgname)
6663

6764
def _get_packages_name(self, options):
6865
return ["Python-%s" % version for version in sorted(PYTHON_VERSION_URL.keys())

pythonbrew/commands/py.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def __init__(self):
3232

3333
def run_command(self, options, args):
3434
if not args:
35-
logger.info("Unrecognized command line argument: argument not found.")
35+
self.parser.print_help()
3636
sys.exit(1)
3737
pythons = self._get_pythons(options.pythons)
3838
for d in pythons:
3939
if options.verbose:
40-
logger.info('*** %s ***' % d)
40+
logger.info('`%s` running...' % d)
4141
path = os.path.join(PATH_PYTHONS, d, 'bin', args[0])
4242
if os.path.isfile(path) and os.access(path, os.X_OK):
4343
subprocess.call([path] + args[1:])
@@ -46,7 +46,7 @@ def run_command(self, options, args):
4646
if os.path.isfile(path) and os.access(path, os.X_OK):
4747
subprocess.call([path] + args)
4848
else:
49-
logger.info('%s: No such file or directory.' % path)
49+
logger.error('%s: No such file or directory.' % path)
5050

5151
def _get_pythons(self, _pythons):
5252
pythons = [Package(p).name for p in _pythons]

pythonbrew/commands/switch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33
from pythonbrew.basecommand import Command
4-
from pythonbrew.define import PATH_PYTHONS, PATH_BIN
4+
from pythonbrew.define import PATH_PYTHONS
55
from pythonbrew.util import Package, set_current_path, is_installed
66
from pythonbrew.log import logger
77

@@ -12,16 +12,16 @@ class SwitchCommand(Command):
1212

1313
def run_command(self, options, args):
1414
if not args:
15-
logger.info("Unrecognized command line argument: argument not found.")
15+
self.parser.print_help()
1616
sys.exit(1)
1717
pkg = Package(args[0])
1818
pkgname = pkg.name
1919
if not is_installed(pkgname):
20-
logger.info("`%s` is not installed." % pkgname)
20+
logger.error("`%s` is not installed." % pkgname)
2121
sys.exit(1)
2222
pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
2323

24-
set_current_path('%s:%s' % (PATH_BIN, pkgbin))
24+
set_current_path(pkgbin)
2525

2626
logger.info("Switched to %s" % pkgname)
2727

pythonbrew/commands/symlink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _symlink(self, srcbin, dstbin, pkgname):
7575
if os.path.isfile(src):
7676
symlink(src, dst)
7777
else:
78-
logger.info("%s: File not found" % src)
78+
logger.error("%s: File not found" % src)
7979

8080
def _get_pythons(self, _pythons):
8181
"""Get the installed python versions list.

pythonbrew/commands/uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run_command(self, options, args):
1919
pkgpath = os.path.join(PATH_PYTHONS, pkgname)
2020
venvpath = os.path.join(PATH_VENVS, pkgname)
2121
if not is_installed(pkgname):
22-
logger.info("`%s` is not installed." % pkgname)
22+
logger.error("`%s` is not installed." % pkgname)
2323
continue
2424
if get_using_python_pkgname() == pkgname:
2525
off()

pythonbrew/commands/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _update_config(self, options, args):
6565
except:
6666
logger.error("Failed to download. `%s`" % download_url)
6767
sys.exit(1)
68-
logger.info("The config.cfg has been updated.")
68+
logger.log("The config.cfg has been updated.")
6969

7070
def _update_pythonbrew(self, options, args):
7171
if options.master:

0 commit comments

Comments
 (0)