Exemple #1
0
 def run_command(self, options, args):
     if args:
         # Uninstall pythonidae
         for arg in args:
             pkg = Package(arg)
             pkgname = pkg.name
             pkgpath = os.path.join(PATH_PYTHONS, pkgname)
             venvpath = os.path.join(PATH_VENVS, pkgname)
             if not is_installed(pkgname):
                 logger.error("`%s` is not installed." % pkgname)
                 continue
             if get_using_python_pkgname() == pkgname:
                 off()
             for d in os.listdir(PATH_BIN):
                 # remove symlink
                 path = os.path.join(PATH_BIN, d)
                 if os.path.islink(path):
                     basename = os.path.basename(os.path.realpath(path))
                     tgtpath = os.path.join(pkgpath, "bin", basename)
                     if os.path.isfile(tgtpath) and os.path.samefile(path, tgtpath):
                         unlink(path)
             rm_r(pkgpath)
             rm_r(venvpath)
     else:
         self.parser.print_help()
Exemple #2
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 not args:
            self.parser.print_help()
            sys.exit(1)
        cmd = args[0]
        if not cmd in ('init', 'create', 'delete', 'use', 'list', 'clone', 'rename', 'print_activate'):
            self.parser.print_help()
            sys.exit(1)

        # initialize?
        if cmd == 'init':
            self.run_command_init()
            return

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            pkgname = get_using_python_pkgname()

        self._pkgname = pkgname
        if self._pkgname:
            self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
            self._workon_home = os.path.join(PATH_VENVS, pkgname)
            self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # is already installed virtualenv?
        if not os.path.exists(self._venv) or not os.path.exists(self._venv_clone):
            self.run_command_init()

        # Create a shell script
        self.__getattribute__('run_command_%s' % cmd)(options, args)
    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 #5
0
 def run_command(self, options, args):
     if args:
         # Uninstall pythons
         for arg in args:
             pkg = Package(arg)
             pkgname = pkg.name
             pkgpath = os.path.join(PATH_PYTHONS, pkgname)
             venvpath = os.path.join(PATH_VENVS, pkgname)
             if not is_installed(pkgname):
                 logger.error("`%s` is not installed." % pkgname)
                 continue
             if get_using_python_pkgname() == pkgname:
                 off()
             for d in os.listdir(PATH_BIN):
                 # remove symlink
                 path = os.path.join(PATH_BIN, d)
                 if os.path.islink(path):
                     basename = os.path.basename(os.path.realpath(path))
                     tgtpath = os.path.join(pkgpath, 'bin', basename)
                     if os.path.isfile(tgtpath) and os.path.samefile(
                             path, tgtpath):
                         unlink(path)
             rm_r(pkgpath)
             rm_r(venvpath)
     else:
         self.parser.print_help()
Exemple #6
0
 def installed(self, options, args):
     logger.log("# pythonbrew pythons")
     cur = get_using_python_pkgname()
     for d in sorted(os.listdir(PATH_PYTHONS)):
         if cur and cur == d:
             logger.log('  %s (*)' % d)
         else:
             logger.log('  %s' % d)
Exemple #7
0
 def installed(self, options, args):
     logger.log("# pythonbrew pythons")
     cur = get_using_python_pkgname()
     for d in sorted(os.listdir(PATH_PYTHONS)):
         if cur and cur == d:
             logger.log('  %s (*)' % d)
         else:
             logger.log('  %s' % d)
Exemple #8
0
    def run_command(self, options, args):
        if options.default:
            # create only one instance as default of an application.
            pythons = self._get_pythons([options.default])
            for pkgname in pythons:
                if args:
                    bin = args[0]
                    self._symlink(bin, bin, pkgname)
                else:
                    self._symlink('python', 'py', pkgname)
        elif options.venv:
            if options.pythons:
                pkgname = Package(options.pythons[0]).name
            else:
                pkgname = get_using_python_pkgname()
            if not is_installed(pkgname):
                logger.error('`%s` is not installed.')
                sys.exit(1)

            venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
            venv_dir = os.path.join(venv_pkgdir, options.venv)
            if not os.path.isdir(venv_dir):
                logger.error("`%s` environment was not found in %s." %
                             (options.venv, venv_pkgdir))
                sys.exit(1)
            pkg = Package(pkgname)
            if args:
                bin = args[0]
                dstbin = '%s%s-%s' % (bin, pkg.version, options.venv)
                self._symlink(bin, dstbin, pkgname)
            else:
                dstbin = 'py%s-%s' % (pkg.version, options.venv)
                self._symlink('python', dstbin, pkgname)
        else:
            pythons = self._get_pythons(options.pythons)
            for pkgname in pythons:
                if options.remove:
                    # remove symlinks
                    for bin in os.listdir(PATH_BIN):
                        path = os.path.join(PATH_BIN, bin)
                        if os.path.islink(path):
                            unlink(path)
                else:
                    # create symlinks
                    if args:
                        bin = args[0]
                        self._symlink_version_suffix(bin, bin, pkgname)
                    else:
                        self._symlink_version_suffix('python', 'py', pkgname)
