Example #1
0
    def install(self):
        # 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 = Downloader.read_head_info(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 have 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)
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        try:
            self.patch()
            self.configure()
            self.make()
            self.make_install()
        except Exception:
            import traceback
            traceback.print_exc()
            rm_r(self.install_dir)
            logger.error("Failed to install %s. Check %s to see why." % (self.pkg.name, self.logfile))
            sys.exit(1)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #2
0
 def _update_pythonz(self, options, args):
     download_url = PYTHONZ_UPDATE_URL
     headinfo = get_headerinfo_from_url(download_url)
     content_type = headinfo['content-type']
     filename = "pythonz-latest"
     distname = "%s.tgz" % filename
     download_file = os.path.join(PATH_DISTS, distname)
     # Remove old tarball
     unlink(download_file)
     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,'pythonz_install.py'), '--upgrade'])
     except:
         logger.error("Failed to update pythonz.")
         sys.exit(1)
     logger.info("The pythonz has been updated.")
Example #3
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 = Downloader.read_head_info(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 have 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)
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        shutil.copytree(self.build_dir, self.install_dir)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #4
0
    def install(self):
        # 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 = Downloader.read_head_info(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

        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)
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        try:
            self.patch()
            self.configure()
            self.make()
            self.make_install()
        except Exception:
            import traceback
            traceback.print_exc()
            rm_r(self.install_dir)
            logger.error("Failed to install %s. Check %s to see why." % (self.pkg.name, self.logfile))
            sys.exit(1)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #5
0
    def run_command(self, options, args):
        download_url = PYTHONZ_UPDATE_URL
        headinfo = Downloader.read_head_info(download_url)
        content_type = headinfo['content-type']
        filename = "pythonz-latest"
        distname = "%s.tgz" % filename
        download_file = os.path.join(PATH_DISTS, distname)
        # Remove old tarball
        unlink(download_file)
        logger.info("Downloading %s as %s" % (distname, download_file))
        try:
            Downloader.fetch(download_url, download_file)
        except DownloadError:
            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, 'pythonz_install.py'), '--upgrade'
            ])
        except:
            logger.error("Failed to update pythonz.")
            sys.exit(1)
        logger.info("pythonz has been updated.")
Example #6
0
    def __init__(self, version, options):
        super(CPythonInstaller, self).__init__(version, options)

        if Version(self.pkg.version) >= '3.1':
            self.configure_options.append('--with-computed-gotos')

        if sys.platform == "darwin":
            # set configure options
            target = get_macosx_deployment_target()
            if target:
                self.configure_options.append('MACOSX_DEPLOYMENT_TARGET=%s' %
                                              target)

            # set build options
            if options.framework and options.static:
                logger.error("Can't specify both framework and static.")
                raise Exception
            if options.framework:
                self.configure_options.append(
                    '--enable-framework=%s' %
                    os.path.join(self.install_dir, 'Frameworks'))
            elif not options.static:
                self.configure_options.append('--enable-shared')
            if options.universal:
                self.configure_options.append('--enable-universalsdk=/')
                self.configure_options.append('--with-universal-archs=intel')
Example #7
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 = Downloader.read_head_info(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 have 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)
        logger.info("Installing %s into %s" %
                    (self.pkg.name, self.install_dir))
        shutil.copytree(self.build_dir, self.install_dir)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." %
                    {"pkgname": self.pkg.name})
Example #8
0
    def __init__(self, version, options):
        # create directories
        makedirs(PATH_DISTS)
        makedirs(PATH_LOG)

        if options.file is not None:
            if not (is_archive_file(options.file) and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            if version not in self.supported_versions:
                logger.warning("Unsupported Python version: `%s`, trying with the following URL anyway: %s" % (version, self.get_version_url(version)))
            self.download_url = self.get_version_url(version)
        self.pkg = Package(version, options.type)
        self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.pkg.name)
        filename = Link(self.download_url).filename
        self.download_file = os.path.join(PATH_DISTS, filename)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []
        self.configure_options = []
