Exemplo n.º 1
0
    def install_setuptools(self):
        options = self.options
        pkgname = self.pkg.name
        if options.no_setuptools:
            logger.log("Skip installation of setuptools.")
            return
        download_url = DISTRIBUTE_SETUP_DLSITE
        filename = Link(download_url).filename
        download_file = os.path.join(PATH_DISTS, filename)

        dl = Downloader()
        dl.download(filename, download_url, download_file)

        install_dir = os.path.join(PATH_PYTHONS, pkgname)
        path_python = os.path.join(install_dir,"bin","python")
        try:
            s = Subprocess(log=self.logfile, cwd=PATH_DISTS, verbose=self.options.verbose)
            logger.info("Installing distribute into %s" % install_dir)
            s.check_call([path_python, filename])
            # installing pip
            easy_install = os.path.join(install_dir, 'bin', 'easy_install')
            if os.path.isfile(easy_install):
                logger.info("Installing pip into %s" % install_dir)
                s.check_call([easy_install, 'pip'])
        except:
            logger.error("Failed to install setuptools. See %s/build.log to see why." % (ROOT))
            logger.log("Skip installation of setuptools.")
Exemplo n.º 2
0
    def install_setuptools(self):
        options = self.options
        pkgname = self.pkg.name
        if options.no_setuptools:
            logger.log("Skip installation of setuptools.")
            return
        download_url = DISTRIBUTE_SETUP_DLSITE
        filename = Link(download_url).filename
        download_file = os.path.join(PATH_DISTS, filename)

        dl = Downloader()
        dl.download(filename, download_url, download_file)

        install_dir = os.path.join(PATH_PYTHONS, pkgname)
        path_python = os.path.join(install_dir, "bin", "python")
        try:
            s = Subprocess(log=self.logfile,
                           cwd=PATH_DISTS,
                           verbose=self.options.verbose)
            logger.info("Installing distribute into %s" % install_dir)
            s.check_call([path_python, filename])
            # installing pip
            easy_install = os.path.join(install_dir, 'bin', 'easy_install')
            if os.path.isfile(easy_install):
                logger.info("Installing pip into %s" % install_dir)
                s.check_call([easy_install, 'pip'])
        except:
            logger.error(
                "Failed to install setuptools. See %s/build.log to see why." %
                (ROOT))
            logger.log("Skip installation of setuptools.")
Exemplo n.º 3
0
def install_pythonbrew():
    PythonbrewInstaller.install(INSTALLER_ROOT)
    # for bash
    shrc = yourshrc = "bashrc"
    logger.log(
        """
Well-done! Congratulations!

The pythonbrew is installed as:
    
  %(ROOT)s

Please add the following line to the end of your ~/.%(yourshrc)s

  [[ -s "%(PATH_ETC)s/%(shrc)s" ]] && source "%(PATH_ETC)s/%(shrc)s"

After that, exit this shell, start a new one, and install some fresh
pythons:

  pythonbrew install 2.7.2
  pythonbrew install 3.2

For further instructions, run:

  pythonbrew help

The default help messages will popup and tell you what to do!

Enjoy pythonbrew at %(ROOT)s!!
""" % {
            'ROOT': ROOT,
            'yourshrc': yourshrc,
            'shrc': shrc,
            'PATH_ETC': PATH_ETC.replace(os.getenv('HOME'), '$HOME')
        })
Exemplo n.º 4
0
def install_pythonbrew():
    PythonbrewInstaller.install(INSTALLER_ROOT)
    # for bash
    shrc = yourshrc = "bashrc"
    logger.log(
        """
Well-done! Congratulations!

The pythonbrew is installed as:
    
  %(ROOT)s

Please add the following line to the end of your ~/.%(yourshrc)s

  [[ -s "%(PATH_ETC)s/%(shrc)s" ]] && source "%(PATH_ETC)s/%(shrc)s"

After that, exit this shell, start a new one, and install some fresh
pythons:

  pythonbrew install 2.7.2
  pythonbrew install 3.2

For further instructions, run:

  pythonbrew help

The default help messages will popup and tell you what to do!

Enjoy pythonbrew at %(ROOT)s!!
"""
        % {"ROOT": ROOT, "yourshrc": yourshrc, "shrc": shrc, "PATH_ETC": PATH_ETC.replace(os.getenv("HOME"), "$HOME")}
    )
