コード例 #1
0
 def aptCreateChroot(self, chroot_dir, use_rootstrap, callback = None):
     """Create chroot in chroot_dir for using APT tools"""
     if not os.path.exists(chroot_dir):
         os.makedirs(chroot_dir)
     target_os = self.target_os
     var_dir = mic_cfg.config.get('general', 'var_dir')
     rootstrap_file = os.path.join(var_dir, "rootstraps", "apt", target_os, self.name, "rootstrap.tgz")
     if not os.path.exists(rootstrap_file):
         if self.__aptCreateRootstrap(chroot_dir, rootstrap_file, use_rootstrap, callback = callback) == False:
             return False
     else:
         cmd = "tar -jxvf %s -C %s" % (rootstrap_file, chroot_dir)
         output = []
         result = pdk_utils.execCommand(cmd, output = output, callback = callback)
         if result != 0:
             print >> sys.stderr, _("ERROR: Unable to rootstrap %s from %s!") % (rootstrap_file, self.name)
             pdk_utils.rmtree(chroot_dir, callback = callback)
             # FIXME: Better exception here
             raise ValueError(" ".join(output))
     # 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(chroot_dir, 'etc', filename)
         pdk_utils.safeTextFileCopy(source_file, target_file, force = True)
     return True
コード例 #2
0
    def setHostname(self, hostname):
        self.mount()
        # Setup copies of some useful files from the host into the chroot
        for filename in ('etc/resolv.conf'),:
            source_file = os.path.join(os.sep, filename)
            target_file = os.path.join(self.chroot_path, filename)
            pdk_utils.safeTextFileCopy(source_file, target_file)
        f = open("%s/etc/hostname" % self.path, 'w')
        f.write("%s\n" % hostname)
        f.close()
        f = open("%s/etc/default/locale" % self.path, 'w')
        f.write("LANG=en_US.UTF8\n")
        f.close()
        f = open("%s/etc/hosts" % self.path, 'w')
        f.write("""# Generated by Moblin Image Creator #
127.0.0.1       localhost localhost.localdomain %s

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

""" % hostname)
        f.close()
コード例 #3
0
    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)