Example #9
0
    def run_command(self, options, args):
        headinfo = Downloader.read_head_info(PYTHONZ_UPDATE_URL)
        content_type = headinfo["content-type"]
        filename = "pythonz-latest"
        distname = "%s.tgz" % filename
        download_file = os.path.join(PATH_DISTS, distname)
        # Remove old tarball
        unlink(download_file)
        logger.info("Downloading %s as %s" % (distname, download_file))
        try:
            Downloader.fetch(PYTHONZ_UPDATE_URL, download_file)
        except DownloadError:
            unlink(download_file)
            logger.error("Failed to download. `%s`" % PYTHONZ_UPDATE_URL)
            sys.exit(1)
        except:
            unlink(download_file)
            raise

        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, "pythonz_install.py"), "--upgrade"])
        except:
            logger.error("Failed to update pythonz.")
            sys.exit(1)
        logger.info("pythonz has been updated.")
Example #10
0
    def install(self):
        # check if java is installed
        r = subprocess.call("command -v java > /dev/null", shell=True)
        if r != 0:
            logger.error("Jython requires Java to be installed, but the 'java' command was not found in the path.")
            return

        # 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:
            try:
                headerinfo = Downloader.read_head_info(self.download_url)
            except DownloadError:
                self.content_type = None
            else:
                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

        self.download()
        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)
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        cmd = 'java -jar %s -s -d %s' % (self.download_file, self.install_dir)
        s = Subprocess(log=self.logfile, verbose=self.options.verbose)
        s.check_call(cmd)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #11
0
    def install(self):
        # check if java is installed
        r = subprocess.call("command -v java > /dev/null", shell=True)
        if r != 0:
            logger.error("Jython requires Java to be installed, but the 'java' command was not found in the path.")
            return

        # 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:
            try:
                headerinfo = Downloader.read_head_info(self.download_url)
            except DownloadError:
                self.content_type = None
            else:
                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

        self.download()
        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)
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        cmd = 'java -jar %s -s -d %s' % (self.download_file, self.install_dir)
        s = Subprocess(log=self.logfile, verbose=self.options.verbose)
        s.check_call(cmd)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #12
0
    def __init__(self, version, options):
        super(CPythonInstaller, self).__init__(version, options)

        if Version(self.pkg.version) >= '3.1':
            self.configure_options.append('--with-computed-gotos')

        if sys.platform == "darwin":
            # set configure options
            target = get_macosx_deployment_target()
            if target:
                self.configure_options.append('MACOSX_DEPLOYMENT_TARGET=%s' % target)

            # set build options
            if options.framework and options.shared:
                logger.error("Can't specify both framework and shared.")
                raise Exception
            if options.framework:
                self.configure_options.append('--enable-framework=%s' % os.path.join(self.install_dir, 'Frameworks'))
            if options.shared:
                self.configure_options.append('--enable-shared')
            if options.universal:
                self.configure_options.append('--enable-universalsdk=/')
                self.configure_options.append('--with-universal-archs=intel')
        else:
            if options.shared:
                self.configure_options.append('--enable-shared')
Example #13
0
def extract_downloadfile(content_type, download_file, target_dir):
    logger.info("Extracting %s into %s" % (os.path.basename(download_file), target_dir))
    if is_gzip(content_type, download_file):
        untar_file(download_file, target_dir)
    else:
        logger.error("Cannot determine archive format of %s" % download_file)
        return False
    return True
Example #14
0
def extract_downloadfile(content_type, download_file, target_dir):
    logger.info("Extracting %s into %s" % (os.path.basename(download_file), target_dir))
    if is_gzip(content_type, download_file):
        untar_file(download_file, target_dir)
    else:
        logger.error("Cannot determine archive format of %s" % download_file)
        return False
    return True