Exemplo n.º 5
0
def systemwide_pythonbrew():
    PythonbrewInstaller.install(INSTALLER_ROOT)
    PythonbrewInstaller.systemwide_install()
    logger.log(
        """
Well-done! Congratulations!

The pythonbrew is installed as:
    
  %(ROOT)s

After that, exit this shell, start a new one, and install some fresh
pythons:

  pythonbrew install 2.7.2
  pythonbrew install 3.2

For further instructions, run:

  pythonbrew help

The default help messages will popup and tell you what to do!

Enjoy pythonbrew at %(ROOT)s!!
"""
        % {"ROOT": ROOT}
    )
Exemplo n.º 6
0
def install_pythonbrew():
    PythonbrewInstaller.install(INSTALLER_ROOT)
    # for bash
    shrc = yourshrc = "bashrc"
    logger.log("""
Well-done! Congratulations!

The pythonbrew is installed as:
    
  %(ROOT)s

Please add the following line to the end of your ~/.%(yourshrc)s

  source %(PATH_ETC)s/%(shrc)s

After that, exit this shell, start a new one, and install some fresh
pythons:

  pythonbrew install 2.7.2
  pythonbrew install 3.2

For further instructions, run:

  pythonbrew help

The default help messages will popup and tell you what to do!

Enjoy pythonbrew at %(ROOT)s!!
""" % {'ROOT':ROOT, 'yourshrc':yourshrc, 'shrc':shrc, 'PATH_ETC':PATH_ETC})
Exemplo n.º 7
0
    def call(self, cmd):
        if is_str(cmd):
            cmd = shlex.split(cmd)
        if self._debug:
            logger.log(cmd)

        fp = ((self._log and open(self._log, 'a')) or None)
        p = subprocess.Popen(cmd,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             cwd=self._cwd)
        while p.returncode is None:
            while bltin_any(select.select([p.stdout], [], [])):
                line = to_str(p.stdout.readline())
                if not line:
                    break
                if self._verbose:
                    logger.log(line.strip())
                if fp:
                    fp.write(line)
                    fp.flush()
            p.poll()
        if fp:
            fp.close()
        return p.returncode
Exemplo n.º 8
0
 def configure(self):
     s = Subprocess(log=self.logfile,
                    cwd=self.build_dir,
                    verbose=self.options.verbose)
     cmd = './configure --prefix="%s" %s %s' % (
         self.install_dir, self.options.configure, ' '.join(
             self.configure_options))
     if self.options.verbose:
         logger.log(cmd)
     s.check_call(cmd)
Exemplo n.º 9
0
 def configure(self):
     s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
     cmd = "./configure --prefix=%s %s %s" % (
         self.install_dir,
         self.options.configure,
         " ".join(self.configure_options),
     )
     if self.options.verbose:
         logger.log(cmd)
     s.check_call(cmd)
Exemplo n.º 10
0
 def run_command_print_activate(self, options, args):
     if len(args) < 2:
         logger.error("Unrecognized command line argument: ( 'pythonbrew venv print_activate <project>' )")
         sys.exit(1)
     
     activate = os.path.join(self._workon_home, args[1], 'bin', 'activate')
     if not os.path.exists(activate):
         logger.error('`%s` environment already does not exist. Try `pythonbrew venv create %s`.' % (args[1], args[1]))
         sys.exit(1)
         
     logger.log(activate)
Exemplo n.º 11
0
 def shell(self, cmd):
     if self._debug:
         logger.log(cmd)
     if is_sequence(cmd):
         cmd = "".join(cmd)
     if self._log:
         if self._verbose:
             cmd = "(%s) 2>&1 | tee '%s'" % (cmd, self._log)
         else:
             cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log)
     returncode = subprocess.call(cmd, shell=True, cwd=self._cwd)
     if returncode:
         raise ShellCommandException("%s: failed to `%s`" % (returncode, cmd))
