Esempio n. 1
0
    def _get_multi_packages(self):
        """
        Get the package info for each sub package, sorted in a order such that
        you don't need to install different ones.
        """

        # Get all the internal packages
        packages = self._data['packages']
        pkg_names = set(packages.keys())

        # Build a graph of the dependencies amongst the packages in this XPD
        dep_graph = {}
        for name, data in self._data['packages'].iteritems():
            if data:
                for dep in data.get('dependencies', []):
                    if dep in pkg_names:
                        dep_graph.setdefault(name, []).append(dep)
            else:
                dep_graph[name] = []

        # Topologically sort them so we start with the package that has no
        # dependencies
        sorted_names = sorted(util.topological_sort(dep_graph))

        # Produce the package data in sorted form
        results = []
        for pkg_name in sorted_names:
            pkg_data = packages.get(pkg_name)
            if pkg_data is None:
                pkg_data = {}

            # Lookup the version and dependencies, for this package, but fall
            # back full package version
            results.append({
                'name':
                pkg_name,
                'version':
                pkg_data.get('version', self.version),
                'description':
                pkg_data.get('description', self.description),
                'dirs':
                pkg_data.get('dirs', []),
                'files':
                pkg_data.get('files', []),
                'dependencies':
                pkg_data.get('dependencies', self.dependencies),
            })

        return results
Esempio n. 2
0
    def test_topological_sort(self):
        """
        Test basic topological sort
        """

        # Basic dependency graph
        graph = {
            'libmulti' : [],
            'libmulti-dev' : ['libmulti'],
            'multi-tools' : ['libmulti'],
        }

        actual = sorted(util.topological_sort(graph))
        expected = ['libmulti', 'libmulti-dev', 'multi-tools']
        self.assertEqual(expected, actual)
Esempio n. 3
0
File: core.py Progetto: jlisee/xpkg
    def _get_multi_packages(self):
        """
        Get the package info for each sub package, sorted in a order such that
        you don't need to install different ones.
        """

        # Get all the internal packages
        packages = self._data['packages']
        pkg_names = set(packages.keys())

        # Build a graph of the dependencies amongst the packages in this XPD
        dep_graph = {}
        for name, data in self._data['packages'].iteritems():
            if data:
                for dep in data.get('dependencies', []):
                    if dep in pkg_names:
                        dep_graph.setdefault(name, []).append(dep)
            else:
                dep_graph[name] = []

        # Topologically sort them so we start with the package that has no
        # dependencies
        sorted_names = sorted(util.topological_sort(dep_graph))

        # Produce the package data in sorted form
        results = []
        for pkg_name in sorted_names:
            pkg_data = packages.get(pkg_name)
            if pkg_data is None:
                pkg_data = {}

            # Lookup the version and dependencies, for this package, but fall
            # back full package version
            results.append({
                'name' : pkg_name,
                'version' : pkg_data.get('version', self.version),
                'description' : pkg_data.get('description', self.description),
                'dirs' : pkg_data.get('dirs', []),
                'files' : pkg_data.get('files', []),
                'dependencies' : pkg_data.get('dependencies', self.dependencies),
            })

        return results