Example #15
0
def untar_file(filename, location):
    if not os.path.exists(location):
        os.makedirs(location)
    if filename.lower().endswith('.gz') or filename.lower().endswith('.tgz'):
        mode = 'r:gz'
    elif filename.lower().endswith('.bz2') or filename.lower().endswith(
            '.tbz'):
        mode = 'r:bz2'
    elif filename.lower().endswith('.tar'):
        mode = 'r'
    else:
        logger.error('Cannot determine compression type for file %s' %
                     filename)
        mode = 'r:*'
    tar = tarfile.open(filename, mode)
    try:
        # note: python<=2.5 doesnt seem to know about pax headers, filter them
        leading = has_leading_dir([
            member.name for member in tar.getmembers()
            if not member.name.startswith('.')
            and member.name != 'pax_global_header'
        ])
        for member in tar.getmembers():
            fn = member.name
            if fn == 'pax_global_header':
                continue
            if leading:
                fn = split_leading_dir(fn)[1]
            path = os.path.join(location, fn)
            if member.isdir():
                if not os.path.exists(path):
                    os.makedirs(path)
            else:
                try:
                    fp = tar.extractfile(member)
                except (KeyError, AttributeError):
                    e = sys.exc_info()[1]
                    # Some corrupt tar files seem to produce this
                    # (specifically bad symlinks)
                    logger.error(
                        'In the tar file %s the member %s is invalid: %s' %
                        (filename, member.name, e))
                    continue
                if not os.path.exists(os.path.dirname(path)):
                    os.makedirs(os.path.dirname(path))
                destfp = open(path, 'wb')
                try:
                    shutil.copyfileobj(fp, destfp)
                finally:
                    destfp.close()
                fp.close()
                # note: configure ...etc
                os.chmod(path, member.mode)
                # note: the file timestamps should be such that asdl_c.py is not invoked.
                os.utime(path, (member.mtime, member.mtime))
    finally:
        tar.close()