Exemplo n.º 12
0
 def shell(self, cmd):
     if self._debug:
         logger.log(cmd)
     if is_sequence(cmd):
         cmd = ''.join(cmd)
     if self._log:
         if self._verbose:
             cmd = "(%s) 2>&1 | tee '%s'" % (cmd, self._log)
         else:
             cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log)
     returncode = subprocess.call(cmd, shell=True, cwd=self._cwd)
     if returncode:
         raise ShellCommandException('%s: failed to `%s`' % (returncode, cmd))
Exemplo n.º 13
0
 def _update_config(self, options, args):
     # config.cfg update
     # TODO: Automatically create for config.cfg
     download_url = PYTHONBREW_UPDATE_URL_CONFIG
     if not download_url:
         logger.error("Invalid download url in config.cfg. `%s`" % download_url)
         sys.exit(1)
     distname = Link(PYTHONBREW_UPDATE_URL_CONFIG).filename
     download_file = PATH_ETC_CONFIG
     try:
         d = Downloader()
         d.download(distname, download_url, download_file)
     except:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     logger.log("The config.cfg has been updated.")
Exemplo n.º 14
0
 def _update_config(self, options, args):
     # config.cfg update
     # TODO: Automatically create for config.cfg
     download_url = PYTHONBREW_UPDATE_URL_CONFIG
     if not download_url:
         logger.error("Invalid download url in config.cfg. `%s`" %
                      download_url)
         sys.exit(1)
     distname = Link(PYTHONBREW_UPDATE_URL_CONFIG).filename
     download_file = PATH_ETC_CONFIG
     try:
         d = Downloader()
         d.download(distname, download_url, download_file)
     except:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     logger.log("The config.cfg has been updated.")
Exemplo n.º 15
0
    def install(self):
        # cleanup
        if os.path.isdir(self.build_dir):
            shutil.rmtree(self.build_dir)

        # get content type.
        if is_file(self.download_url):
            path = fileurl_to_path(self.download_url)
            self.content_type = mimetypes.guess_type(path)[0]
        else:
            headerinfo = get_headerinfo_from_url(self.download_url)
            self.content_type = headerinfo['content-type']
        if is_html(self.content_type):
            # note: maybe got 404 or 503 http status code.
            logger.error("Invalid content-type: `%s`" % self.content_type)
            return

        if os.path.isdir(self.install_dir):
            logger.info("You are already installed `%s`" % self.pkg.name)
            return

        self.download_and_extract()
        logger.info(
            "\nThis could take a while. You can run the following command on another shell to track the status:"
        )
        logger.info("  tail -f %s\n" % self.logfile)
        self.patch()
        logger.info("Installing %s into %s" %
                    (self.pkg.name, self.install_dir))
        try:
            self.configure()
            self.make()
            self.make_install()
        except:
            rm_r(self.install_dir)
            logger.error("Failed to install %s. See %s to see why." %
                         (self.pkg.name, self.logfile))
            logger.log("  pythonbrew install --force %s" % self.pkg.version)
            sys.exit(1)
        self.symlink()
        self.install_setuptools()
        logger.info(
            "\nInstalled %(pkgname)s successfully. Run the following command to switch to %(pkgname)s."
            % {"pkgname": self.pkg.name})
        logger.info("  pythonbrew switch %s" % self.pkg.alias)
Exemplo n.º 16
0
    def install(self):
        # cleanup
        if os.path.isdir(self.build_dir):
            shutil.rmtree(self.build_dir)

        # get content type.
        if is_file(self.download_url):
            path = fileurl_to_path(self.download_url)
            self.content_type = mimetypes.guess_type(path)[0]
        else:
            headerinfo = get_headerinfo_from_url(self.download_url)
            self.content_type = headerinfo["content-type"]
        if is_html(self.content_type):
            # note: maybe got 404 or 503 http status code.
            logger.error("Invalid content-type: `%s`" % self.content_type)
            return

        if os.path.isdir(self.install_dir):
            logger.info("You are already installed `%s`" % self.pkg.name)
            return

        self.download_and_extract()
        logger.info(
            "\nThis could take a while. You can run the following command on another shell to track the status:"
        )
        logger.info("  tail -f %s\n" % self.logfile)
        self.patch()
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        try:
            self.configure()
            self.make()
            self.make_install()
        except:
            rm_r(self.install_dir)
            logger.error("Failed to install %s. See %s to see why." % (self.pkg.name, self.logfile))
            logger.log("  pythonbrew install --force %s" % self.pkg.version)
            sys.exit(1)
        self.symlink()
        self.install_setuptools()
        logger.info(
            "\nInstalled %(pkgname)s successfully. Run the following command to switch to %(pkgname)s."
            % {"pkgname": self.pkg.name}
        )
        logger.info("  pythonbrew switch %s" % self.pkg.alias)
