Skip to content

Commit

Permalink
Merge pull request #9 from cwrc/8_single_item
Browse files Browse the repository at this point in the history
Feature: add ability to force preservation of a single item
  • Loading branch information
jefferya authored May 31, 2024
2 parents 8c7dc2e + 831f649 commit ca7bba6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
9 changes: 9 additions & 0 deletions rootfs/var/www/leaf-isle-bagger/drupal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions rootfs/var/www/leaf-isle-bagger/drupal/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
34 changes: 24 additions & 10 deletions rootfs/var/www/leaf-isle-bagger/leaf-bagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
##############################################################################################
Expand Down Expand Up @@ -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()


Expand All @@ -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")
Expand Down

0 comments on commit ca7bba6

Please sign in to comment.