Esempio n. 1
0
 def __init__(self, arg, options):
     if is_url(arg):
         name = arg
     elif 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)
     else:
         pkg = Package(name)
         self.download_url = get_python_version_url(pkg.version)
         if not self.download_url:
             logger.info("Unknown python version: `%s`" % pkg.name)
             sys.exit(1)
         filename = Link(self.download_url).filename
     self.pkg = pkg
     self.install_dir = "%s/%s" % (PATH_PYTHONS, pkg.name)
     self.build_dir = "%s/%s" % (PATH_BUILD, pkg.name)
     self.download_file = "%s/%s" % (PATH_DISTS, filename)
     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']
     self.options = options
     self.logfile = "%s/build.log" % PATH_LOG
Esempio n. 2
0
    def _update_pythonbrew(self, options, args):
        if options.master:
            version = 'master'
        elif options.develop:
            version = 'develop'
        else:
            version = get_stable_version()
            # check for version
            if not options.force and Version(version) <= VERSION:
                logger.info(
                    "You are already running the installed latest version of pythonbrew."
                )
                return

        download_url = get_pythonbrew_update_url(version)
        if not download_url:
            logger.error("`pythonbrew-%s` was not found in pypi." % version)
            sys.exit(1)
        headinfo = get_headerinfo_from_url(download_url)
        content_type = headinfo['content-type']
        if not options.master and not options.develop:
            if not is_gzip(content_type, Link(download_url).filename):
                logger.error("content type should be gzip. content-type:`%s`" %
                             content_type)
                sys.exit(1)

        filename = "pythonbrew-%s" % version
        distname = "%s.tgz" % filename
        download_file = os.path.join(PATH_DISTS, distname)
        try:
            d = Downloader()
            d.download(distname, download_url, download_file)
        except:
            logger.error("Failed to download. `%s`" % download_url)
            sys.exit(1)

        extract_dir = os.path.join(PATH_BUILD, filename)
        rm_r(extract_dir)
        if not extract_downloadfile(content_type, download_file, extract_dir):
            sys.exit(1)

        try:
            logger.info("Installing %s into %s" % (extract_dir, ROOT))
            s = Subprocess()
            s.check_call([
                sys.executable,
                os.path.join(extract_dir, 'pythonbrew_install.py'), '--upgrade'
            ])
        except:
            logger.error("Failed to update pythonbrew.")
            sys.exit(1)
        logger.info("The pythonbrew has been updated.")
Esempio n. 3
0
    def _update_pythonbrew(self, options, args):
        if options.master:
            version = "master"
        elif options.develop:
            version = "develop"
        else:
            version = get_stable_version()
            # check for version
            if not options.force and Version(version) <= VERSION:
                logger.info("You are already running the installed latest version of pythonbrew.")
                return

        download_url = get_pythonbrew_update_url(version)
        if not download_url:
            logger.error("`pythonbrew-%s` was not found in pypi." % version)
            sys.exit(1)
        headinfo = get_headerinfo_from_url(download_url)
        content_type = headinfo["content-type"]
        if not options.master and not options.develop:
            if not is_gzip(content_type, Link(download_url).filename):
                logger.error("content type should be gzip. content-type:`%s`" % content_type)
                sys.exit(1)

        filename = "pythonbrew-%s" % version
        distname = "%s.tgz" % filename
        download_file = os.path.join(PATH_DISTS, distname)
        try:
            d = Downloader()
            d.download(distname, download_url, download_file)
        except:
            logger.error("Failed to download. `%s`" % download_url)
            sys.exit(1)

        extract_dir = os.path.join(PATH_BUILD, filename)
        rm_r(extract_dir)
        if not extract_downloadfile(content_type, download_file, extract_dir):
            sys.exit(1)

        try:
            logger.info("Installing %s into %s" % (extract_dir, ROOT))
            s = Subprocess()
            s.check_call([sys.executable, os.path.join(extract_dir, "pythonbrew_install.py"), "--upgrade"])
        except:
            logger.error("Failed to update pythonbrew.")
            sys.exit(1)
        logger.info("The pythonbrew has been updated.")
    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)
Esempio n. 5
0
 def _update_pythonbrew(self, options, args):
     # pythonbrew update
     if options.head:
         version = 'head'
     else:
         version = get_stable_version()
         # check for version
         if not options.force and version <= VERSION:
             logger.info("You are already running the installed latest version of pythonbrew.")
             return
     
     download_url = get_pythonbrew_update_url(version)
     if not download_url:
         logger.error("`%s` of pythonbrew not found." % version)
         sys.exit(1)
     headinfo = get_headerinfo_from_url(download_url)
     content_type = headinfo['content-type']
     # head is only for gzip.
     if not options.head and not is_gzip(content_type, Link(download_url).filename):
         logger.error("Invalid content-type: `%s`" % content_type)
         sys.exit(1)
     
     filename = "pythonbrew-%s" % version
     distname = "%s.tgz" % filename
     download_file = os.path.join(PATH_DISTS, distname)
     try:
         d = Downloader()
         d.download(distname, download_url, download_file)
     except:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     
     extract_dir = os.path.join(PATH_BUILD, filename)
     rm_r(extract_dir)
     if not unpack_downloadfile(content_type, download_file, extract_dir):
         sys.exit(1)
     
     try:
         logger.info("Installing %s into %s" % (extract_dir, ROOT))
         s = Subprocess()
         s.check_call('%s %s/pythonbrew_install.py --upgrade' % (sys.executable, extract_dir))
     except:
         logger.error("Failed to update pythonbrew.")
         sys.exit(1)
     logger.info("The pythonbrew has been updated.")
Esempio n. 6
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)