Exemple #1
0
    def __init__(self, arg, options):
        if is_archive_file(arg):
            name = path_to_fileurl(arg)
        elif os.path.isdir(arg):
            name = path_to_fileurl(arg)
        else:
            name = arg

        if is_url(name):
            self.download_url = name
            filename = Link(self.download_url).filename
            pkg = Package(filename, options.alias)
        else:
            pkg = Package(name, options.alias)
            self.download_url = get_python_version_url(pkg.version)
            if not self.download_url:
                logger.error("Unknown python version: `%s`" % pkg.name)
                raise UnknownVersionException
            filename = Link(self.download_url).filename
        self.pkg = pkg
        self.install_dir = os.path.join(PATH_PYTHONS, pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, pkg.name)
        self.download_file = os.path.join(PATH_DISTS, filename)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []

        if Version(self.pkg.version) >= '3.1':
            self.configure_options = ['--with-computed-gotos']
        else:
            self.configure_options = []
Exemple #2
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 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)
 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)
    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 _create_dummy(self, version):
     from pythonbrew.define import PATH_PYTHONS
     from pythonbrew.util import Package
     pkgname = Package(version).name
     os.makedirs(os.path.join(PATH_PYTHONS, pkgname))
     os.makedirs(os.path.join(PATH_PYTHONS, pkgname, 'bin'))
     os.makedirs(os.path.join(PATH_PYTHONS, pkgname, 'lib'))
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()
Exemple #8
0
 def _get_pythons(self, _pythons):
     """Get the installed python versions list.
     """
     pythons = [Package(p).name for p in _pythons]
     return [
         d for d in sorted(os.listdir(PATH_PYTHONS))
         if not pythons or d in pythons
     ]
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
        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')

        self._set_temp(pkgbin)

        logger.info("Using `%s`" % pkgname)
Exemple #11
0
 def available_install(self, options, args):
     logger.log('# Pythons')
     if args:
         pkg = Package(args[0])
         _re = re.compile(r"%s" % pkg.name)
         pkgs = []
         for pkgname in self._get_packages_name(options):
             if _re.match(pkgname):
                 pkgs.append(pkgname)
         if pkgs:
             for pkgname in pkgs:
                 logger.log("%s" % pkgname)
         else:
             logger.error("`%s` was not found." % pkg.name)
     else:
         for pkgname in self._get_packages_name(options):
             logger.log("%s" % pkgname)
Exemple #12
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 #13
0
 def _symlink_version_suffix(self, srcbin, dstbin, pkgname):
     """Create a symlink. add version suffix.
     """
     version = Package(pkgname).version
     dstbin = '%s%s' % (dstbin, version)
     self._symlink(srcbin, dstbin, pkgname)
Exemple #14
0
 def _get_pythons(self, _pythons):
     pythons = [Package(p).name for p in _pythons]
     return [
         d for d in sorted(os.listdir(PATH_PYTHONS))
         if not pythons or d in pythons
     ]