Exemple #1
0
 def run_command(self, options, args):
     if args:
         # Uninstall pythonidae
         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()
    def run_command(self, options, args):
        if options.python:
            pkgname = Package(options.python).name
        else:
            pkgname = get_using_python_pkgname()
        if not is_installed(pkgname):
            logger.error('`%s` is not installed.' % pkgname)
            sys.exit(1)
        logger.info('Using %s' % pkgname)

        # build a path
        python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # Download bootstrap.py
        download_url = BOOTSTRAP_DLSITE
        filename = Link(download_url).filename
        bootstrap = os.path.join(os.getcwd(),
                                 filename)  # fetching into current directory
        try:
            d = Downloader()
            d.download(filename, download_url, bootstrap)
        except:
            e = sys.exc_info()[1]
            logger.error("%s" % (e))
            sys.exit(1)

        # call bootstrap.py
        if subprocess.call([python, bootstrap, '-d']):
            logger.error('Failed to bootstrap.')
            sys.exit(1)

        # call buildout
        subprocess.call(['./bin/buildout'])
 def test_uninstall(self):
     from pythonbrew.commands.uninstall import UninstallCommand
     from pythonbrew.util import is_installed
     self._create_dummy('2.7.5')
     c = UninstallCommand()
     c.run_command(None, ['2.7.5'])
     eq_(False, is_installed('2.7.5'))
Exemple #4
0
    def run_command(self, options, args):
        if options.python:
            pkgname = Package(options.python).name
        else:
            pkgname = get_using_python_pkgname()
        if not is_installed(pkgname):
            logger.error('`%s` is not installed.' % pkgname)
            sys.exit(1)
        logger.info('Using %s' % pkgname)
        
        # build a path
        python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        
        # Download bootstrap.py
        download_url = BOOTSTRAP_DLSITE
        download_hash = BOOTSTRAP_HASH
        filename = Link(download_url).filename
        bootstrap = os.path.join(os.getcwd(), filename) # fetching into current directory
        try:
            d = Downloader()
            d.download(filename, download_url, bootstrap, download_hash) 
        except:
            e = sys.exc_info()[1]
            logger.error("%s" % (e))
            sys.exit(1)

        # call bootstrap.py
        if subprocess.call([python, bootstrap, '-d']):
            logger.error('Failed to bootstrap.')
            sys.exit(1)

        # call buildout
        subprocess.call(['./bin/buildout'])
 def test_uninstall(self):
     from pythonbrew.commands.uninstall import UninstallCommand
     from pythonbrew.util import is_installed
     self._create_dummy('2.7.5')
     c = UninstallCommand()
     c.run_command(None, ['2.7.5'])
     eq_(False, is_installed('2.7.5'))
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        cmd = args[0]
        if not cmd in ('init', 'create', 'delete', 'use', 'list', 'clone', 'rename', 'print_activate'):
            self.parser.print_help()
            sys.exit(1)

        # initialize?
        if cmd == 'init':
            self.run_command_init()
            return

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            pkgname = get_using_python_pkgname()

        self._pkgname = pkgname
        if self._pkgname:
            self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
            self._workon_home = os.path.join(PATH_VENVS, pkgname)
            self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # is already installed virtualenv?
        if not os.path.exists(self._venv) or not os.path.exists(self._venv_clone):
            self.run_command_init()

        # Create a shell script
        self.__getattribute__('run_command_%s' % cmd)(options, args)
Exemple #7
0
 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()
 def test_install_3_4_3(self):
     from pythonbrew.commands.install import InstallCommand
     from pythonbrew.util import is_installed
     o = self.Options({'force': True, 'test': False, 'verbose': False, 'configure': "",
                       'no_setuptools': False, 'alias': None, 'jobs': 2,
                       'framework': False, 'universal': False, 'static': False})
     c = InstallCommand()
     c.run_command(o, ['3.4.3'])
     ok_(is_installed('3.4.3'))
Exemple #9
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        pkg = Package(args[0])
        pkgname = pkg.name
        if not is_installed(pkgname):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)
        pkgbin = os.path.join(PATH_PYTHONS, pkgname, 'bin')

        set_current_path(pkgbin)

        logger.info("Switched to %s" % pkgname)
