Exemple #1
0
 def run_command_clone(self, options, args):
     if len(args) < 3:
         logger.error("Unrecognized command line argument: ( 'pythonbrew venv clone <source> <target>' )")
         sys.exit(1)
     
     if not os.access(PATH_VENVS, os.W_OK):
         logger.error("Can not clone a virtual environment in %s.\nPermission denied." % PATH_VENVS)
         sys.exit(1)
     
     virtualenv_options = []
     if options.no_site_packages:
         virtualenv_options.append('--no-site-packages')
     
     source, target = args[1], args[2]
     source_dir     = os.path.join(self._workon_home, source)
     target_dir     = os.path.join(self._workon_home, target)
     
     if not os.path.isdir(source_dir):
         logger.error('%s does not exist.' % source_dir)
         sys.exit(1)
     
     logger.info("Cloning `%s` environment into `%s` on %s" % (source, target, self._workon_home))
     
     # Create the new venv first
     self.run_command_create(options, ['create', target])
     
     print "Copying " + source + "'s libraries to " + target + "'s virtual environment...",
     # Copy all files and folders into the new venv dir, without replacing anything
     copy_libs(source, target)
     print "done."
     
     # Activate the new venv
     self.run_command_use(options, ['use', target])
Exemple #2
0
 def patch(self):
     version = self.pkg.version
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir)
         patches = []
         if is_macosx_snowleopard():
             if is_python24(version):
                 patch_dir = os.path.join(PATH_PATCHES_MACOSX_PYTHON24,'files')
                 patches = ['patch-configure', 'patch-Makefile.pre.in',
                            'patch-Lib-cgi.py', 'patch-Lib-site.py',
                            'patch-setup.py', 'patch-Include-pyport.h',
                            'patch-Mac-OSX-Makefile.in', 'patch-Mac-OSX-IDLE-Makefile.in',
                            'patch-Mac-OSX-PythonLauncher-Makefile.in', 'patch-configure-badcflags.diff',
                            'patch-configure-arch_only.diff', 'patch-macosmodule.diff',
                            'patch-mactoolboxglue.diff', 'patch-pymactoolbox.diff']
             elif is_python25(version):
                 patch_dir = os.path.join(PATH_PATCHES_MACOSX_PYTHON25,'files')
                 patches = ['patch-Makefile.pre.in.diff', 'patch-Lib-cgi.py.diff',
                            'patch-Lib-distutils-dist.py.diff', 'patch-setup.py.diff',
                            'patch-configure-badcflags.diff', 'patch-configure-arch_only.diff',
                            'patch-64bit.diff', 'patch-pyconfig.h.in.diff',
                            'patch-Modules-posixmodule.c.diff']
         if patches:
             logger.info("Patching %s" % self.pkg.name)
             for patch in patches:
                 s.check_call("patch -p0 < %s" % os.path.join(patch_dir, patch))
     except:
         logger.error("Failed to patch `%s`" % self.build_dir)
         sys.exit(1)
