Exemple #1
0
    def init(env_dir, name, toolset_name=None):
        """
        Initialize the environment in the given directory.
        """

        # Bail out with an error if the environment already exists
        if Environment.env_exists(env_dir):
            raise Exception('Environment already exists in: %s' % env_dir)

        # Create the empty db file (this triggers database file creation)
        pdb = InstallDatabase(env_dir)

        # Make sure we have a valid ld.so symlink
        linux.update_ld_so_symlink(env_dir)

        # Lookup our toolset and translate to dict
        toolset = build.Toolset.lookup_by_name(toolset_name)

        # Create our settings dict and write it disk
        settings = {
            'name' : name,
            'toolset' : toolset.to_dict(),
        }

        # For path to our settings files, and save it
        settings_path = os.path.join(env_dir, Environment.SETTINGS_PATH)

        with open(settings_path, 'w') as f:
            util.yaml_dump(settings, f)
Exemple #2
0
    def init(env_dir, name, toolset_name=None):
        """
        Initialize the environment in the given directory.
        """

        # Bail out with an error if the environment already exists
        if Environment.env_exists(env_dir):
            raise Exception('Environment already exists in: %s' % env_dir)

        # Create the empty db file (this triggers database file creation)
        pdb = InstallDatabase(env_dir)

        # Make sure we have a valid ld.so symlink
        linux.update_ld_so_symlink(env_dir)

        # Lookup our toolset and translate to dict
        toolset = build.Toolset.lookup_by_name(toolset_name)

        # Create our settings dict and write it disk
        settings = {
            'name': name,
            'toolset': toolset.to_dict(),
        }

        # For path to our settings files, and save it
        settings_path = os.path.join(env_dir, Environment.SETTINGS_PATH)

        with open(settings_path, 'w') as f:
            util.yaml_dump(settings, f)
Exemple #3
0
    def _mark_installed(self, name, info):
        """
        Marks the package installed and updates the so link as needed.
        """

        self._pdb.mark_installed(info['name'], info)

        linux.update_ld_so_symlink(self._env_dir)
Exemple #4
0
    def _mark_installed(self, name, info):
        """
        Marks the package installed and updates the so link as needed.
        """

        self._pdb.mark_installed(info['name'], info)

        linux.update_ld_so_symlink(self._env_dir)
Exemple #5
0
    def remove(self, name):
        """
        Removes the given package from the environment.
        """

        # Determine if another package depends on this one
        rdepends = self._pdb.get_rdepends(name)

        if len(rdepends) > 0:
            args = (name, ', '.join(rdepends))
            raise Exception("Can't remove %s required by: %s" % args)

        # Remove all the files from the db
        info = self._pdb.get_info(name)

        if info:
            # First we remove the files
            for f in sorted(info['files']):
                full_path = os.path.join(self._env_dir, f)

                # We use lexists to test for existence here, because we don't
                # want to de-reference symbolic links, we want to know if the
                # link file itself is present.
                if os.path.lexists(full_path):
                    os.remove(full_path)
                else:
                    # TODO: Log a warning here
                    print 'WARNING: package %s file not found: %s' % (
                        name, full_path)

            # Now remove the directories (reverse so we remove the deeper,
            # dirs first)
            # TODO: don't try remove directories that are owned by other
            # packages
            for d in sorted(info['dirs'], reverse=True):
                full_path = os.path.join(self._env_dir, d)

                # We use lexists to test for existence here, because we don't
                # want to de-reference symbolic links, we want to know if the
                # link file itself is present.
                if os.path.lexists(full_path):
                    if len(os.listdir(full_path)) == 0:
                        os.rmdir(full_path)
                    elif self._pdb.dir_references(d) == 1:
                        # Only warn when we are the last package referencing this dir
                        print 'WARNING: not removing dir, has files:', full_path
                else:
                    # TODO: Log a warning here
                    print 'WARNING: package %s directory not found: %s' % (
                        name, full_path)

            # Remove the package from the database
            self._pdb.mark_removed(name)

            # Update the ld.so as needed
            linux.update_ld_so_symlink(self._env_dir)
        else:
            print 'Package %s not installed.' % name
