Example #1
0
 def symlink(self):
     install_dir = os.path.realpath(self.install_dir)
     if self.pkg.type == 'pypy':
         bin_dir = os.path.join(install_dir, 'bin')
         symlink(os.path.join(bin_dir, 'pypy'),
                 os.path.join(bin_dir, 'python'))
         return
     if self.options.framework:
         # create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
         bin_dir = os.path.join(install_dir, 'bin')
         if os.path.exists(bin_dir):
             rm_r(bin_dir)
         m = re.match(r'\d\.\d', self.pkg.version)
         if m:
             version = m.group(0)
         symlink(
             os.path.join(install_dir, 'Frameworks',
                          'Python.framework', 'Versions', version, 'bin'),
             os.path.join(bin_dir))
     path_python = os.path.join(install_dir, 'bin', 'python')
     if not os.path.isfile(path_python):
         src = None
         for d in os.listdir(os.path.join(install_dir, 'bin')):
             if re.match(r'python\d\.\d', d):
                 src = d
                 break
         if src:
             path_src = os.path.join(install_dir, 'bin', src)
             symlink(path_src, path_python)
Example #2
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 #3
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 #4
0
 def symlink(self):
     install_dir = os.path.realpath(self.install_dir)
     if self.pkg.type == "pypy":
         bin_dir = os.path.join(install_dir, "bin")
         symlink(os.path.join(bin_dir, "pypy"), os.path.join(bin_dir, "python"))
         return
     if self.options.framework:
         # create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
         bin_dir = os.path.join(install_dir, "bin")
         if os.path.exists(bin_dir):
             rm_r(bin_dir)
         m = re.match(r"\d\.\d", self.pkg.version)
         if m:
             version = m.group(0)
         symlink(
             os.path.join(install_dir, "Frameworks", "Python.framework", "Versions", version, "bin"),
             os.path.join(bin_dir),
         )
     path_python = os.path.join(install_dir, "bin", "python")
     if not os.path.isfile(path_python):
         src = None
         for d in os.listdir(os.path.join(install_dir, "bin")):
             if re.match(r"python\d\.\d", d):
                 src = d
                 break
         if src:
             path_src = os.path.join(install_dir, "bin", src)
             symlink(path_src, path_python)
Example #5
0
 def symlink(self):
     install_dir = os.path.realpath(self.install_dir)
     if self.pkg.type == 'pypy':
         bin_dir = os.path.join(install_dir, 'bin')
         symlink(os.path.join(bin_dir, 'pypy'), os.path.join(bin_dir, 'python'))
         return
     if self.options.framework:
         # create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
         bin_dir = os.path.join(install_dir, 'bin')
         if os.path.exists(bin_dir):
             rm_r(bin_dir)
         m = re.match(r'\d\.\d', self.pkg.version)
         if m:
             version = m.group(0)
         symlink(os.path.join(install_dir, 'Frameworks', 'Python.framework', 'Versions', version, 'bin'), os.path.join(bin_dir))
     path_python = os.path.join(install_dir, 'bin', 'python')
     if not os.path.isfile(path_python):
         src = None
         for d in os.listdir(os.path.join(install_dir, 'bin')):
             if re.match(r'python\d\.\d', d):
                 src = d
                 break
         if src:
             path_src = os.path.join(install_dir, 'bin', src)
             symlink(path_src, path_python)
