Example #1
0
 def download_unpack(self):
     content_type = self.content_type
     if is_html(content_type):
         logger.error("Invalid content-type: `%s`" % content_type)
         sys.exit(1)
     if is_file(self.download_url):
         path = fileurl_to_path(self.download_url)
         if os.path.isdir(path):
             logger.info('Copying %s into %s' % (path, self.build_dir))
             if os.path.isdir(self.build_dir):
                 shutil.rmtree(self.build_dir)
             shutil.copytree(path, self.build_dir)
             return
     if os.path.isfile(self.download_file):
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         msg = Link(self.download_url).show_msg
         try:
             dl = Downloader()
             dl.download(msg, self.download_url, self.download_file)
         except:
             unlink(self.download_file)
             logger.info("\nInterrupt to abort. `%s`" % (self.download_url))
             sys.exit(1)
     # unpack
     if not unpack_downloadfile(self.content_type, self.download_file, self.build_dir):
         sys.exit(1)
Example #2
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
    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)
Example #4
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)
 def download_and_extract(self):
     if is_file(self.download_url):
         path = fileurl_to_path(self.download_url)
         if os.path.isdir(path):
             logger.info('Copying %s into %s' % (path, self.build_dir))
             shutil.copytree(path, self.build_dir)
             return
     if os.path.isfile(self.download_file):
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         base_url = Link(self.download_url).base_url
         try:
             dl = Downloader()
             dl.download(base_url, self.download_url, self.download_file)
         except:
             unlink(self.download_file)
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             sys.exit(1)
     # extracting
     if not extract_downloadfile(self.content_type, self.download_file, self.build_dir):
         sys.exit(1)
 def download_and_extract(self):
     if is_file(self.download_url):
         path = fileurl_to_path(self.download_url)
         if os.path.isdir(path):
             logger.info('Copying %s into %s' % (path, self.build_dir))
             shutil.copytree(path, self.build_dir)
             return
     if os.path.isfile(self.download_file):
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         base_url = Link(self.download_url).base_url
         try:
             dl = Downloader()
             dl.download(base_url, self.download_url, self.download_file)
         except:
             unlink(self.download_file)
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             sys.exit(1)
     # extracting
     if not extract_downloadfile(self.content_type, self.download_file, self.build_dir):
         sys.exit(1)