Exemple #10
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     pkg = Package(args[0])
     pkgname = pkg.name
     if not is_installed(pkgname):
         logger.error("`%s` is not installed." % pkgname)
         sys.exit(1)
     pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
     
     set_current_path(pkgbin)
     
     logger.info("Switched to %s" % pkgname)
Exemple #11
0
    def run_command(self, options, args):
        if options.default:
            # create only one instance as default of an application.
            pythons = self._get_pythons([options.default])
            for pkgname in pythons:
                if args:
                    bin = args[0]
                    self._symlink(bin, bin, pkgname)
                else:
                    self._symlink('python', 'py', pkgname)
        elif options.venv:
            if options.pythons:
                pkgname = Package(options.pythons[0]).name
            else:
                pkgname = get_using_python_pkgname()
            if not is_installed(pkgname):
                logger.error('`%s` is not installed.')
                sys.exit(1)

            venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
            venv_dir = os.path.join(venv_pkgdir, options.venv)
            if not os.path.isdir(venv_dir):
                logger.error("`%s` environment was not found in %s." %
                             (options.venv, venv_pkgdir))
                sys.exit(1)
            pkg = Package(pkgname)
            if args:
                bin = args[0]
                dstbin = '%s%s-%s' % (bin, pkg.version, options.venv)
                self._symlink(bin, dstbin, pkgname)
            else:
                dstbin = 'py%s-%s' % (pkg.version, options.venv)
                self._symlink('python', dstbin, pkgname)
        else:
            pythons = self._get_pythons(options.pythons)
            for pkgname in pythons:
                if options.remove:
                    # remove symlinks
                    for bin in os.listdir(PATH_BIN):
                        path = os.path.join(PATH_BIN, bin)
                        if os.path.islink(path):
                            unlink(path)
                else:
                    # create symlinks
                    if args:
                        bin = args[0]
                        self._symlink_version_suffix(bin, bin, pkgname)
                    else:
                        self._symlink_version_suffix('python', 'py', pkgname)
Exemple #12
0
 def run_command(self, options, args):
     if options.default:
         # create only one instance as default of an application.
         pythons = self._get_pythons([options.default])
         for pkgname in pythons:
             if args:
                 bin = args[0]
                 self._symlink(bin, bin, pkgname)
             else:
                 self._symlink('python', 'py', pkgname)
     elif options.venv:
         if options.pythons:
             pkgname = Package(options.pythons[0]).name
         else:
             pkgname = get_using_python_pkgname()
         if not is_installed(pkgname):
             logger.error('`%s` is not installed.')
             sys.exit(1)
         
         venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
         venv_dir = os.path.join(venv_pkgdir, options.venv)
         if not os.path.isdir(venv_dir):
             logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir))
             sys.exit(1)
         pkg = Package(pkgname)
         if args:
             bin = args[0]
             dstbin = '%s%s-%s' % (bin, pkg.version, options.venv)
             self._symlink(bin, dstbin, pkgname)
         else:
             dstbin = 'py%s-%s' % (pkg.version, options.venv)
             self._symlink('python', dstbin, pkgname)
     else:
         pythons = self._get_pythons(options.pythons)
         for pkgname in pythons:
             if options.remove:
                 # remove symlinks
                 for bin in os.listdir(PATH_BIN):
                     path = os.path.join(PATH_BIN, bin)
                     if os.path.islink(path):
                         unlink(path)
             else:
                 # create symlinks
                 if args:
                     bin = args[0]
                     self._symlink_version_suffix(bin, bin, pkgname)
                 else:
                     self._symlink_version_suffix('python', 'py', pkgname)
 def test_install_3_4_3(self):
     from pythonbrew.commands.install import InstallCommand
     from pythonbrew.util import is_installed
     o = self.Options({
         'force': True,
         'test': False,
         'verbose': False,
         'configure': "",
         'no_setuptools': False,
         'alias': None,
         'jobs': 2,
         'framework': False,
         'universal': False,
         'static': False
     })
     c = InstallCommand()
     c.run_command(o, ['3.4.3'])
     ok_(is_installed('3.4.3'))
