def __aptCreateRootstrap(self, chroot_dir, rootstrap_file, use_rootstrap, callback = None):
     codename = self.buildroot_codename
     components = ",".join(self.buildroot_components)
     mirror = self.buildroot_mirror
     chroot_type_string = "Platform"
     basedir = os.path.dirname(rootstrap_file)
     if not os.path.exists(basedir):
         os.makedirs(basedir)
     if mic_cfg.config.get('general', 'package_manager') == 'apt':
         cmd = "debootstrap --arch %s --include=apt --components=%s %s %s %s" % (self.architecture, components, codename, chroot_dir, mirror)
     elif mic_cfg.config.get('general', 'package_manager') == 'yum':
         cmd = "/usr/sbin/debootstrap --arch %s --include=apt --components=%s %s %s %s" % (self.architecture, components, codename, chroot_dir, mirror)
     output = []
     # XXX Evil hack
     if not os.path.isfile("/usr/lib/debootstrap/scripts/%s" % codename) and not os.path.isfile("/usr/share/debootstrap/scripts/%s" % codename):
         cmd += " " + paths.PKGDATADIR + "/debootstrap-scripts/%s" % codename
     # Sometimes we see network issues that trigger debootstrap to claim the
     # apt repository is corrupt.  This trick will force up to 10 attempts
     # before bailing out with an error
     count = 0
     while count < 10:
         count += 1
         print _("--------%s rootstrap creation try: %s ----------") % (chroot_type_string, count)
         print _("Execing command: %s") % cmd
         result = pdk_utils.execCommand(cmd, output = output, callback = callback)
         if result == 0:
             print _("--------%s rootstrap creation completed successfully----------") % chroot_type_string
             break;
         if result < 0:
             print _("Process Aborted")
             return False
         print _("--------%s rootstrap creation failed result: %s ----------") % (chroot_type_string, result)
         sleeptime = 30
         print _("--------For try: %s.  Sleeping for %s seconds... -----------------") % (count, sleeptime)
         time.sleep(sleeptime)
     if result != 0:
         print >> sys.stderr, _("ERROR: Unable to generate %s rootstrap!") % chroot_type_string
         raise ValueError(" ".join(output))
     self.pkg_manager.cleanPackageCache(chroot_dir)
     source_dir = os.path.join(self.path, 'sources')
     for filename in os.listdir(source_dir):
         source_path = os.path.join(source_dir, filename)
         dest_path = os.path.join(chroot_dir, 'etc', 'apt', 'sources.list.d', filename)
         pdk_utils.copySourcesListFile(source_path, dest_path)
     source_path = os.path.join(self.path, 'preferences')
     if os.path.exists(source_path):
         shutil.copy(source_path, os.path.join(chroot_dir, 'etc', 'apt'))
     if use_rootstrap == True:
         self.__createRootstrap(chroot_dir, rootstrap_file, callback = None)
    def __yumCreateBase(self, chroot_dir):
        for dirname in [
            'dev',
            'dev/pts',
            'etc/yum.repos.d',
            'proc',
            'var/lib/rpm', 
            'var/lib/yum',
            'var/log',
            'sys',
            ]:
            os.makedirs(os.path.join(chroot_dir, dirname))
        target_etc = os.path.join(chroot_dir, "etc")
        # Setup copies of some useful files from the host into the chroot
        for filename in [ 'hosts', 'resolv.conf' ]:
            source_file = os.path.join("/etc", filename)
            target_file = os.path.join(target_etc, filename)
            pdk_utils.safeTextFileCopy(source_file, target_file, force = True)
        yumconf = open(os.path.join(target_etc, 'yum.conf'), 'w')
        print >> yumconf, """\
[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=0
plugins=1
metadata_expire=1800
releasever=8
"""
        yumconf.close()
        yum_repos_dir = os.path.join(self.path, 'yum.repos.d')
        for filename in os.listdir(yum_repos_dir):
            source_path = os.path.join(yum_repos_dir, filename)
            dest_path = os.path.join(chroot_dir, 'etc', 'yum.repos.d', filename)
            pdk_utils.copySourcesListFile(source_path, dest_path)