From 73b94498e9b41a50496863d2c8bcd461b122eb68 Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Tue, 3 Feb 2026 16:37:02 -0500 Subject: [PATCH 1/7] Added a script to update beamline --- scripts/update_beamline.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/update_beamline.py diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py new file mode 100644 index 00000000..e81a7c42 --- /dev/null +++ b/scripts/update_beamline.py @@ -0,0 +1,45 @@ +import asyncio + +from nsls2api.infrastructure import mongodb_setup +from nsls2api.infrastructure.config import get_settings +from nsls2api.models.beamlines import Beamline, ServiceAccounts +from nsls2api.services import pass_service + +settings = get_settings() + +# CHANGE THIS TO THE BEAMLINE YOU WANT TO CREATE +BEAMLINE_NAME = "CDI" + + +async def main(): + # Initialize Beanie + await mongodb_setup.init_connection(settings.mongodb_dsn) + + pass_resources = await pass_service.get_pass_resources() + pass_ids = [r["ID"] for r in pass_resources if r["Code"] == BEAMLINE_NAME] + + if not pass_ids: + raise KeyError(f"No pass ID was found for {BEAMLINE_NAME}") + + if len(pass_ids) > 1: + raise ValueError(f"Multiple pass IDs found for {BEAMLINE_NAME}: {pass_ids}") + + beamline = await Beamline.find_one(Beamline.pass_id == str(pass_ids[0])) + if not beamline: + raise KeyError(f"No beamline found with pass_id {pass_ids[0]}") + + # Change only the values that need to be changed. + beamline.service_accounts = ServiceAccounts( + ioc="softioc-cdi", + epics_services="epics-services-cdi", + workflow="workflow-cdi", + bluesky="bluesky-cdi", + operator="xf09id1", + lsdc=None + ) + + await beamline.save() + print("Updated service_accounts for beamline:", beamline.name) + +if __name__ == "__main__": + asyncio.run(main()) From 43931c43e50d5282fb197b4be58dd8667a91bba7 Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Tue, 3 Feb 2026 22:55:20 -0500 Subject: [PATCH 2/7] Review comments addressed. --- scripts/update_beamline.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index e81a7c42..abaf3c8b 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -1,4 +1,5 @@ import asyncio +import datetime from nsls2api.infrastructure import mongodb_setup from nsls2api.infrastructure.config import get_settings @@ -7,7 +8,7 @@ settings = get_settings() -# CHANGE THIS TO THE BEAMLINE YOU WANT TO CREATE +# CHANGE THIS TO THE BEAMLINE YOU WANT TO UPDATE BEAMLINE_NAME = "CDI" @@ -28,7 +29,7 @@ async def main(): if not beamline: raise KeyError(f"No beamline found with pass_id {pass_ids[0]}") - # Change only the values that need to be changed. + # CHANGE THESE VALUES TO SUIT YOUR NEEDS. beamline.service_accounts = ServiceAccounts( ioc="softioc-cdi", epics_services="epics-services-cdi", @@ -38,8 +39,13 @@ async def main(): lsdc=None ) - await beamline.save() - print("Updated service_accounts for beamline:", beamline.name) + print("Will update service_accounts for beamline:", beamline.name) + print(beamline) + + beamline.last_updated = datetime.datetime.now() + + # Uncomment this line to actually save the changes to the database + await beamline.save() if __name__ == "__main__": asyncio.run(main()) From 47605332441304e586f9022c5bf4e97f85ecda9f Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Wed, 4 Feb 2026 15:50:28 -0500 Subject: [PATCH 3/7] Removed hardcoded values from the script --- scripts/update_beamline.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index abaf3c8b..72e04207 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -9,7 +9,7 @@ settings = get_settings() # CHANGE THIS TO THE BEAMLINE YOU WANT TO UPDATE -BEAMLINE_NAME = "CDI" +BEAMLINE_NAME = "TLA" async def main(): @@ -27,25 +27,30 @@ async def main(): beamline = await Beamline.find_one(Beamline.pass_id == str(pass_ids[0])) if not beamline: - raise KeyError(f"No beamline found with pass_id {pass_ids[0]}") + raise KeyError(f"No beamline found with pass_id {pass_ids[0]}") + + print(beamline) # CHANGE THESE VALUES TO SUIT YOUR NEEDS. beamline.service_accounts = ServiceAccounts( - ioc="softioc-cdi", - epics_services="epics-services-cdi", - workflow="workflow-cdi", - bluesky="bluesky-cdi", + ioc="softioc-tla", + epics_services="epics-services-tla", + workflow="workflow-tla", + bluesky="bluesky-tla", operator="xf09id1", lsdc=None ) print("Will update service_accounts for beamline:", beamline.name) - print(beamline) beamline.last_updated = datetime.datetime.now() + print(datetime.datetime.now()) # Uncomment this line to actually save the changes to the database - await beamline.save() + # await beamline.save() + + print("Updated beamline") + print(beamline) if __name__ == "__main__": asyncio.run(main()) From ddb0d90efba821863ef6a5381811faf3961eaa4f Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Wed, 4 Feb 2026 15:56:27 -0500 Subject: [PATCH 4/7] Grammar improvement --- scripts/update_beamline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index 72e04207..c7158591 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -46,7 +46,7 @@ async def main(): beamline.last_updated = datetime.datetime.now() print(datetime.datetime.now()) - # Uncomment this line to actually save the changes to the database + # Uncomment the line below to actually save the changes to the database # await beamline.save() print("Updated beamline") From 5e7b1ca6ec035c9a509a7fad974b21e35faf5a6f Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Thu, 5 Feb 2026 15:12:41 -0500 Subject: [PATCH 5/7] Removed redundant print statements and addressed review comments --- scripts/update_beamline.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index c7158591..08e8f8bc 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -9,7 +9,7 @@ settings = get_settings() # CHANGE THIS TO THE BEAMLINE YOU WANT TO UPDATE -BEAMLINE_NAME = "TLA" +BEAMLINE_NAME = "TLA" # Example: "HXN", "CDI", "AMX", etc. async def main(): @@ -29,28 +29,32 @@ async def main(): if not beamline: raise KeyError(f"No beamline found with pass_id {pass_ids[0]}") + print("Current beamline:") print(beamline) - # CHANGE THESE VALUES TO SUIT YOUR NEEDS. + # This is an example of updating the service accounts for the beamline. + # Change these values to suit your needs. beamline.service_accounts = ServiceAccounts( - ioc="softioc-tla", + ioc="softioc-tla-1", epics_services="epics-services-tla", workflow="workflow-tla", bluesky="bluesky-tla", - operator="xf09id1", + operator="xf99id", lsdc=None ) - print("Will update service_accounts for beamline:", beamline.name) + # INCLUDE ADDITIONAL CHANGES TO THE BEAMLINE OBJECT HERE AS NEEDED + # Example: beamline.long_name = "Repurposed Beamline" + # or: beamline.port = "99-BM" + # etc. or: beamline.network_locations = "xf99bm1" beamline.last_updated = datetime.datetime.now() - print(datetime.datetime.now()) + + print("New values to be updated for the beamline:", beamline.name) + print(beamline) # Uncomment the line below to actually save the changes to the database # await beamline.save() - print("Updated beamline") - print(beamline) - if __name__ == "__main__": asyncio.run(main()) From 6052733df9199b99998d3010fd79dbe0aea1bf26 Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Thu, 5 Feb 2026 15:14:00 -0500 Subject: [PATCH 6/7] typo --- scripts/update_beamline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index 08e8f8bc..34038ee4 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -35,7 +35,7 @@ async def main(): # This is an example of updating the service accounts for the beamline. # Change these values to suit your needs. beamline.service_accounts = ServiceAccounts( - ioc="softioc-tla-1", + ioc="softioc-tla", epics_services="epics-services-tla", workflow="workflow-tla", bluesky="bluesky-tla", From 8160d8314fd5d9763847a6a531869667bc6dcf37 Mon Sep 17 00:00:00 2001 From: anubhutisinha04 Date: Thu, 5 Feb 2026 15:19:07 -0500 Subject: [PATCH 7/7] typo number 2 --- scripts/update_beamline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/update_beamline.py b/scripts/update_beamline.py index 34038ee4..66c69503 100644 --- a/scripts/update_beamline.py +++ b/scripts/update_beamline.py @@ -46,7 +46,7 @@ async def main(): # INCLUDE ADDITIONAL CHANGES TO THE BEAMLINE OBJECT HERE AS NEEDED # Example: beamline.long_name = "Repurposed Beamline" # or: beamline.port = "99-BM" - # etc. or: beamline.network_locations = "xf99bm1" + # or: beamline.network_locations = "xf99bm1" beamline.last_updated = datetime.datetime.now()