diff --git a/opengever/maintenance/scripts/export_subtree_bundle.py b/opengever/maintenance/scripts/export_subtree_bundle.py index 5af793d..ba3fb04 100644 --- a/opengever/maintenance/scripts/export_subtree_bundle.py +++ b/opengever/maintenance/scripts/export_subtree_bundle.py @@ -6,6 +6,20 @@ (--with-local-roles | --without-local-roles) (--dossiers-with-parent-reference | --dossiers-with-parent-guid) + +Export specific objects along with all their parent and child objects. + +Example: +To export two specific objects and include their parent and child objects, +use the following command: + + export_subtree_bundle.py + --branch /fd/ordnungssystem/fuehrung/kommunikation/allgemeines + --branch /fd/ordnungssystem/allgemeines/dossier-1 + fd/ordnungssystem + +This command exports the specified objects, along with all related parent and +child objects in the hierarchy. """ from Acquisition import aq_inner @@ -441,6 +455,13 @@ def serialize_node(self, node, serialized_nodes_by_type, parent_guid=None): self.serialize_node(child, serialized_nodes_by_type, parent_guid=parent_guid) def should_skip_child(self, child): + # Don't export non-whitelisted subtrees + if self.options.branches: + path = '/'.join(child.getPhysicalPath()) + if not self.is_parent_or_child_of(path, self.options.branches): + self.skipped_data['Skipped due to subtree filter'].append(path) + return True + # Don't export inactive dossiers review_state = api.content.get_state(child) if review_state == 'dossier-state-inactive': @@ -457,6 +478,20 @@ def should_skip_child(self, child): return False + def is_parent_or_child_of(self, context_path, paths): + context_path = context_path.strip('/') + '/' + for path in paths: + path = path.strip('/') + '/' + + # context is child of path or is path + if context_path in path: + return True + + # context is a parent of path + if path in context_path: + return True + return False + def serialize_review_state(self, obj): if obj.portal_type == 'ftw.mail.mail': # The WF state 'mail-state-active' is not currently allowed per the @@ -613,6 +648,14 @@ def iso_datestr(self, value): help="Reference dossier's repofolder parent via bundle GUID", ) + parser.add_argument( + '--branch', + action='append', + dest='branches', + help='Path of an object whos parents and children should be exported. ' + 'All other objects will be skipped.' + ) + options = parser.parse_args(sys.argv[3:]) transaction.doom()