Skip to content

Commit

Permalink
Extend export_subtree_bundle: Allow to export only specific branches
Browse files Browse the repository at this point in the history
  • Loading branch information
elioschmutz committed Dec 20, 2024
1 parent 1feb446 commit 4d2a206
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions opengever/maintenance/scripts/export_subtree_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
(--with-local-roles | --without-local-roles)
(--dossiers-with-parent-reference | --dossiers-with-parent-guid)
<path>
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
Expand Down Expand Up @@ -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':
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4d2a206

Please sign in to comment.