Example #16
0
 def download(self):
     if os.path.isfile(self.download_file) and sha256(self.download_file) == self.expected_sha256:
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         base_url = Link(self.download_url).base_url
         logger.info("Downloading %s as %s" % (base_url, self.download_file))
         try:
             Downloader.fetch(self.download_url, self.download_file, self.expected_sha256)
         except DownloadError:
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             raise
Example #17
0
    def run_command(self, options, args):
        if not args or len(args) > 1:
            self.parser.print_help()
            return

        pkg = Package(args[0], options.type)
        pkgname = pkg.name
        if not is_installed(pkg):
            logger.error("`%s` is not installed." % pkgname)
            return
        logger.log(os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python'))
Example #18
0
    def run_command(self, options, args):
        if not args or len(args) > 1:
            self.parser.print_help()
            return

        pkg = Package(args[0], options.type)
        pkgname = pkg.name
        if not is_installed(pkg):
            logger.error("`%s` is not installed." % pkgname)
            return
        logger.log(os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python'))
Example #19
0
 def download(self):
     if os.path.isfile(self.download_file) and sha256(self.download_file) == self.expected_sha256:
         logger.info("Use the previously fetched %s" % (self.download_file))
     else:
         base_url = Link(self.download_url).base_url
         logger.info("Downloading %s as %s" % (base_url, self.download_file))
         try:
             Downloader.fetch(self.download_url, self.download_file, self.expected_sha256)
         except DownloadError:
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             sys.exit(1)
Example #20
0
def untar_file(filename, location):
    if not os.path.exists(location):
        os.makedirs(location)
    if filename.lower().endswith('.gz') or filename.lower().endswith('.tgz'):
        mode = 'r:gz'
    elif filename.lower().endswith('.bz2') or filename.lower().endswith('.tbz'):
        mode = 'r:bz2'
    elif filename.lower().endswith('.tar'):
        mode = 'r'
    else:
        logger.error('Cannot determine compression type for file %s' % filename)
        mode = 'r:*'
    tar = tarfile.open(filename, mode)
    try:
        # note: python<=2.5 doesnt seem to know about pax headers, filter them
        leading = has_leading_dir([
            member.name for member in tar.getmembers()
            if member.name != 'pax_global_header'
        ])
        for member in tar.getmembers():
            fn = member.name
            if fn == 'pax_global_header':
                continue
            if leading:
                fn = split_leading_dir(fn)[1]
            path = os.path.join(location, fn)
            if member.isdir():
                if not os.path.exists(path):
                    os.makedirs(path)
            else:
                try:
                    fp = tar.extractfile(member)
                except (KeyError, AttributeError):
                    e = sys.exc_info()[1]
                    # Some corrupt tar files seem to produce this
                    # (specifically bad symlinks)
                    logger.error('In the tar file %s the member %s is invalid: %s'
                                  % (filename, member.name, e))
                    continue
                if not os.path.exists(os.path.dirname(path)):
                    os.makedirs(os.path.dirname(path))
                destfp = open(path, 'wb')
                try:
                    shutil.copyfileobj(fp, destfp)
                finally:
                    destfp.close()
                fp.close()
                # note: configure ...etc
                os.chmod(path, member.mode)
                # note: the file timestamps should be such that asdl_c.py is not invoked.
                os.utime(path, (member.mtime, member.mtime))
    finally:
        tar.close()
Example #21
0
 def run_command(self, options, args):
     if args:
         # Uninstall pythons
         for arg in args:
             pkg = Package(arg, options.type)
             pkgname = pkg.name
             if not is_installed(pkg):
                 logger.error("`%s` is not installed." % pkgname)
                 continue
             rm_r(os.path.join(PATH_PYTHONS, pkgname))
     else:
         self.parser.print_help()
Example #22
0
 def _apply_patches(self):
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
         for patch in self.patches:
             if type(patch) is dict:
                 for ed, source in patch.items():
                     s.shell('ed - %s < %s' % (source, ed))
             else:
                 s.shell("patch -p0 < %s" % patch)
     except:
         logger.error("Failed to patch `%s`.\n%s" % (self.build_dir, sys.exc_info()[1]))
         sys.exit(1)
Example #23
0
 def run_command(self, options, args):
     if args:
         # Uninstall pythons
         for arg in args:
             pkg = Package(arg, options.type)
             pkgname = pkg.name
             if not is_installed(pkg):
                 logger.error("`%s` is not installed." % pkgname)
                 continue
             rm_r(os.path.join(PATH_PYTHONS, pkgname))
     else:
         self.parser.print_help()
Example #24
0
 def _apply_patches(self):
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
         for patch in self.patches:
             if type(patch) is dict:
                 for ed, source in patch.items():
                     s.shell('ed - %s < %s' % (source, ed))
             else:
                 s.shell("patch -p0 < %s" % patch)
     except:
         logger.error("Failed to patch `%s`.\n%s" % (self.build_dir, sys.exc_info()[1]))
         sys.exit(1)
Example #25
0
    def __init__(self, version, options):
        # create directories
        makedirs(PATH_BUILD)
        makedirs(PATH_DISTS)
        makedirs(PATH_LOG)

        if options.file is not None:
            if not (is_archive_file(options.file)
                    and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            self.download_url = self.get_version_url(version)
            if version not in self.supported_versions:
                logger.warning(
                    "Unsupported Python version: `%s`, trying with the following URL anyway: %s"
                    % (version, self.download_url))

        self.pkg = Package(version, options.type)
        if options.external_path:
            if not os.path.isabs(options.external_path):
                options.external_path = os.path.join(
                    os.path.abspath(os.path.curdir), options.external_path)
            self.install_dir = os.path.join(options.external_path,
                                            self.pkg.name)
        else:
            self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.pkg.name)
        filename = Link(self.download_url).filename
        self.download_file = os.path.join(PATH_DISTS, filename)

        # cleanup
        if os.path.isdir(self.build_dir):
            shutil.rmtree(self.build_dir)

        if os.path.isdir(self.install_dir):
            if options.reinstall:
                shutil.rmtree(self.install_dir)
            else:
                raise AlreadyInstalledError("You have already installed `%s`" %
                                            self.pkg.name)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []
        self.configure_options = []
Example #26
0
 def download(self):
     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
         logger.info("Downloading %s as %s" %
                     (base_url, self.download_file))
         try:
             Downloader.fetch(self.download_url, self.download_file)
         except DownloadError:
             unlink(self.download_file)
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             sys.exit(1)
Example #27
0
    def __init__(self, version, options):
        # create directories
        makedirs(PATH_BUILD)
        makedirs(PATH_DISTS)
        makedirs(PATH_LOG)

        if options.file is not None:
            if not (is_archive_file(options.file) and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            self.download_url = self.get_version_url(version)
            if version not in self.supported_versions:
                logger.warning("Unsupported Python version: `%s`, trying with the following URL anyway: %s" % (version, self.download_url))

        self.pkg = Package(version, options.type)
        if options.external_path:
            if not os.path.isabs(options.external_path):
                options.external_path = os.path.join(
                    os.path.abspath(os.path.curdir),
                    options.external_path)
            self.install_dir = os.path.join(options.external_path,
                                            self.pkg.name)
        else:
            self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.pkg.name)
        filename = Link(self.download_url).filename
        self.download_file = os.path.join(PATH_DISTS, filename)

        # cleanup
        if os.path.isdir(self.build_dir):
            shutil.rmtree(self.build_dir)

        if os.path.isdir(self.install_dir):
            if options.reinstall:
                shutil.rmtree(self.install_dir)
            else:
                raise AlreadyInstalledError("You have already installed `%s`" % self.pkg.name)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []
        self.configure_options = []
Example #28
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        pkg = Package(args[0], options.type)
        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)
Example #29
0
 def download(self):
     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
         logger.info("Downloading %s as %s" % (base_url, self.download_file))
         try:
             Downloader.fetch(self.download_url, self.download_file)
         except DownloadError:
             unlink(self.download_file)
             logger.error("Failed to download.\n%s" % (sys.exc_info()[1]))
             sys.exit(1)
         except:
             unlink(self.download_file)
             raise
Example #30
0
 def _update_config(self, options, args):
     # config.cfg update
     # TODO: Automatically create for config.cfg
     download_url = PYTHONZ_UPDATE_URL_CONFIG
     if not download_url:
         logger.error("Invalid download url in config.cfg. `%s`" % download_url)
         sys.exit(1)
     distname = Link(PYTHONZ_UPDATE_URL_CONFIG).filename
     download_file = PATH_ETC_CONFIG
     logger.info("Downloading %s as %s" % (distname, download_file))
     try:
         Downloader.fetch(download_url, download_file)
     except DownloadError:
         logger.error("Failed to download. `%s`" % download_url)
         sys.exit(1)
     logger.log("The config.cfg has been updated.")
Example #31
0
    def install(self):
        # 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 = Downloader.read_head_info(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

        self.download_and_extract()
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        shutil.copytree(self.build_dir, self.install_dir)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #32
0
    def run_command(self, options, args):
        if not args or len(args) > 1:
            self.parser.print_help()
            sys.exit(1)

        pkg = Package(args[0], options.type)
        pkgname = pkg.name
        if not is_installed(pkg):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)
        for bin in ('python3', 'python', 'pypy3', 'pypy'):
            path = os.path.join(PATH_PYTHONS, pkgname, 'bin', bin)
            if os.path.exists(path):
                break
        else:
            # fallback
            path = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        logger.log(path)
