Esempio n. 1
0
    def dump(
        self,
        resource,
        directory,
        subresources=True,
        verbose=False,
        dry_run=False,
        registry=None
        ):
        """ Dump a resource to ``directory``. The resource will be represented
        by at least one properties file and other subdirectories.
        Sub-resources will dumped as subdirectories if ``subresources`` is
        True."""

        if registry is None:
            registry = get_current_registry()

        self.set_yaml(registry)

        dumpers = self.get_dumpers(registry)

        stack = [(self.ospath.abspath(self.ospath.normpath(directory)),
                  resource)]
        first = None

        while stack: # breadth-first is easiest

            directory, resource = stack.pop()

            if first is None:
                first = resource

            context = self._make_dump_context(
                directory,
                registry,
                dumpers,
                verbose,
                dry_run
                )

            logger.info('Dumping %s' % resource_path(resource))
            context.dump(resource)

            if not subresources:
                break

            if is_folder(resource):
                for subresource in resource.values():
                    subdirectory = self.ospath.join(
                        directory,
                        RESOURCES_DIRNAME,
                        subresource.__name__
                        )
                    stack.append((subdirectory, subresource))

        callbacks = registry.pop('dumper_callbacks', ())

        for callback in callbacks:
            callback(first)
Esempio n. 2
0
    def dump(self,
             resource,
             directory,
             subresources=True,
             verbose=False,
             dry_run=False,
             registry=None):
        """ Dump a resource to ``directory``. The resource will be represented
        by at least one properties file and other subdirectories.
        Sub-resources will dumped as subdirectories if ``subresources`` is
        True."""

        if registry is None:
            registry = get_current_registry()

        self.set_yaml(registry)

        dumpers = self.get_dumpers(registry)

        stack = [(self.ospath.abspath(self.ospath.normpath(directory)),
                  resource)]
        first = None

        while stack:  # breadth-first is easiest

            directory, resource = stack.pop()

            if first is None:
                first = resource

            context = self._make_dump_context(directory, registry, dumpers,
                                              verbose, dry_run)

            logger.info('Dumping %s' % resource_path(resource))
            context.dump(resource)

            if not subresources:
                break

            if is_folder(resource):
                for subresource in resource.values():
                    subdirectory = self.ospath.join(directory,
                                                    RESOURCES_DIRNAME,
                                                    subresource.__name__)
                    stack.append((subdirectory, subresource))

        callbacks = registry.pop('dumper_callbacks', ())

        for callback in callbacks:
            callback(first)
Esempio n. 3
0
def evolve(root):
    logger.info(
        'Running substanced evolve step 8: add explicit oid ordering to folders'
    )
    for obj in postorder(root):
        if is_folder(obj):
            order = getattr(obj, '_order', None)
            if order is not None:
                oid_order = ()
                name_order = ()
                if order:
                    if isinstance(order[0], string_types):
                        # handle master branch
                        name_order = obj._order
                        oid_order = []
                        for name in name_order:
                            oid_order.append(get_oid(obj.data[name]))
                    else:
                        # handle ree-ordering-clientside-foo-bar-baz branch
                        name_order = [x[0] for x in order]
                        oid_order = [x[1] for x in order]
                obj._order = tuple(name_order)
                obj._order_oids = tuple(oid_order)
Esempio n. 4
0
def evolve(root):
    logger.info(
        'Running substanced evolve step 8: add explicit oid ordering to folders'
        )
    for obj in postorder(root):
        if is_folder(obj):
            order = getattr(obj, '_order', None)
            if order is not None:
                oid_order = ()
                name_order = ()
                if order:
                    if isinstance(order[0], string_types):
                        # handle master branch
                        name_order = obj._order
                        oid_order = []
                        for name in name_order:
                            oid_order.append(get_oid(obj.data[name]))
                    else:
                        # handle ree-ordering-clientside-foo-bar-baz branch
                        name_order = [x[0] for x in order]
                        oid_order = [x[1] for x in order]
                obj._order = tuple(name_order)
                obj._order_oids = tuple(oid_order)
Esempio n. 5
0
 def dump(self, context):
     resource = context.resource
     if is_folder(resource) and resource.is_ordered():
         context.dump_yaml(resource.order, self.fn)
Esempio n. 6
0
 def visit(node):
     if is_folder(node):
         for child in node.data.values():
             for result in visit(child):
                 yield result
     yield node
Esempio n. 7
0
 def dump(self, context):
     resource = context.resource
     if is_folder(resource) and resource.is_ordered():
         context.dump_yaml(resource.order, self.fn)
Esempio n. 8
0
 def visit(node):
     if is_folder(node):
         for child in node.data.values():
             for result in visit(child):
                 yield result
     yield node