Exemple #6
0
    def remove(self, name):
        """
        Removes the given package from the environment.
        """

        # Determine if another package depends on this one
        rdepends = self._pdb.get_rdepends(name)

        if len(rdepends) > 0:
            args = (name, ', '.join(rdepends))
            raise Exception("Can't remove %s required by: %s" % args)

        # Remove all the files from the db
        info = self._pdb.get_info(name)

        if info:
            # First we remove the files
            for f in sorted(info['files']):
                full_path = os.path.join(self._env_dir, f)

                # We use lexists to test for existence here, because we don't
                # want to de-reference symbolic links, we want to know if the
                # link file itself is present.
                if os.path.lexists(full_path):
                    os.remove(full_path)
                else:
                    # TODO: Log a warning here
                    print 'WARNING: package %s file not found: %s' % (name, full_path)

            # Now remove the directories (reverse so we remove the deeper,
            # dirs first)
            # TODO: don't try remove directories that are owned by other
            # packages
            for d in sorted(info['dirs'], reverse=True):
                full_path = os.path.join(self._env_dir, d)

                # We use lexists to test for existence here, because we don't
                # want to de-reference symbolic links, we want to know if the
                # link file itself is present.
                if os.path.lexists(full_path):
                    if len(os.listdir(full_path)) == 0:
                        os.rmdir(full_path)
                    elif self._pdb.dir_references(d) == 1:
                        # Only warn when we are the last package referencing this dir
                        print 'WARNING: not removing dir, has files:',full_path
                else:
                    # TODO: Log a warning here
                    print 'WARNING: package %s directory not found: %s' % (name, full_path)

            # Remove the package from the database
            self._pdb.mark_removed(name)

            # Update the ld.so as needed
            linux.update_ld_so_symlink(self._env_dir)
        else:
            print 'Package %s not installed.' % name
Exemple #7
0
    def build(self, target_dir, environment = None, output_to_file=True):
        """
        Right now this just executes instructions inside the XPD, but in the
        future we can make this a little smarter.

        It returns the info structure for the created package.  See the XPA
        class for the structure of the data returned.
        """

        # Create our temporary directory
        self._work_dir = tempfile.mkdtemp(suffix = '-xpkg-' + self._xpd.name)

        # TODO: LOG THIS
        print 'Working in:',self._work_dir

        # Create our output
        if output_to_file:
            # Form a hopefully unique name for the output file
            args = (self._xpd.name, self._xpd.version)
            output_file = '%s-%s_build.log' % args

            # Put the file in our environment if we have, or the current
            # directory
            if environment:
                # Find out log dir
                log_dir = environment.log_dir(environment.root)

                # Make sure it exists
                util.ensure_dir(log_dir)

                # Now finally commit to our path
                output_path = os.path.join(log_dir, output_file)
            else:
                output_path = os.path.abspath(os.path.join('.', output_file))

            # TODO: LOG THIS
            print 'Log file:',output_path

            # Open our file for writing
            self._output = open(output_path, 'w')
        else:
            self._output = None

        # Store our target dir
        self._target_dir = target_dir
        util.ensure_dir(self._target_dir)

        # Determine our environment directory
        if environment:
            self._env_dir = environment._env_dir
        else:
            self._env_dir = ''

        # Setup the ld.so symlink in the target dir pointing to either
        # the system ld.so, or the current environments
        ld_target_dir = self._target_dir
        update_root = self._env_dir if len(self._env_dir) else self._target_dir

        linux.update_ld_so_symlink(update_root, ld_target_dir)

        try:
            # Store the current environment
            env_vars = util.EnvStorage(store = True)

            # If we have an environment apply it's variables so the build can
            # reference the libraries installed in it
            if environment:
                environment.apply_env_variables()

            # Fetches and unpacks all the required sources for the package
            self._get_sources()

            # Determine what directory we have to do the build in
            dirs = [d for d in os.listdir(self._work_dir) if
                    os.path.isdir(os.path.join(self._work_dir, d))]

            if 'build-dir' in self._xpd._data:
                # If the user specifies a build directory use it
                rel_build_dir = self._xpd._data['build-dir']
                build_dir = os.path.join(self._work_dir, rel_build_dir)

                # Make sure the directory exists
                util.ensure_dir(build_dir)
            elif len(dirs) == 1:
                build_dir = os.path.join(self._work_dir, dirs[0])
            else:
                build_dir = self._work_dir

            with util.cd(build_dir):
                # Standard build configure install
                self._configure()

                self._build()

                new_paths = self._install()
        finally:
            # Put back our environment
            env_vars.restore()

            self._env_dir = ''

            # Close our output file if it exists
            if self._output:
                self._output.close()
                self._output = None

            # Make sure we cleanup after we are done
            shutil.rmtree(self._work_dir)


        return self._create_info(new_paths)