Example #33
0
    def run_command(self, options, args):
        if not args or len(args) > 1:
            self.parser.print_help()
            sys.exit(1)

        pkg = Package(args[0], options.type)
        pkgname = pkg.name
        if not is_installed(pkg):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)
        for bin in ('python3', 'python', 'pypy3', 'pypy'):
            path = os.path.join(PATH_PYTHONS, pkgname, 'bin', bin)
            if os.path.exists(path):
                break
        else:
            # fallback
            path = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        logger.log(path)
Example #34
0
    def install(self):
        # 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 = Downloader.read_head_info(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

        self.download_and_extract()
        logger.info("Installing %s into %s" % (self.pkg.name, self.install_dir))
        shutil.copytree(self.build_dir, self.install_dir)
        self.symlink()
        logger.info("\nInstalled %(pkgname)s successfully." % {"pkgname": self.pkg.name})
Example #35
0
    def __init__(self, arg, options):
        super(PythonInstallerMacOSX, self).__init__(arg, options)

        # set configure options
        target = get_macosx_deployment_target()
        if target:
            self.configure_options.append('MACOSX_DEPLOYMENT_TARGET=%s' % target)

        # set build options
        if options.framework and options.static:
            logger.error("Can't specify both framework and static.")
            raise Exception
        if options.framework:
            self.configure_options.append('--enable-framework=%s' % os.path.join(self.install_dir, 'Frameworks'))
        elif not options.static:
            self.configure_options.append('--enable-shared')
        if options.universal:
            self.configure_options.append('--enable-universalsdk=/')
            self.configure_options.append('--with-universal-archs=intel')