Example #6
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 #7
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 #8
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 #9
0
    def install(installer_root):
        # create directories
        makedirs(PATH_PYTHONS)
        makedirs(PATH_BUILD)
        makedirs(PATH_DISTS)
        makedirs(PATH_ETC)
        makedirs(PATH_BIN)
        makedirs(PATH_LOG)
        makedirs(PATH_HOME_ETC)

        # create script directories
        rm_r(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS_PYTHONZ)
        makedirs(PATH_SCRIPTS_PYTHONZ_COMMANDS)
        makedirs(PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # copy all .py files
        for path in glob.glob(os.path.join(installer_root, "*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ)
        for path in glob.glob(os.path.join(installer_root, "commands", "*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_COMMANDS)
        for path in glob.glob(os.path.join(installer_root, "installer", "*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # create patches direcotry
        rm_r(PATH_PATCHES)
        shutil.copytree(os.path.join(installer_root, "patches"), PATH_PATCHES)

        # create a main file
        with open("%s/pythonz_main.py" % PATH_SCRIPTS, "w") as f:
            f.write(
                """import pythonz
if __name__ == "__main__":
    pythonz.main()
"""
            )

        # create entry point file
        with open(PATH_BIN_PYTHONZ, "w") as f:
            f.write(
                """#!/usr/bin/env bash
%s %s/pythonz_main.py "$@"
"""
                % (sys.executable, PATH_SCRIPTS)
            )

        # mode 0755
        os.chmod(
            PATH_BIN_PYTHONZ,
            stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH,
        )

        # create a bashrc for pythonz
        shutil.copy(os.path.join(installer_root, "etc", "bashrc"), os.path.join(PATH_ETC, "bashrc"))

        # copy config.cfg
        shutil.copy(os.path.join(installer_root, "etc", "config.cfg"), PATH_ETC_CONFIG)
Example #10
0
    def install(installer_root):
        # create directories
        makedirs(PATH_PYTHONS)
        makedirs(PATH_BUILD)
        makedirs(PATH_DISTS)
        makedirs(PATH_ETC)
        makedirs(PATH_BASH_COMPLETION)
        makedirs(PATH_BIN)
        makedirs(PATH_LOG)
        makedirs(PATH_HOME_ETC)

        # create script directories
        rm_r(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS_PYTHONZ)
        makedirs(PATH_SCRIPTS_PYTHONZ_COMMANDS)
        makedirs(PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # copy all .py files
        for path in glob.glob(os.path.join(installer_root,"*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ)
        for path in glob.glob(os.path.join(installer_root,"commands","*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_COMMANDS)
        for path in glob.glob(os.path.join(installer_root,"installer","*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # create patches direcotry
        rm_r(PATH_PATCHES)
        shutil.copytree(os.path.join(installer_root,"patches"), PATH_PATCHES)

        # create a main file
        with open("%s/pythonz_main.py" % PATH_SCRIPTS, "w") as f:
            f.write("""import pythonz
if __name__ == "__main__":
    pythonz.main()
""")

        # create entry point file
        with open(PATH_BIN_PYTHONZ, "w") as f:
            f.write("""#!/usr/bin/env bash
python %s/pythonz_main.py "$@"
""" % PATH_SCRIPTS)

        # mode 0755
        os.chmod(PATH_BIN_PYTHONZ, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH)

        # create a bashrc for pythonz
        shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc'))

        # create a fish file for pythonz
        shutil.copy(os.path.join(installer_root, 'etc', 'pythonz.fish'), os.path.join(PATH_ETC, 'pythonz.fish'))

        #copy all *.sh files to bash_completion.d directory
        for path in glob.glob(os.path.join(installer_root,"etc","bash_completion.d","*.sh")):
            shutil.copy( path, PATH_BASH_COMPLETION )
Example #11
0
    def install(installer_root):
        # create directories
        makedirs(PATH_PYTHONS)
        makedirs(PATH_BUILD)
        makedirs(PATH_DISTS)
        makedirs(PATH_ETC)
        makedirs(PATH_BASH_COMPLETION)
        makedirs(PATH_BIN)
        makedirs(PATH_LOG)
        makedirs(PATH_HOME_ETC)

        # create script directories
        rm_r(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS)
        makedirs(PATH_SCRIPTS_PYTHONZ)
        makedirs(PATH_SCRIPTS_PYTHONZ_COMMANDS)
        makedirs(PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # copy all .py files
        for path in glob.glob(os.path.join(installer_root,"*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ)
        for path in glob.glob(os.path.join(installer_root,"commands","*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_COMMANDS)
        for path in glob.glob(os.path.join(installer_root,"installer","*.py")):
            shutil.copy(path, PATH_SCRIPTS_PYTHONZ_INSTALLER)

        # create patches direcotry
        rm_r(PATH_PATCHES)
        shutil.copytree(os.path.join(installer_root,"patches"), PATH_PATCHES)

        # create a main file
        with open("%s/pythonz_main.py" % PATH_SCRIPTS, "w") as f:
            f.write("""import pythonz
if __name__ == "__main__":
    pythonz.main()
""")

        # create entry point file
        with open(PATH_BIN_PYTHONZ, "w") as f:
            f.write("""#!/usr/bin/env bash
python %s/pythonz_main.py "$@"
""" % PATH_SCRIPTS)

        # mode 0755
        os.chmod(PATH_BIN_PYTHONZ, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH)

        # create a bashrc for pythonz
        shutil.copy(os.path.join(installer_root,'etc','bashrc'), os.path.join(PATH_ETC,'bashrc'))

        # create a fish file for pythonz
        shutil.copy(os.path.join(installer_root, 'etc', 'pythonz.fish'), os.path.join(PATH_ETC, 'pythonz.fish'))

        #copy all *.sh files to bash_completion.d directory
        for path in glob.glob(os.path.join(installer_root,"etc","bash_completion.d","*.sh")):
            shutil.copy( path, PATH_BASH_COMPLETION )
Example #12
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 #13
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 #14
0
 def symlink(self):
     install_dir = os.path.realpath(self.install_dir)
     bin_dir = os.path.join(install_dir, 'bin')
     if self.options.framework:
         # create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
         if os.path.exists(bin_dir):
             rm_r(bin_dir)
         m = re.match(r'\d\.\d', self.pkg.version)
         if m:
             version = m.group(0)
         symlink(os.path.join(install_dir, 'Frameworks', 'Python.framework', 'Versions', version, 'bin'), os.path.join(bin_dir))
     path_python = os.path.join(bin_dir, 'python')
     if not os.path.isfile(path_python):
         for f in os.listdir(bin_dir):
             if re.match(r'python\d\.\d$', f):
                 symlink(os.path.join(bin_dir, f), path_python)
                 break
Example #15
0
 def symlink(self):
     install_dir = os.path.realpath(self.install_dir)
     bin_dir = os.path.join(install_dir, 'bin')
     if self.options.framework:
         # create symlink bin -> /path/to/Frameworks/Python.framework/Versions/?.?/bin
         if os.path.exists(bin_dir):
             rm_r(bin_dir)
         m = re.match(r'\d\.\d', self.pkg.version)
         if m:
             version = m.group(0)
         symlink(os.path.join(install_dir, 'Frameworks', 'Python.framework', 'Versions', version, 'bin'), os.path.join(bin_dir))
     path_python = os.path.join(bin_dir, 'python')
     if not os.path.isfile(path_python):
         for f in os.listdir(bin_dir):
             if re.match(r'python\d\.\d$', f):
                 symlink(os.path.join(bin_dir, f), path_python)
                 break
Example #16
0
 def _cleanup(self, root):
     for dir in os.listdir(root):
         rm_r(os.path.join(root, dir))
Example #17
0
 def _cleanup(self, root):
     for dir in os.listdir(root):
         rm_r(os.path.join(root, dir))