From 831f649242857209852d4b8f06864780003be3d0 Mon Sep 17 00:00:00 2001 From: Jeffery Antoniuk Date: Fri, 31 May 2024 16:54:01 -0600 Subject: [PATCH] Feature: add ability to force preservation of a single item * address --- rootfs/var/www/leaf-isle-bagger/drupal/api.py | 9 +++++ .../www/leaf-isle-bagger/drupal/utilities.py | 9 +++++ .../var/www/leaf-isle-bagger/leaf-bagger.py | 34 +++++++++++++------ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/rootfs/var/www/leaf-isle-bagger/drupal/api.py b/rootfs/var/www/leaf-isle-bagger/drupal/api.py index 345c759..51da6c7 100644 --- a/rootfs/var/www/leaf-isle-bagger/drupal/api.py +++ b/rootfs/var/www/leaf-isle-bagger/drupal/api.py @@ -56,3 +56,12 @@ def get_media_list(session, server, page=0, date_filter=""): ) response.raise_for_status() return response + + +# +def get_node_by_format(session, server, item_id): + response = session.get( + urljoin(server, f"node/{item_id}?_format=json"), + ) + response.raise_for_status() + return response diff --git a/rootfs/var/www/leaf-isle-bagger/drupal/utilities.py b/rootfs/var/www/leaf-isle-bagger/drupal/utilities.py index 041b0ca..4377542 100644 --- a/rootfs/var/www/leaf-isle-bagger/drupal/utilities.py +++ b/rootfs/var/www/leaf-isle-bagger/drupal/utilities.py @@ -51,6 +51,15 @@ def id_list_from_nodes(session, args): return node_list +# build list of ids from Drupal Nodes +def id_list_from_arg(session, args): + node_list = {} + node = drupalApi.get_node_by_format(session, args.server, args.force_single_node) + node = json.loads(node.content) + add_to_node_list(node_list, node["nid"][0]["value"], node["changed"][0]["value"]) + return node_list + + # query media as media changes are not reflected as node revisions # exclude Drupal Media not attached to a Drupal Node def id_list_merge_with_media(session, args, node_list): diff --git a/rootfs/var/www/leaf-isle-bagger/leaf-bagger.py b/rootfs/var/www/leaf-isle-bagger/leaf-bagger.py index f5447aa..a1e7532 100644 --- a/rootfs/var/www/leaf-isle-bagger/leaf-bagger.py +++ b/rootfs/var/www/leaf-isle-bagger/leaf-bagger.py @@ -2,7 +2,11 @@ # desc: connect to a Drupal instance, get a list of Drupal Nodes and Media that have changed # since a supplied date and return a list of Drupal Nodes (e.g., to preserve in an # AIP - archival information package) -# usage: python3 get_node_id.py --server ${server_name} --output ${output_path} --date '2024-05-16T16:51:52' +# usage: python3 leaf-bagger.py \ +# --server ${server_name} \ +# --output ${output_path} \ +# --date '2024-05-16T16:51:52' \ +# --container 'test' \ # license: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication # date: May 15, 2024 ############################################################################################## @@ -55,6 +59,12 @@ def parse_args(): help="Path to the Archival Information Packages (AIPs/BAGs).", default=f"{os.getenv('BAGGER_OUTPUT_DIR')}", ) + parser.add_argument( + "--force_single_node", + required=False, + help="Override node selection and process only the specified item.", + default="", + ) return parser.parse_args() @@ -64,15 +74,19 @@ def process(args, session): # a list of resources to preserve node_list = {} - # get a list of Drupal Node IDs changed since a given optional date - node_list = drupalUtilities.id_list_from_nodes(session, args) - logging.info(f"Drupal nodes - {node_list}") - - # inspect Drupal Media for changes - # a Media change is does not transitively change the associated Node change timestamp) - # if Media changed then add associated Node ID to the list - drupalUtilities.id_list_merge_with_media(session, args, node_list) - logging.info(f"Drupal nodes with media changes - {node_list}") + if args.force_single_node: + node_list = drupalUtilities.id_list_from_arg(session, args) + logging.info(node_list) + else: + # get a list of Drupal Node IDs changed since a given optional date + # or a single node then force update + node_list = drupalUtilities.id_list_from_nodes(session, args) + logging.info(node_list) + # inspect Drupal Media for changes + # a Media change is does not transitively change the associated Node change timestamp) + # if Media changed then add associated Node ID to the list + drupalUtilities.id_list_merge_with_media(session, args, node_list) + logging.info(f"Drupal nodes with media changes - {node_list}") # create archival information packages logging.info("Create AIPs")