Example #36
0
    def __init__(self, version, options):
        super(CPythonInstaller, self).__init__(version, options)

        version = Version(self.pkg.version)

        if version >= '3.1':
            self.configure_options.append('--with-computed-gotos')

        # fix for #109
        if version < '2.7':
            self.configure_options.append('SVNVERSION="Unversioned directory"')

        # fix for #127
        if sys.platform.startswith('linux'):
            if version >= '2.5' and version < '3.0':
                self.configure_options.append('--enable-unicode=ucs4')
            elif version >= '3.0' and version < '3.3':
                self.configure_options.append('--with-wide-unicode')

        if sys.platform == "darwin":
            # set configure options
            target = get_macosx_deployment_target()
            if target:
                self.configure_options.append('MACOSX_DEPLOYMENT_TARGET=%s' %
                                              target)

            # set build options
            if options.framework and options.shared:
                logger.error("Can't specify both framework and shared.")
                raise Exception
            if options.framework:
                self.configure_options.append(
                    '--enable-framework=%s' %
                    os.path.join(self.install_dir, 'Frameworks'))
            if options.shared:
                self.configure_options.append('--enable-shared')
            if options.universal:
                self.configure_options.append('--enable-universalsdk=/')
                self.configure_options.append('--with-universal-archs=intel')
        else:
            if options.shared:
                self.configure_options.append('--enable-shared')
Example #37
0
 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)
Example #38
0
    def __init__(self, version, options):
        if options.file is not None:
            if not (is_archive_file(options.file)
                    and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            if version not in self.supported_versions:
                logger.error(
                    "Unsupported Python version: `%s`, you may install it anyway by supplying the download or file URL"
                    % version)
                raise UnknownVersionException
            self.download_url = self.get_version_url(version)
        self.pkg = Package(version, options.type)
        self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.pkg.name)
        filename = Link(self.download_url).filename
        self.download_file = os.path.join(PATH_DISTS, filename)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []
        self.configure_options = []
Example #39
0
    def __init__(self, version, options):
        if options.file is not None:
            if not (is_archive_file(options.file) and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            if version not in self.supported_versions:
                logger.error("Unsupported Python version: `%s`, you may install it anyway by supplying the download or file URL" % version)
                raise UnknownVersionException
            self.download_url = self.get_version_url(version)
        self.pkg = Package(version, options.type)
        self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.pkg.name)
        filename = Link(self.download_url).filename
        self.download_file = os.path.join(PATH_DISTS, filename)

        self.options = options
        self.logfile = os.path.join(PATH_LOG, 'build.log')
        self.patches = []
        self.configure_options = []
Example #40
0
    def __init__(self, arg, options):
        version = arg
        if options.file is not None:
            if not (is_archive_file(options.file) and os.path.isfile(options.file)):
                logger.error('invalid file specified: %s' % options.file)
                raise RuntimeError
            self.download_url  = path_to_fileurl(options.file)
        elif options.url is not None:
            if not is_url(options.url):
                logger.error('invalid URL specified: %s' % options.url)
                raise RuntimeError
            self.download_url = options.url
        else:
            self.download_url = get_python_version_url(options.type, version)
            if not self.download_url:
                logger.error("Unknown python version: `%s`" % version)
                raise UnknownVersionException
        filename = Link(self.download_url).filename
        self.pkg = Package(version, options.type)
        self.install_dir = os.path.join(PATH_PYTHONS, self.pkg.name)
        self.build_dir = os.path.join(PATH_BUILD, self.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 self.pkg.type in ('cpython', 'stackless') and Version(self.pkg.version) >= '3.1':
            self.configure_options = ['--with-computed-gotos']
        else:
            self.configure_options = []
Example #41
0
    def __init__(self, version, options):
        super(CPythonInstaller, self).__init__(version, options)

        if Version(self.pkg.version) >= "3.1":
            self.configure_options.append("--with-computed-gotos")

        if sys.platform == "darwin":
            # set configure options
            target = get_macosx_deployment_target()
            if target:
                self.configure_options.append("MACOSX_DEPLOYMENT_TARGET=%s" % target)

            # set build options
            if options.framework and options.static:
                logger.error("Can't specify both framework and static.")
                raise Exception
            if options.framework:
                self.configure_options.append("--enable-framework=%s" % os.path.join(self.install_dir, "Frameworks"))
            elif not options.static:
                self.configure_options.append("--enable-shared")
            if options.universal:
                self.configure_options.append("--enable-universalsdk=/")
                self.configure_options.append("--with-universal-archs=intel")