(self, directory, codename=None, arch=None)
return self.context
Bootstrap a basic Debian or Ubuntu system using debootstrap_.

        :param directory: The pathname of the target directory (a string).
        :param codename: The codename of the target (a string).
        :param arch: The target architecture (a string or :data:`None`).
        :returns: A :class:`~executor.contexts.ChangeRootContext` object.

        If `directory` already exists and isn't empty then it is assumed that
        the chroot has already been created and debootstrap_ won't be run.
        Before this method returns it changes :attr:`context` to the chroot.

        .. _debootstrap: https://manpages.debian.org/debootstrap
Bootstrap a basic Debian or Ubuntu system using debootstrap_.
Bootstrap a basic Debian or Ubuntu system using debootstrap_ .
def create_chroot(self, directory, codename=None, arch=None):
        """
        Bootstrap a basic Debian or Ubuntu system using debootstrap_.

        :param directory: The pathname of the target directory (a string).
        :param codename: The codename of the target (a string).
        :param arch: The target architecture (a string or :data:`None`).
        :returns: A :class:`~executor.contexts.ChangeRootContext` object.

        If `directory` already exists and isn't empty then it is assumed that
        the chroot has already been created and debootstrap_ won't be run.
        Before this method returns it changes :attr:`context` to the chroot.

        .. _debootstrap: https://manpages.debian.org/debootstrap
        """
        logger.debug("Checking if chroot already exists (%s) ..", directory)
        if self.context.exists(directory) and self.context.list_entries(directory):
            logger.info("The chroot already exists, skipping initialization.")
            first_run = False
        else:
            # Ensure the `debootstrap' program is installed.
            if not self.context.find_program('debootstrap'):
                logger.info("Installing `debootstrap' program ..")
                self.context.execute('apt-get', 'install', '--yes', 'debootstrap', sudo=True)
            # Use the `debootstrap' program to create the chroot.
            timer = Timer()
            debootstrap_command = ['debootstrap']
            if arch:
                debootstrap_command.append('--arch=%s' % arch)
            release_chroot = None
            keyring_chroot = ''
            codename_chroot = ''
            best_mirror_chroot = None
            generate_sources_list_chroot = None
            if codename and codename != self.distribution_codename:
                updater_chroot = AptMirrorUpdater()
                updater_chroot.distribution_codename = codename
                if updater_chroot.distributor_id == 'linuxmint':
                    msg = "It seems no sense to create chroot of Linux Mint, " \
                          "please specify a codename of Ubuntu or Debian " \
                          "to create chroot."
                    raise ValueError(msg)

                if not self.context.exists(updater_chroot.release.keyring_file):
                    if updater_chroot.distributor_id == 'ubuntu':
                        self.context.execute('apt-get', 'install', '--yes', 'ubuntu-keyring', sudo=True)
                    elif updater_chroot.distributor_id == 'debian':
                        self.context.execute('apt-get', 'install', '--yes', 'debian-archive-keyring', sudo=True)
                release_chroot = updater_chroot.release
                keyring_chroot = updater_chroot.release.keyring_file
                codename_chroot = codename
                best_mirror_chroot = updater_chroot.best_mirror
            else:
                if self.distributor_id == 'linuxmint':
                    msg = "It seems no sense to create chroot of Linux Mint, " \
                          "please use -C to specify a codename of Ubuntu or Debian " \
                          "to create chroot."
                    raise ValueError(msg)
                release_chroot = self.release
                keyring_chroot = self.release.keyring_file
                codename_chroot = self.distribution_codename
                best_mirror_chroot = self.best_mirror
            logger.info("Creating %s chroot in %s ..", release_chroot, directory)
            debootstrap_command.append('--keyring=%s' % keyring_chroot)
            debootstrap_command.append(codename_chroot)
            debootstrap_command.append(directory)
            debootstrap_command.append(best_mirror_chroot)
            self.context.execute(*debootstrap_command, sudo=True)
            logger.info("Took %s to create %s chroot.", timer, release_chroot)
            first_run = True
        # Switch the execution context to the chroot and reset the locale (to
        # avoid locale warnings emitted by post-installation scripts run by
        # `apt-get install').
        self.context = ChangeRootContext(
            chroot=directory,
            environment=dict(LC_ALL='C'),
        )
        # Clear the values of cached properties that can be
        # invalidated by switching the execution context.
        del self.current_mirror
        del self.stable_mirror
        if codename and codename != self.distribution_codename:
            updater_chroot.context = self.context
            del updater_chroot.current_mirror
            del updater_chroot.stable_mirror
            generate_sources_list_chroot = updater_chroot.generate_sources_list()
        else:
            generate_sources_list_chroot = self.generate_sources_list()
        # The following initialization only needs to happen on the first
        # run, but it requires the context to be set to the chroot.
        if first_run:
            # Make sure the `lsb_release' program is available. It is
            # my experience that this package cannot be installed using
            # `debootstrap --include=lsb-release', it specifically
            # needs to be installed afterwards.
            self.context.execute('apt-get', 'install', '--yes', 'lsb-release', sudo=True)
            # Cleanup downloaded *.deb archives.
            self.context.execute('apt-get', 'clean', sudo=True)
            # Install a suitable /etc/apt/sources.list file. The logic behind
            # generate_sources_list() depends on the `lsb_release' program.
            logger.debug("sources.list for chroot generated:")
            logger.debug(generate_sources_list_chroot)
            self.install_sources_list(generate_sources_list_chroot)
            # Make sure the package lists are up to date.
            self.smart_update()
        return self.context
