コード例 #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
ファイル: SDK.py プロジェクト: juanje/moblin-image-creator
 def delete_project(self, project_name):
     # first delete all contained targets
     proj = self.projects[project_name]
     for target in proj.targets:
         self.progress_callback(None)
         proj.delete_target(target, False, callback = self.progress_callback)
     proj.targets.clear()
     # and then deal with the project
     directory_set = proj.umount()
     if directory_set:
         raise pdk_utils.ImageCreatorUmountError, directory_set
     pdk_utils.rmtree(proj.path, callback = self.progress_callback)
     os.unlink(proj.config_info.filename)
コード例 #3
0
ファイル: SDK.py プロジェクト: juanje/moblin-image-creator
    def create_project(self, parent_path, name, desc, platform, use_rootstrap = True):
        """
        Create a new project by specifying an install path, a name, a
        short description, and a platform object.

        Example:

        # By 'creating' a project, the class will:
        #   - create a new directory (i.e. path)
        #   - create the initial directory structure
        #   - setup the project configuration files both inside the project
        #     directory, and also 'create the project config' in
        #     /usr/share/pdk/projects/

        proj = SDK().create_project(self, '~/projects/myproject',
                                    'My Project',
                                    'This is a test, only a test', 'donley')

        # after creating the project, you still need to install the platform
        # specific packages to enable the project to be used as a jailroot
        proj.install()
        """
        if not parent_path or not name or not desc or not platform:
            raise ValueError(_("Empty argument passed in"))
        if name in self.projects:
            raise ValueError(_("Project: %s already exists") % name)
        install_path = os.path.realpath(os.path.abspath(os.path.expanduser(parent_path)))
        self.status_label_callback(_("Creating the project chroot environment"))
        if platform.createChroot(install_path, use_rootstrap, callback = self.progress_callback) == False:
            pdk_utils.rmtree(install_path, callback = self.progress_callback)
            raise ValueError(_("Rootstrap Creating cancelled"))
        # create the config file
        self.status_label_callback(_("Creating Config file"))
        config_path = os.path.join(self.config_path, "%s.proj" % name)
        config_file = open(config_path, 'w')
        config_file.write("NAME=%s\n" % (name))
        config_file.write("PATH=%s\n" % (install_path))
        config_file.write("DESC=%s\n" % (desc))
        config_file.write("PLATFORM=%s\n" % (platform.name))
        config_file.close()
        # instantiate the project
        self.status_label_callback(_("Initiating the project"))
        config = PackageConfig(config_path)
        try:
            self.projects[name] = Project.Project(config, platform, self.progress_callback)
        except:
            pdk_utils.rmtree(install_path, callback = self.progress_callback)
            os.unlink(config_path)
            raise ValueError("%s" % (sys.exc_value))
        self.projects[name].mount()
        return self.projects[name]
コード例 #4
0
ファイル: SDK.py プロジェクト: juanje/moblin-image-creator
 def clear_rootstraps(self):
     print _("Deleting rootstraps...")
     for key in self.platforms.iterkeys():
         path = self.platforms[key].path
         for prefix in [ "build", "target" ]:
             root_strap_path = os.path.join(path, "%s-rootstrap.tar.bz2" % prefix)
             if os.path.exists(root_strap_path):
                 print _("Deleting: %s") % root_strap_path
                 os.unlink(root_strap_path)
     var_dir = mic_cfg.config.get('general', 'var_dir')
     rootstrap_dir = os.path.join(var_dir, "rootstraps")
     if os.path.exists(rootstrap_dir):
         print _("Deleting rootstrap directory: %s") % rootstrap_dir
         pdk_utils.rmtree(rootstrap_dir, callback = self.progress_callback)
