Example #1
0
    def normalize_path(self, path):
        """Construct a canonical representation of a Store path.

        A canonical Store path is very simple: it is either the root (/),
        a bundle (/name), a package (/name), or a class in a package (/package/class).
        Any other extensions are reducible to this by the simple mechanism of cutting
        off any prefixing bits.
        """

        if path == None or path == "/":
            # Root
            return "/"

        parts = path.split("/")
        if parts[0] == "":
            parts[0:1] = []
        last = parts[-1]

        if PackageNode.with_name(self, last) != None or PackageNode.with_name(self, last) != None:
            # Bundle/Package or Bundle/Bundle ... all but the last element are unnecessary.
            return "/" + last
        else:
            # Package/Class ... normalize Class by stripping any Root.Smalltalk prefix.
            if last.startswith("Root.Smalltalk."):
                last = last[len("Root.Smalltalk.") :]
            if len(parts) >= 2:
                return "/" + parts[-2] + "/" + last
            else:
                return "/" + last
Example #2
0
    def get_node(self, path, rev=None):
        """Return a StoreNode subclass appropriate to handle the resource at path and rev."""

        # Case 1: Root
        if not path or path == "/":
            return self.root

        parts = path.split("/")
        if parts[0] == "":
            parts = parts[1:]

        # Workaround to deal with us wanting to use None revisions
        # in places where unicode() is used
        if rev == "None":
            rev = None

        if len(parts) == 1:
            # Case 2: /BundleName
            bundle = BundleNode.with_name(self, parts[0], rev)
            if bundle != None:
                return bundle

            # Case 3: /PackageName
            package = PackageNode.with_name(self, parts[0], rev)
            if package != None:
                return package
        else:
            # Case 4: /PackageName/Fully.Qualified.ClassName
            package = PackageNode.with_name(self, parts[-2], rev)
            if package != None:
                subnode = package.subnode_named(parts[-1])
                if subnode != None:
                    return subnode
        raise NoSuchNode(path, rev)
Example #3
0
    def get_entries(self):
        """Generator method for the PackageNodes and/or BundleNodes contained
        within this view of the repository.
        """

        for bundle_name in self.bundle_names:
            if bundle_name == 'ALL':
                for bnode in BundleNode.all(self.repos):
                    yield bnode
            elif bundle_name != None:
                yield BundleNode.with_name(self.repos, bundle_name)
        
        for package_prefix in self.package_prefixes:
            if package_prefix == 'ALL':
                for pkg in PackageNode.all(self.repos):
                    yield pkg
            elif package_prefix != None:
                for pkg in PackageNode.named_like(self.repos, package_prefix + '%'):
                    yield pkg
Example #4
0
    def get_entries(self):
        """Generator method that produces the PackageNodes and BundleNodes contained in this bundle."""
        
        # Start by looking for any sub-bundles.  Don't bother ordering them because
        # Trac will scrap the order anyway.
        for row in self.repos.sql("SELECT subbundleref FROM tw_bundles WHERE bundleref = %i" % self.id):
            yield BundleNode.with_id(self.repos, row[0])

        # Look for sub-packages next.
        for row in self.repos.sql("SELECT packageref FROM tw_packages WHERE bundleref = %i" % self.id):
            yield PackageNode.with_id(self.repos, row[0])