Exemplo n.º 17
0
    def call(self, cmd):
        if is_str(cmd):
            cmd = shlex.split(cmd)
        if self._debug:
            logger.log(cmd)

        fp = (self._log and open(self._log, "a")) or None
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=self._cwd)
        while p.returncode is None:
            while bltin_any(select.select([p.stdout], [], [])):
                line = to_str(p.stdout.readline())
                if not line:
                    break
                if self._verbose:
                    logger.log(line.strip())
                if fp:
                    fp.write(line)
                    fp.flush()
            p.poll()
        if fp:
            fp.close()
        return p.returncode
Exemplo n.º 18
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)
Exemplo n.º 19
0
 def installed(self, options, args):
     logger.log("# pythonbrew pythons")
     cur = get_using_python_pkgname()
     for d in sorted(os.listdir(PATH_PYTHONS)):
         if cur and cur == d:
             logger.log('  %s (*)' % d)
         else:
             logger.log('  %s' % d)
Exemplo n.º 20
0
 def installed(self, options, args):
     logger.log("# pythonbrew pythons")
     cur = get_using_python_pkgname()
     for d in sorted(os.listdir(PATH_PYTHONS)):
         if cur and cur == d:
             logger.log('  %s (*)' % d)
         else:
             logger.log('  %s' % d)
Exemplo n.º 21
0
 def run_command(self, options, args):
     if args:
         command = args[0]
         if command not in command_dict:
             parser.error("Unknown command: `%s`" % command)
             return
         command = command_dict[command]
         command.parser.print_help()
         return
     parser.print_help()
     logger.log("\nCommands available:")
     commands = [command_dict[key] for key in sorted(command_dict.keys())]
     for command in commands:
         logger.log("  %s: %s" % (command.name, command.summary))
     logger.log("\nFurther Instructions:")
     logger.log("  https://github.com/utahta/pythonbrew")
Exemplo n.º 22
0
 def run_command(self, options, args):
     if args:
         command = args[0]
         if command not in command_dict:
             parser.error("Unknown command: `%s`" % command)
             return
         command = command_dict[command]
         command.parser.print_help()
         return
     parser.print_help()
     logger.log("\nCommands available:")
     commands = [command_dict[key] for key in sorted(command_dict.keys())]
     for command in commands:
         logger.log("  %s: %s" % (command.name, command.summary))
     logger.log("\nFurther Instructions:")
     logger.log("  https://github.com/utahta/pythonbrew")
Exemplo n.º 23
0
def systemwide_pythonbrew():
    PythonbrewInstaller.install(INSTALLER_ROOT)
    PythonbrewInstaller.systemwide_install()
    logger.log("""
Well-done! Congratulations!

The pythonbrew is installed as:
    
  %(ROOT)s

After that, exit this shell, start a new one, and install some fresh
pythons:

  pythonbrew install 2.7.2
  pythonbrew install 3.2

For further instructions, run:

  pythonbrew help

The default help messages will popup and tell you what to do!

Enjoy pythonbrew at %(ROOT)s!!
""" % {'ROOT': ROOT})
Exemplo n.º 24
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)
Exemplo n.º 25
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)
Exemplo n.º 26
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)
Exemplo n.º 27
0
 def run_command(self, options, args):
     logger.log(VERSION)
Exemplo n.º 28
0
 def __init__(self):
     returncode = subprocess.call("command -v curl > /dev/null", shell=True)
     if returncode:
         logger.log("pythonbrew required curl. curl was not found in your path.")
         sys.exit(1)
Exemplo n.º 29
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)