コード例 #5
0
ファイル: SDK.py プロジェクト: juanje/moblin-image-creator
 def load_project(self, project_name, project_path, filename, progressCallback = None):
     """Load the specified filename as project_name and store it in
     project_path"""
     tar_filename = filename
     if not filename.endswith(".mic.tar.bz2"):
         raise ValueError(_("Specified project restore file: %s, does not end in .mic.tar.bz2"))
     config_file = os.path.join(self.config_path, "%s.proj" % project_name)
     if os.path.exists(config_file):
         raise ValueError(_("A project already exists with that name: %s") % config_file)
     if project_path.find(' ') != -1:
         raise ValueError(_("Specified project path contains a space character, not allowed: %s") % project_path)
     if os.path.exists(project_path):
         if os.path.isdir(project_path):
             if len(os.listdir(project_path)):
                 raise ValueError(_("Specified project-path, is a directory, but it is NOT empty: %s") % project_path)
             else:
                 os.rmdir(project_path)
         else:
             raise ValueError(_("Specified project-path, exists, but it is not a directory"))
     tempdir = tempfile.mkdtemp()
     cwd = os.getcwd()
     os.chdir(tempdir)
     print _("Extracting: %s to temporary directory: %s/") % (filename, tempdir)
     time.sleep(2)
     if self.isVerboseProjectTar():
         tar_options = "xfjv"
     else:
         tar_options = "xfj"
     pdk_utils.execCommand("tar %s %s --numeric-owner" % (tar_options, filename), callback = progressCallback)
     os.chdir(cwd)
     source_config_file = os.path.join(tempdir, "config", "save.proj")
     if not os.path.isfile(source_config_file):
         raise ValueError(_("Project config file did not exist in project tarfile.  Could not find: %s") % source_config_file)
     source_project = os.path.join(tempdir, "project")
     if not os.path.isdir(source_project):
         raise ValueError(_("Project directory did not exist in project tarfile.  Could not find: %s") % source_project)
     print _("Writing new config file: %s") % config_file
     self.copyProjectConfigFile(source_config_file, config_file, project_name, project_path)
     print _("Moving project directory into place at: %s") % project_path
     cmd_line = "mv -v %s %s" % (source_project, project_path)
     print cmd_line
     result = pdk_utils.execCommand(cmd_line)
     if result:
         print _("Error doing 'mv' cmd")
         sys.exit(1)
     print _("Removing temporary directory: %s") % tempdir
     pdk_utils.rmtree(tempdir, callback = self.progress_callback)
     print _("Project: %s restored to: %s") % (project_name, project_path)
コード例 #6
0
 def create_initramfs(self, initrd_file, kernel_version):
     print _("Creating initramfs for kernel version: %s") % kernel_version
     # copy the platform initramfs stuff into /etc/initramfs-tools/ in the target
     src_path = os.path.join(paths.PKGDATADIR + '/platforms', self.project.platform.name, 'initramfs')
     dst_path = os.path.join(self.target.fs_path, 'etc', 'initramfs-tools', )
     pdk_utils.rmtree(dst_path, True, callback = self.progress_callback)
     shutil.copytree(src_path, dst_path, True)
     # Create our config file that is used by our scripts during the running
     # of initramfs.  The initramfs/hooks/mobile script in each platform
     # takes care of putting this file into place into the initramfs image.
     cfg_filename = os.path.join(dst_path, "moblin-initramfs.cfg")
     self.writeShellConfigFile(cfg_filename)
     print _("moblin-initramfs.cfg file created")
     kernel_mod_path = os.path.join('/lib/modules', kernel_version)
     cmd = "mkinitramfs -o %s %s" % (initrd_file , kernel_mod_path)
     print _("Executing: %s") % cmd
     self.target.chroot(cmd)
コード例 #7
0
 def yumCreateChroot(self, chroot_dir, use_rootstrap, callback = None):
     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", "yum", target_os, self.name, "rootstrap.tgz")
     if not os.path.exists(rootstrap_file):
         self.__yumCreateRootstrap(chroot_dir, rootstrap_file, use_rootstrap, callback = callback)
     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, name)
             pdk_utils.rmtree(chroot_dir, callback = callback)
             # FIXME: Better exception here
             raise ValueError(" ".join(output))
コード例 #8
0
 def delete_target(self, name, do_pop=True, callback = None):
     target = self.targets[name]
     self.umountTarget(target)
     seen_paths = []
     while True:
         try:
             pdk_utils.rmtree(os.path.join(self.path, 'targets', name), callback = callback)
             break
         except OSError, e:
             # See if we get a resource busy error, if so we think it is a
             # mounted filesystem issue
             if e.errno == errno.EBUSY:
                 if e.filename in seen_paths:
                     raise OSError, e
                 else:
                     seen_paths.append(e.filename)
                     pdk_utils.umount(e.filename)
             else:
                 raise OSError, e