Exemplo n.º 1
0
    def run_command_use(self, options, args):
        if len(args) < 2:
            logger.error("Unrecognized command line argument: ( 'pythonbrew venv use <project>' )")
            sys.exit(1)

        workon_home = None
        activate = None
        if self._pkgname:
            workon_home = self._workon_home
            activate = os.path.join(workon_home, args[1], 'bin', 'activate')
        else:
            for pkgname in get_installed_pythons_pkgname():
                workon_home = os.path.join(PATH_VENVS, pkgname)
                if os.path.isdir(workon_home):
                    if len([d for d in os.listdir(workon_home) if d == args[1]]) > 0:
                        activate = os.path.join(workon_home, args[1], 'bin', 'activate')
                        break
        if not activate or not os.path.exists(activate):
            logger.error('`%s` environment does not exist. Try `pythonbrew venv create %s`.' % (args[1], args[1]))
            sys.exit(1)

        self._write("""\
echo '# Using `%(arg)s` environment (found in %(workon_home)s)'
echo '# To leave an environment, simply run `deactivate`'
source '%(activate)s'
""" % {'arg': args[1], 'workon_home': workon_home, 'activate': activate})
Exemplo n.º 2
0
 def run_command_list(self, options, args):
     if options.python:
         pkgname = Package(options.python).name
         workon_home = os.path.join(PATH_VENVS, pkgname)
         if pkgname == self._pkgname:
             logger.log("%s (*)" % pkgname)
         else:
             logger.log("%s" % pkgname)
         if os.path.isdir(workon_home):
             for d in sorted(os.listdir(workon_home)):
                 if os.path.isdir(os.path.join(workon_home, d)):
                     logger.log("  %s" % d)
     else:
         for pkgname in get_installed_pythons_pkgname():
             workon_home = os.path.join(PATH_VENVS, pkgname)
             if os.path.isdir(workon_home):
                 dirs = os.listdir(workon_home)
                 if len(dirs) > 0:
                     if pkgname == self._pkgname:
                         logger.log("%s (*)" % pkgname)
                     else:
                         logger.log("%s" % pkgname)
                     for d in sorted(dirs):
                         if os.path.isdir(os.path.join(workon_home, d)):
                             logger.log("  %s" % d)
Exemplo n.º 3
0
 def run_command_list(self, options, args):
     if options.all:
         for pkgname in get_installed_pythons_pkgname():
             workon_home = os.path.join(PATH_VENVS, pkgname)
             logger.log("# virtualenv for %(pkgname)s (found in %(workon_home)s)" % {'pkgname': pkgname, 'workon_home': workon_home})
             if os.path.isdir(workon_home):
                 for d in sorted(os.listdir(workon_home)):
                     if os.path.isdir(os.path.join(workon_home, d)):
                         logger.log(d)
     else:
         logger.log("# virtualenv for %(pkgname)s (found in %(workon_home)s)" % {'pkgname': self._pkgname, 'workon_home': self._workon_home})
         if os.path.isdir(self._workon_home):
             for d in sorted(os.listdir(self._workon_home)):
                 if os.path.isdir(os.path.join(self._workon_home, d)):
                     logger.log(d)