Exemple #14
0
    def run_command(self, options, args):
        if options.python:
            pkgname = Package(options.python).name
        else:
            pkgname = get_using_python_pkgname()
        if not is_installed(pkgname):
            logger.error('`%s` is not installed.' % pkgnam)
            sys.exit(1)
        logger.info('Using %s' % pkgname)
        
        # build a path
        python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        
        # Download bootstrap.py
        download_url = BOOTSTRAP_DLSITE
        filename = Link(download_url).filename
        bootstrap = os.path.join(os.getcwd(), filename) # fetching into current directory
        try:
            d = Downloader()
            d.download(filename, download_url, bootstrap)
        except:
            e = sys.exc_info()[1]
            logger.error("%s" % (e))
            sys.exit(1)

        # call bootstrap.py
        option_boostrap = [python.encode('utf8'), bootstrap, '-d']
        if options.config:
            option_boostrap.extend(['-c', options.config])
        
        
        cmd_bootstrap =' '.join("{0}".format(iter_el) for
                                iter_el in  option_boostrap)
        
        if subprocess.call(shlex.split(cmd_bootstrap.encode('utf8'))):
                logger.error('Failed to bootstrap.')
                sys.exit(1)
        
        # call buildout
        if options.config:
            subprocess.call(['./bin/buildout', '-c', options.config])
        else:
            subprocess.call(['./bin/buildout'])
Exemple #15
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        cmd = args[0]
        if not cmd in ('init', 'create', 'delete', 'use', 'list'):
            self.parser.print_help()
            sys.exit(1)

        # initialize?
        if cmd == 'init':
            self.run_command_init()
            return

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            # check using python under pythonbrew
            pkgname = get_using_python_pkgname()
            if not pkgname:
                logger.error(
                    'Can not use venv command before switching a python.  Try \'pythonbrew switch <version of python>\'.'
                )
                sys.exit(1)
        self._pkgname = pkgname
        self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        self._workon_home = os.path.join(PATH_VENVS, pkgname)
        self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # is already installed virtualenv?
        if not os.path.exists(self._venv):
            self.run_command_init()

        # Create a shell script
        self.__getattribute__('run_command_%s' % cmd)(options, args)
Exemple #16
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     cmd = args[0]
     if not cmd in ('init', 'create', 'delete', 'use', 'list'):
         self.parser.print_help()
         sys.exit(1)
     
     # initialize?
     if cmd == 'init':
         self.run_command_init()
         return
     
     # target python interpreter
     if options.python:
         pkgname = Package(options.python).name
         if not is_installed(pkgname):
             logger.error('%s is not installed.' % pkgname)
             sys.exit(1)
     else:
         # check using python under pythonbrew
         pkgname = get_using_python_pkgname()
         if not pkgname:
             logger.error('Can not use venv command before switching a python.  Try \'pythonbrew switch <version of python>\'.')
             sys.exit(1)
     self._pkgname = pkgname
     self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
     self._workon_home = os.path.join(PATH_VENVS, pkgname)
     self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
     
     # is already installed virtualenv?
     if not os.path.exists(self._venv):
         self.run_command_init()
     
     # Create a shell script
     self.__getattribute__('run_command_%s' % cmd)(options, args)
Exemple #17
0
    def run_command(self, options, args):
        if args:
            bin_ = args[0]
        else:
            bin_ = 'python'

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            pkgname = get_using_python_pkgname()

        if not pkgname:
            logger.error("Unknown python version: ( 'pythonbrew locate -p VERSION' )")
            sys.exit(1)

        if options.venv:
            venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
            venv_dir = os.path.join(venv_pkgdir, options.venv)
            if not os.path.isdir(venv_dir):
                logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir))
                sys.exit(1)

            bindir = os.path.join(venv_dir, 'bin')
        else:
            bindir = os.path.join(PATH_PYTHONS, pkgname, 'bin')

        if not os.path.isdir(bindir):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)

        path = os.path.join(bindir, bin_)
        logger.log(path)