def create_chroot ( self , directory , codename = None , arch = None ) : logger . debug ( "Checking if chroot already exists (%s) .." , directory ) if self . context . exists ( directory ) and self . context . list_entries ( directory ) : logger . info ( "The chroot already exists, skipping initialization." ) first_run = False else : # Ensure the `debootstrap' program is installed. if not self . context . find_program ( 'debootstrap' ) : logger . info ( "Installing `debootstrap' program .." ) self . context . execute ( 'apt-get' , 'install' , '--yes' , 'debootstrap' , sudo = True ) # Use the `debootstrap' program to create the chroot. timer = Timer ( ) debootstrap_command = [ 'debootstrap' ] if arch : debootstrap_command . append ( '--arch=%s' % arch ) release_chroot = None keyring_chroot = '' codename_chroot = '' best_mirror_chroot = None generate_sources_list_chroot = None if codename and codename != self . distribution_codename : updater_chroot = AptMirrorUpdater ( ) updater_chroot . distribution_codename = codename if updater_chroot . distributor_id == 'linuxmint' : msg = "It seems no sense to create chroot of Linux Mint, " "please specify a codename of Ubuntu or Debian " "to create chroot." raise ValueError ( msg ) if not self . context . exists ( updater_chroot . release . keyring_file ) : if updater_chroot . distributor_id == 'ubuntu' : self . context . execute ( 'apt-get' , 'install' , '--yes' , 'ubuntu-keyring' , sudo = True ) elif updater_chroot . distributor_id == 'debian' : self . context . execute ( 'apt-get' , 'install' , '--yes' , 'debian-archive-keyring' , sudo = True ) release_chroot = updater_chroot . release keyring_chroot = updater_chroot . release . keyring_file codename_chroot = codename best_mirror_chroot = updater_chroot . best_mirror else : if self . distributor_id == 'linuxmint' : msg = "It seems no sense to create chroot of Linux Mint, " "please use -C to specify a codename of Ubuntu or Debian " "to create chroot." raise ValueError ( msg ) release_chroot = self . release keyring_chroot = self . release . keyring_file codename_chroot = self . distribution_codename best_mirror_chroot = self . best_mirror logger . info ( "Creating %s chroot in %s .." , release_chroot , directory ) debootstrap_command . append ( '--keyring=%s' % keyring_chroot ) debootstrap_command . append ( codename_chroot ) debootstrap_command . append ( directory ) debootstrap_command . append ( best_mirror_chroot ) self . context . execute ( * debootstrap_command , sudo = True ) logger . info ( "Took %s to create %s chroot." , timer , release_chroot ) first_run = True # Switch the execution context to the chroot and reset the locale (to # avoid locale warnings emitted by post-installation scripts run by # `apt-get install'). self . context = ChangeRootContext ( chroot = directory , environment = dict ( LC_ALL = 'C' ) , ) # Clear the values of cached properties that can be # invalidated by switching the execution context. del self . current_mirror del self . stable_mirror if codename and codename != self . distribution_codename : updater_chroot . context = self . context del updater_chroot . current_mirror del updater_chroot . stable_mirror generate_sources_list_chroot = updater_chroot . generate_sources_list ( ) else : generate_sources_list_chroot = self . generate_sources_list ( ) # The following initialization only needs to happen on the first # run, but it requires the context to be set to the chroot. if first_run : # Make sure the `lsb_release' program is available. It is # my experience that this package cannot be installed using # `debootstrap --include=lsb-release', it specifically # needs to be installed afterwards. self . context . execute ( 'apt-get' , 'install' , '--yes' , 'lsb-release' , sudo = True ) # Cleanup downloaded *.deb archives. self . context . execute ( 'apt-get' , 'clean' , sudo = True ) # Install a suitable /etc/apt/sources.list file. The logic behind # generate_sources_list() depends on the `lsb_release' program. logger . debug ( "sources.list for chroot generated:" ) logger . debug ( generate_sources_list_chroot ) self . install_sources_list ( generate_sources_list_chroot ) # Make sure the package lists are up to date. self . smart_update ( ) return self . context