Exemple #9
0
 def run_command(self, options, args):
     if options.default:
         # create only one instance as default of an application.
         pythons = self._get_pythons([options.default])
         for pkgname in pythons:
             if args:
                 bin = args[0]
                 self._symlink(bin, bin, pkgname)
             else:
                 self._symlink('python', 'py', pkgname)
     elif options.venv:
         if options.pythons:
             pkgname = Package(options.pythons[0]).name
         else:
             pkgname = get_using_python_pkgname()
         if not is_installed(pkgname):
             logger.error('`%s` is not installed.')
             sys.exit(1)
         
         venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
         venv_dir = os.path.join(venv_pkgdir, options.venv)
         if not os.path.isdir(venv_dir):
             logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir))
             sys.exit(1)
         pkg = Package(pkgname)
         if args:
             bin = args[0]
             dstbin = '%s%s-%s' % (bin, pkg.version, options.venv)
             self._symlink(bin, dstbin, pkgname)
         else:
             dstbin = 'py%s-%s' % (pkg.version, options.venv)
             self._symlink('python', dstbin, pkgname)
     else:
         pythons = self._get_pythons(options.pythons)
         for pkgname in pythons:
             if options.remove:
                 # remove symlinks
                 for bin in os.listdir(PATH_BIN):
                     path = os.path.join(PATH_BIN, bin)
                     if os.path.islink(path):
                         unlink(path)
             else:
                 # create symlinks
                 if args:
                     bin = args[0]
                     self._symlink_version_suffix(bin, bin, pkgname)
                 else:
                     self._symlink_version_suffix('python', 'py', pkgname)
Exemple #10
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.' % pkgnam)
            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
        option_boostrap = [python.encode('utf8'), bootstrap, '-d']
        if options.config:
            option_boostrap.extend(['-c', options.config])
        
        
        cmd_bootstrap =' '.join("{0}".format(iter_el) for
                                iter_el in  option_boostrap)
        
        if subprocess.call(shlex.split(cmd_bootstrap.encode('utf8'))):
                logger.error('Failed to bootstrap.')
                sys.exit(1)
        
        # call buildout
        if options.config:
            subprocess.call(['./bin/buildout', '-c', options.config])
        else:
            subprocess.call(['./bin/buildout'])
Exemple #11
0
    def run_command(self, options, args):
        if not args:
            self.parser.print_help()
            sys.exit(1)
        cmd = args[0]
        if not cmd in ('init', 'create', 'delete', 'use', 'list'):
            self.parser.print_help()
            sys.exit(1)

        # initialize?
        if cmd == 'init':
            self.run_command_init()
            return

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            # check using python under pythonbrew
            pkgname = get_using_python_pkgname()
            if not pkgname:
                logger.error(
                    'Can not use venv command before switching a python.  Try \'pythonbrew switch <version of python>\'.'
                )
                sys.exit(1)
        self._pkgname = pkgname
        self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
        self._workon_home = os.path.join(PATH_VENVS, pkgname)
        self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')

        # is already installed virtualenv?
        if not os.path.exists(self._venv):
            self.run_command_init()

        # Create a shell script
        self.__getattribute__('run_command_%s' % cmd)(options, args)
Exemple #12
0
 def run_command(self, options, args):
     if not args:
         self.parser.print_help()
         sys.exit(1)
     cmd = args[0]
     if not cmd in ('init', 'create', 'delete', 'use', 'list'):
         self.parser.print_help()
         sys.exit(1)
     
     # initialize?
     if cmd == 'init':
         self.run_command_init()
         return
     
     # target python interpreter
     if options.python:
         pkgname = Package(options.python).name
         if not is_installed(pkgname):
             logger.error('%s is not installed.' % pkgname)
             sys.exit(1)
     else:
         # check using python under pythonbrew
         pkgname = get_using_python_pkgname()
         if not pkgname:
             logger.error('Can not use venv command before switching a python.  Try \'pythonbrew switch <version of python>\'.')
             sys.exit(1)
     self._pkgname = pkgname
     self._target_py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
     self._workon_home = os.path.join(PATH_VENVS, pkgname)
     self._py = os.path.join(PATH_PYTHONS, pkgname, 'bin', 'python')
     
     # is already installed virtualenv?
     if not os.path.exists(self._venv):
         self.run_command_init()
     
     # Create a shell script
     self.__getattribute__('run_command_%s' % cmd)(options, args)
Exemple #13
0
    def run_command(self, options, args):
        if args:
            bin_ = args[0]
        else:
            bin_ = 'python'

        # target python interpreter
        if options.python:
            pkgname = Package(options.python).name
            if not is_installed(pkgname):
                logger.error('%s is not installed.' % pkgname)
                sys.exit(1)
        else:
            pkgname = get_using_python_pkgname()

        if not pkgname:
            logger.error("Unknown python version: ( 'pythonbrew locate -p VERSION' )")
            sys.exit(1)

        if options.venv:
            venv_pkgdir = os.path.join(PATH_VENVS, pkgname)
            venv_dir = os.path.join(venv_pkgdir, options.venv)
            if not os.path.isdir(venv_dir):
                logger.error("`%s` environment was not found in %s." % (options.venv, venv_pkgdir))
                sys.exit(1)

            bindir = os.path.join(venv_dir, 'bin')
        else:
            bindir = os.path.join(PATH_PYTHONS, pkgname, 'bin')

        if not os.path.isdir(bindir):
            logger.error("`%s` is not installed." % pkgname)
            sys.exit(1)

        path = os.path.join(bindir, bin_)
        logger.log(path)