Exemple #3
0
def install_pythonbrew():
    PythonbrewInstaller().install(INSTALLER_ROOT)
    
    m = re.search("(t?csh)", os.environ.get("SHELL"))
    if m:
        shrc = "cshrc"
        yourshrc = m.group(1)+"rc"
    else:
        shrc = yourshrc = "bashrc"
    
    logger.info("""
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.6.6
  pythonbrew install 2.5.5

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})
Exemple #4
0
    def run_command(self, options, args):
        if options.python:
            pkgname = Package(options.python).name
        else:
            pkgname = get_using_python_pkgname()
        if not is_installed(pkgname):
            logger.error('`%s` is not installed.' % pkgname)
            sys.exit(1)
        logger.info('Using %s' % pkgname)
        
        # build a path
        python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        
        # Download bootstrap.py
        download_url = BOOTSTRAP_DLSITE
        download_hash = BOOTSTRAP_HASH
        filename = Link(download_url).filename
        bootstrap = os.path.join(os.getcwd(), filename) # fetching into current directory
        try:
            d = Downloader()
            d.download(filename, download_url, bootstrap, download_hash) 
        except:
            e = sys.exc_info()[1]
            logger.error("%s" % (e))
            sys.exit(1)

        # call bootstrap.py
        if subprocess.call([python, bootstrap, '-d']):
            logger.error('Failed to bootstrap.')
            sys.exit(1)

        # call buildout
        subprocess.call(['./bin/buildout'])
    def run_command(self, options, args):
        if options.python:
            pkgname = Package(options.python).name
        else:
            pkgname = get_using_python_pkgname()
        if not is_installed(pkgname):
            logger.error('`%s` is not installed.' % pkgname)
            sys.exit(1)
        logger.info('Using %s' % pkgname)

        # build a path
        python = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # Download bootstrap.py
        download_url = BOOTSTRAP_DLSITE
        filename = Link(download_url).filename
        bootstrap = os.path.join(os.getcwd(),
                                 filename)  # fetching into current directory
        try:
            d = Downloader()
            d.download(filename, download_url, bootstrap)
        except:
            e = sys.exc_info()[1]
            logger.error("%s" % (e))
            sys.exit(1)

        # call bootstrap.py
        if subprocess.call([python, bootstrap, '-d']):
            logger.error('Failed to bootstrap.')
            sys.exit(1)

        # call buildout
        subprocess.call(['./bin/buildout'])
Exemple #6
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.")
    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.")
Exemple #8
0
    def run_command_create(self, options, args):
        if not os.access(PATH_VENVS, os.W_OK):
            logger.error(
                "Can not create a virtual environment in %s.\nPermission denied."
                % PATH_VENVS)
            sys.exit(1)
        if not self._pkgname:
            logger.error(
                "Unknown python version: ( 'pythonbrew venv create <project> -p VERSION' )"
            )
            sys.exit(1)

        virtualenv_options = []
        if options.no_site_packages:
            virtualenv_options.append('--no-site-packages')

        for arg in args[1:]:
            target_dir = os.path.join(self._workon_home, arg)
            logger.info("Creating `%s` environment into %s" %
                        (arg, self._workon_home))
            # make command
            cmd = [self._py, self._venv, '-p', self._target_py]
            cmd.extend(virtualenv_options)
            cmd.append(target_dir)
            # create environment
            s = Subprocess(verbose=True)
            s.call(cmd)
    def run_command_clone(self, options, args):
        if len(args) < 3:
            logger.error("Unrecognized command line argument: ( 'pythonbrew venv clone <source> <target>' )")
            sys.exit(1)
        if not os.access(PATH_VENVS, os.W_OK):
            logger.error("Can not clone a virtual environment in %s.\nPermission denied." % PATH_VENVS)
            sys.exit(1)
        if not self._pkgname:
            logger.error("Unknown python version: ( 'pythonbrew venv clone <source> <target> -p VERSION' )")
            sys.exit(1)

        source, target = args[1], args[2]
        source_dir = os.path.join(self._workon_home, source)
        target_dir = os.path.join(self._workon_home, target)

        if not os.path.isdir(source_dir):
            logger.error('%s does not exist.' % source_dir)
            sys.exit(1)

        if os.path.isdir(target_dir):
            logger.error('Can not overwrite %s.' % target_dir)
            sys.exit(1)

        logger.info("Cloning `%s` environment into `%s` on %s" % (source, target, self._workon_home))

        # Copies source to target
        cmd = [self._py, self._venv_clone, source_dir, target_dir]
        s = Subprocess()
        s.call(cmd)
Exemple #10
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
Exemple #11
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
Exemple #12
0
def unpack_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
Exemple #13
0
 def _symlink(self, srcbin, dstbin, pkgname):
     """Create a symlink.
     """
     src = os.path.join(PATH_PYTHONS, pkgname, 'bin', srcbin)
     dst = os.path.join(PATH_BIN, dstbin)
     if os.path.isfile(src):
         symlink(src, dst)
     else:
         logger.info("%s: File not found" % src)
Exemple #14
0
 def check_call(self, cmd, shell=None, cwd=None):
     if shell:
         self._shell = shell
     if cwd:
         self._cwd = cwd
     if self._print_cmd:
         logger.info(cmd)
     if self._log:
         cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log)
     retcode = subprocess.call(cmd, shell=self._shell, cwd=self._cwd)
     if retcode != 0:
         raise BuildingException()
Exemple #15
0
 def patch(self):
     version = self.pkg.version
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir)
         patches = []
         eds = {}
         if is_python24(version):
             patch_dir = PATH_PATCHES_MACOSX_PYTHON24
             patches = ['patch-configure', 'patch-Makefile.pre.in',
                        'patch-Lib-cgi.py.diff', 'patch-Lib-site.py.diff',
                        'patch-setup.py.diff', 'patch-Include-pyport.h',
                        'patch-Mac-OSX-Makefile.in', 'patch-Mac-OSX-IDLE-Makefile.in',
                        'patch-Mac-OSX-PythonLauncher-Makefile.in', 'patch-configure-badcflags.diff',
                        'patch-configure-arch_only.diff', 'patch-macosmodule.diff',
                        'patch-mactoolboxglue.diff', 'patch-pymactoolbox.diff',
                        'patch-gestaltmodule.c.diff']
         elif is_python25(version):
             patch_dir = PATH_PATCHES_MACOSX_PYTHON25
             patches = ['patch-Makefile.pre.in.diff', 
                        'patch-Lib-cgi.py.diff',
                        'patch-Lib-distutils-dist.py.diff', 
                        'patch-setup.py.diff',
                        'patch-configure-badcflags.diff', 
                        'patch-configure-arch_only.diff',
                        'patch-64bit.diff', 
                        'patch-pyconfig.h.in.diff',
                        'patch-gestaltmodule.c.diff']
             eds = {'_localemodule.c.ed': 'Modules/_localemodule.c', 
                    'locale.py.ed': 'Lib/locale.py'}
         elif is_python26(version):
             patch_dir = PATH_PATCHES_MACOSX_PYTHON26
             patches = ['patch-Lib-cgi.py.diff', 
                        'patch-Lib-distutils-dist.py.diff',
                        'patch-Mac-IDLE-Makefile.in.diff',
                        'patch-Mac-Makefile.in.diff',
                        'patch-Mac-PythonLauncher-Makefile.in.diff',
                        'patch-Mac-Tools-Doc-setup.py.diff',
                        'patch-setup.py-db46.diff',
                        'patch-Lib-ctypes-macholib-dyld.py.diff',
                        'patch-setup_no_tkinter.py.diff']
             eds = {'_localemodule.c.ed': 'Modules/_localemodule.c', 
                    'locale.py.ed': 'Lib/locale.py'}
             
         if patches or eds:
             logger.info("Patching %s" % self.pkg.name)
             for patch in patches:
                 s.check_call("patch -p0 < %s" % os.path.join(patch_dir, patch))
             for (ed, source) in eds.items():
                 ed = os.path.join(patch_dir, ed)
                 s.check_call('ed - %s < %s' % (source, ed))
     except:
         logger.error("Failed to patch `%s`" % self.build_dir)
         sys.exit(1)
Exemple #16
0
 def check_call(self, cmd, shell=None, cwd=None):
     if shell:
         self._shell = shell
     if cwd:
         self._cwd = cwd
     if self._print_cmd:
         logger.info(cmd)
     if self._log:
         cmd = "(%s) >> '%s' 2>&1" % (cmd, self._log)
     retcode = subprocess.call(cmd, shell=self._shell, cwd=self._cwd)
     if retcode != 0:
         raise ShellCommandException('Failed to `%s` command' % cmd)
Exemple #17
0
 def run_command_init(self):
     if os.path.exists(self._venv):
         logger.info('venv command is already initialized.')
         return
     if not os.access(PATH_DISTS, os.W_OK):
         logger.error("Can not initialize venv command: Permission denied.")
         sys.exit(1)
     d = Downloader()
     download_file = os.path.join(PATH_DISTS, 'virtualenv.tar.gz')
     d.download('virtualenv.tar.gz', VIRTUALENV_DLSITE, download_file)
     logger.info('Extracting virtualenv into %s' % self._venv_dir)
     untar_file(download_file, self._venv_dir)
Exemple #18
0
 def run_command_delete(self, options, args):
     for arg in args[1:]:
         target_dir = os.path.join(self._workon_home, arg)
         if not os.path.isdir(target_dir):
             logger.error('%s already does not exist.' % target_dir)
         else:
             if not os.access(target_dir, os.W_OK):
                 logger.error("Can not delete %s.\nPermission denied." % target_dir)
                 continue
             logger.info('Deleting `%s` environment in %s' % (arg, self._workon_home))
             # make command
             rm_r(target_dir)
Exemple #19
0
 def run_command(self, options, args):
     if not args:
         logger.error("Unrecognized command line argument: argument not found.")
         sys.exit(1)
     pkg = Package(args[0])
     pkgname = pkg.name
     pkgdir = "%s/%s" % (PATH_PYTHONS, pkgname)
     if not os.path.isdir(pkgdir):
         logger.error("`%s` is not installed." % pkgname)
         sys.exit(1)
     self._switch_dir(pkgdir)
     logger.info("Switched to %s" % pkgname)
Exemple #20
0
 def run_command(self, options, args):
     if args:
         pkg = Package(args[0])
         pkgname = pkg.name
         pkgpath = os.path.join(PATH_PYTHONS, pkgname)
         if not os.path.isdir(pkgpath):
             logger.info("`%s` is not installed." % pkgname)
             sys.exit(1)
         if get_current_python_path() == os.path.join(pkgpath,'bin','python'):
             off()
         rm_r(pkgpath)
     else:
         self.parser.print_help()
Exemple #21
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        pkg = Package(args[0])
        pkgname = pkg.name
        if not is_installed(pkgname):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)
        pkgbin = os.path.join(PATH_PYTHONS, pkgname, 'bin')

        set_current_path(pkgbin)

        logger.info("Switched to %s" % pkgname)
Exemple #22
0
 def install_setuptools(self):
     options = self.options
     pkgname = self.pkg.name
     if options.no_setuptools:
         logger.info("Skip installation setuptools.")
         return
     if re.match("^Python-3.*", pkgname):
         is_python3 = True
     else:
         is_python3 = False
     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)
         logger.info("Installing distribute into %s" % install_dir)
         s.check_call("%s %s" % (path_python, filename))
         if os.path.isfile("%s/bin/easy_install" % (install_dir)) and not is_python3:
             logger.info("Installing pip into %s" % install_dir)
             s.check_call("%s/bin/easy_install pip" % (install_dir))
     except:
         logger.error("Failed to install setuptools. See %s/build.log to see why." % (ROOT))
         logger.info("Skip install setuptools.")
 def _do_patch(self):
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
         if self.patches:
             logger.info("Patching %s" % self.pkg.name)
             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)
 def _do_patch(self):
     try:
         s = Subprocess(log=self.logfile, cwd=self.build_dir, verbose=self.options.verbose)
         if self.patches:
             logger.info("Patching %s" % self.pkg.name)
             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)
Exemple #25
0
 def run_command(self, options, args):
     if not args:
         logger.info("Unrecognized command line argument: argument not found.")
         sys.exit(1)
     python_file = args[0]
     
     pythons = self._get_pythons(options.pythons)
     for d in pythons:
         path = os.path.join(PATH_PYTHONS, d, 'bin', 'python')
         if os.path.isfile(path) and os.access(path, os.X_OK):
             if options.verbose:
                 logger.info('*** %s ***' % d)
             p = Popen("%s %s" % (path, python_file), shell=True)
             p.wait()
Exemple #26
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     pkg = Package(args[0])
     pkgname = pkg.name
     if not is_installed(pkgname):
         logger.error("`%s` is not installed." % pkgname)
         sys.exit(1)
     pkgbin = os.path.join(PATH_PYTHONS,pkgname,'bin')
     
     set_current_path(pkgbin)
     
     logger.info("Switched to %s" % pkgname)
Exemple #27
0
 def __init__(self, arg, options):
     super(PythonInstallerMacOSX, self).__init__(arg, options)
     version = self.pkg.version
     # check for version
     if version < '2.6' and (version != '2.4.6' and version != '2.5.5'):
         logger.info("`%s` is not supported on MacOSX Snow Leopard" % self.pkg.name)
         raise NotSupportedVersionException
     # set configure options
     if is_python24(version):
         self.configure_options = '--with-universal-archs="intel" MACOSX_DEPLOYMENT_TARGET=10.6 CPPFLAGS="-D__DARWIN_UNIX03"'
     elif is_python25(version):
         self.configure_options = '--with-universal-archs="intel" MACOSX_DEPLOYMENT_TARGET=10.6 CPPFLAGS="-D_DARWIN_C_SOURCE"'
     elif is_python26(version):
         self.configure_options = '--with-universal-archs="intel" --enable-universalsdk=/ MACOSX_DEPLOYMENT_TARGET=10.6'
Exemple #28
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        pkg = Package(args[0])
        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)
Exemple #29
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     pkg = Package(args[0])
     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)
Exemple #30
0
 def run_command(self, options, args):
     if args:
         pkg = Package(args[0])
         pkgname = pkg.name
         pkgpath = "%s/%s" % (PATH_PYTHONS, pkgname)
         if not os.path.isdir(pkgpath):
             logger.info("`%s` is not installed." % pkgname)
             sys.exit(1)
         if os.path.islink("%s/current" % PATH_PYTHONS):
             curpath = os.path.realpath("%s/current" % PATH_PYTHONS)
             if pkgpath == curpath:
                 off()
         rm_r(pkgpath)
     else:
         self.parser.print_help()
Exemple #31
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.info("The config.cfg has been updated.")
Exemple #32
0
 def run_command(self, options, args):
     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.info("%s" % pkgname)
         else:
             print "Python version not found. `%s`" % pkg.name
     else:
         for pkgname in self._get_packages_name(options):
             logger.info("%s" % pkgname)
Exemple #33
0
    def run_command_delete(self, options, args):
        if not self._pkgname:
            logger.error("Unknown python version: ( 'pythonbrew venv delete <project> -p VERSION' )")
            sys.exit(1)

        for arg in args[1:]:
            target_dir = os.path.join(self._workon_home, arg)
            if not os.path.isdir(target_dir):
                logger.error('%s does not exist.' % target_dir)
            else:
                if not os.access(target_dir, os.W_OK):
                    logger.error("Can not delete %s.\nPermission denied." % target_dir)
                    continue
                logger.info('Deleting `%s` environment in %s' % (arg, self._workon_home))
                # make command
                rm_r(target_dir)
Exemple #34
0
    def run_command_rename(self, options, args):
        if len(args) < 3:
            logger.error("Unrecognized command line argument: ( 'pythonbrew venv rename <source> <target>' )")
            sys.exit(1)
        if not os.access(PATH_VENVS, os.W_OK):
            logger.error("Can not rename a virtual environment in %s.\nPermission denied." % PATH_VENVS)
            sys.exit(1)
        if not self._pkgname:
            logger.error("Unknown python version: ( 'pythonbrew venv rename <source> <target> -p VERSION' )")
            sys.exit(1)

        logger.info("Rename `%s` environment to `%s` on %s" % (args[1], args[2], self._workon_home))

        source, target = args[1], args[2]
        self.run_command_clone(options, ['clone', source, target])
        self.run_command_delete(options, ['delete', source])
Exemple #35
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     pythons = self._get_pythons(options.pythons)
     for d in pythons:
         if options.verbose:
             logger.info('`%s` running...' % d)
         path = os.path.join(PATH_PYTHONS, d, 'bin', args[0])
         if os.path.isfile(path) and os.access(path, os.X_OK):
             subprocess.call([path] + args[1:])
         else:
             path = os.path.join(PATH_PYTHONS, d, 'bin', 'python')
             if os.path.isfile(path) and os.access(path, os.X_OK):
                 subprocess.call([path] + args)
             else:
                 logger.error('%s: No such file or directory.' % path)
Exemple #36
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     pythons = self._get_pythons(options.pythons)
     for d in pythons:
         if options.verbose:
             logger.info('`%s` running...' % d)
         path = os.path.join(PATH_PYTHONS, d, 'bin', args[0])
         if os.path.isfile(path) and os.access(path, os.X_OK):
             subprocess.call([path] + args[1:])
         else:
             path = os.path.join(PATH_PYTHONS, d, 'bin', 'python')
             if os.path.isfile(path) and os.access(path, os.X_OK):
                 subprocess.call([path] + args)
             else:
                 logger.error('%s: No such file or directory.' % path)
Exemple #37
0
 def run_command(self, options, args):
     if args:
         # Install pythons
         for arg in args:
             try:
                 if is_macosx_snowleopard():
                     p = PythonInstallerMacOSX(arg, options)
                 else:
                     p = PythonInstaller(arg, options)
                 p.install()
             except UnknownVersionException:
                 continue
             except AlreadyInstalledException:
                 continue
             except NotSupportedVersionException:
                 continue
     else:
         logger.info("Unknown python version.")
Exemple #38
0
 def installed(self, options, args):
     logger.info('# installed pythons')
     cur = get_current_python_path()
     for d in sorted(os.listdir(PATH_PYTHONS)):
         if cur == os.path.join(PATH_PYTHONS, d, 'bin','python'):
             logger.info('%s (*)' % d)
             cur = None
         else:
             logger.info('%s' % d)
     if cur:
         logger.info('%s (*)' % cur)
 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)
Exemple #40
0
    def run_command_clone(self, options, args):
        if len(args) < 3:
            logger.error(
                "Unrecognized command line argument: ( 'pythonbrew venv clone <source> <target>' )"
            )
            sys.exit(1)

        if not os.access(PATH_VENVS, os.W_OK):
            logger.error(
                "Can not clone a virtual environment in %s.\nPermission denied."
                % PATH_VENVS)
            sys.exit(1)

        virtualenv_options = []
        if options.no_site_packages:
            virtualenv_options.append('--no-site-packages')

        source, target = args[1], args[2]
        source_dir = os.path.join(self._workon_home, source)
        target_dir = os.path.join(self._workon_home, target)

        if not os.path.isdir(source_dir):
            logger.error('%s does not exist.' % source_dir)
            sys.exit(1)

        logger.info("Cloning `%s` environment into `%s` on %s" %
                    (source, target, self._workon_home))

        # Create the new venv first
        self.run_command_create(options, ['create', target])

        print "Copying " + source + "'s libraries to " + target + "'s virtual environment...",
        # Copy all files and folders into the new venv dir, without replacing anything
        copy_libs(source, target)
        print "done."

        # Activate the new venv
        self.run_command_use(options, ['use', target])
Exemple #41
0
 def run_command_init(self):
     if os.path.exists(self._venv):
         logger.info('Remove virtualenv. (%s)' % self._venv_dir)
         rm_r(self._venv_dir)
     if os.path.exists(self._venv_clone):
         logger.info('Remove virtualenv-clone. (%s)' % self._venv_clone_dir)
         rm_r(self._venv_clone_dir)
     if not os.access(PATH_DISTS, os.W_OK):
         logger.error("Can not initialize venv command: Permission denied.")
         sys.exit(1)
     d = Downloader()
     download_file = os.path.join(PATH_DISTS, 'virtualenv.tar.gz')
     d.download('virtualenv.tar.gz', VIRTUALENV_DLSITE, download_file)
     logger.info('Extracting virtualenv into %s' % self._venv_dir)
     untar_file(download_file, self._venv_dir)
     download_file = os.path.join(PATH_DISTS, 'virtualenv-clone.tar.gz')
     d.download('virtualenv-clone.tar.gz', VIRTUALENV_CLONE_DLSITE, download_file)
     logger.info('Extracting virtualenv-clone into %s' % self._venv_clone_dir)
     untar_file(download_file, self._venv_clone_dir)
Exemple #42
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.")
Exemple #43
0
 def download(self, msg, url, path):
     logger.info("Downloading %s as %s" % (msg, path))
     c = Curl()
     c.fetch(url, path)
Exemple #44
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))
            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)