From 2e8fe9487144592e9b64a7f5acc3acb392f0bff5 Mon Sep 17 00:00:00 2001 From: Daniel Maclaren Date: Fri, 16 Feb 2024 16:23:58 +0000 Subject: [PATCH 01/33] First draft of update_scripts.py Co-authored-by: esmith1729 --- .../ibex_install_utils/tasks/common_paths.py | 1 + .../tasks/update_scripts.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py diff --git a/installation_and_upgrade/ibex_install_utils/tasks/common_paths.py b/installation_and_upgrade/ibex_install_utils/tasks/common_paths.py index 83ddd11c..b7362aa6 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/common_paths.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/common_paths.py @@ -1,6 +1,7 @@ import os INSTRUMENT_BASE_DIR = os.path.join("C:\\", "Instrument") +SCRIPTS_BASE_DIR = os.path.join(INSTRUMENT_BASE_DIR, "Scripts") APPS_BASE_DIR = os.path.join(INSTRUMENT_BASE_DIR, "Apps") VAR_DIR = os.path.join(INSTRUMENT_BASE_DIR, "var") INST_SHARE_AREA = os.path.join(r"\\isis.cclrc.ac.uk", "inst$") diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py new file mode 100644 index 00000000..655611b6 --- /dev/null +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -0,0 +1,41 @@ +import subprocess + +from ibex_install_utils.task import task +from ibex_install_utils.tasks import BaseTasks +from ibex_install_utils.tasks.common_paths import SCRIPTS_BASE_DIR + +class UpdateScripts(BaseTasks): + + @task(f"Update scripts repo by merging master branch into instrument branch?") + def update_scripts(self): + try: + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout master", shell=True) + print("Checking out master") + except subprocess.CalledProcessError as e: + print(f"Error checking out master branch: {e}") + + try: + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git pull", shell=True) + print("Fetched remote") + except subprocess.CalledProcessError as e: + print(f"Error fetching remote: {e}") + + try: + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout -b %COMPUTERNAME%", shell=True) + print("Checked out to the instrument branch") + except subprocess.CalledProcessError as e: + print(f"Error checking out to new release branch and push: {e}") + + try: + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git merge master", shell=True) + print(f"Merging master into instrument scripts branch") + except subprocess.CalledProcessError as e: + print(f"Error merging master: {e}") + + try: + # run a git status to rebuild index if needed + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git status", shell=True) + except subprocess.CalledProcessError as e: + print(f"Error running git status: {e}") + + \ No newline at end of file From 280ed72674f2db574e3208a4a92accb631ed9253 Mon Sep 17 00:00:00 2001 From: Daniel Maclaren Date: Mon, 19 Feb 2024 15:53:49 +0000 Subject: [PATCH 02/33] rework to the script Co-authored-by: esmith1729 --- .../tasks/update_scripts.py | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 655611b6..2db2f70f 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -8,34 +8,21 @@ class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") def update_scripts(self): - try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout master", shell=True) - print("Checking out master") - except subprocess.CalledProcessError as e: - print(f"Error checking out master branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git pull", shell=True) - print("Fetched remote") + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) + print("Checked out to the instrument branch") except subprocess.CalledProcessError as e: - print(f"Error fetching remote: {e}") + print(f"Error checking out to instrument branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout -b %COMPUTERNAME%", shell=True) - print("Checked out to the instrument branch") + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git fetch --all && git merge master", shell=True) + print("Fetching all changes and merging") except subprocess.CalledProcessError as e: - print(f"Error checking out to new release branch and push: {e}") + print(f"Error Fetching all changes and merging: {e}") - try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git merge master", shell=True) - print(f"Merging master into instrument scripts branch") - except subprocess.CalledProcessError as e: - print(f"Error merging master: {e}") - try: - # run a git status to rebuild index if needed - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git status", shell=True) + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push", shell=True) + print("Pushing to branch") except subprocess.CalledProcessError as e: - print(f"Error running git status: {e}") - - \ No newline at end of file + print(f"Error pushing to branch: {e}") From c7c30f9f1b86b81af3c75c301baf19524e4abe81 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Wed, 21 Feb 2024 12:16:06 +0000 Subject: [PATCH 03/33] Change update script to create branch if doesn't exist, fetch and merge master, and then push to origin --- .../tasks/update_scripts.py | 37 ++++++++----------- .../ibex_install_utils/update_scripts.txt | 0 installation_and_upgrade/pythonwrap.bat | 5 +++ 3 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 installation_and_upgrade/ibex_install_utils/update_scripts.txt create mode 100644 installation_and_upgrade/pythonwrap.bat diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 655611b6..78abe725 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -3,39 +3,32 @@ from ibex_install_utils.task import task from ibex_install_utils.tasks import BaseTasks from ibex_install_utils.tasks.common_paths import SCRIPTS_BASE_DIR +from ibex_install_utils.user_prompt import UserPrompt class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") def update_scripts(self): - try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout master", shell=True) - print("Checking out master") - except subprocess.CalledProcessError as e: - print(f"Error checking out master branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git pull", shell=True) - print("Fetched remote") + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) + print("Checked out to the instrument branch") except subprocess.CalledProcessError as e: - print(f"Error fetching remote: {e}") + print(f"Error checking out to instrument branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout -b %COMPUTERNAME%", shell=True) - print("Checked out to the instrument branch") + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git fetch --all && git merge master", shell=True) + print("Fetching all changes and merging") except subprocess.CalledProcessError as e: - print(f"Error checking out to new release branch and push: {e}") - - try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git merge master", shell=True) - print(f"Merging master into instrument scripts branch") - except subprocess.CalledProcessError as e: - print(f"Error merging master: {e}") + print(f"Error Fetching all changes and merging: {e}") + try: - # run a git status to rebuild index if needed - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git status", shell=True) + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push -u origin %COMPUTERNAME%", shell=True) + print("Pushing to branch") except subprocess.CalledProcessError as e: - print(f"Error running git status: {e}") - - \ No newline at end of file + print(f"Error pushing to branch: {e}") + +if __name__ == "__main__": + prompt = UserPrompt(False,True) + UpdateScripts(prompt, "", "", "", "", "").update_scripts() diff --git a/installation_and_upgrade/ibex_install_utils/update_scripts.txt b/installation_and_upgrade/ibex_install_utils/update_scripts.txt new file mode 100644 index 00000000..e69de29b diff --git a/installation_and_upgrade/pythonwrap.bat b/installation_and_upgrade/pythonwrap.bat new file mode 100644 index 00000000..1235dac7 --- /dev/null +++ b/installation_and_upgrade/pythonwrap.bat @@ -0,0 +1,5 @@ +@ECHO OFF +setlocal +set PYTHONPATH=%1 +python %2 %3 +endlocal \ No newline at end of file From 929b22ade35257bf2b64f57988dbae16234afba4 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Wed, 21 Feb 2024 12:30:19 +0000 Subject: [PATCH 04/33] Merge if name == main call --- .../ibex_install_utils/tasks/update_scripts.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index bbd8e8dc..d089f862 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -21,23 +21,19 @@ def update_scripts(self): print("Fetching all changes and merging") except subprocess.CalledProcessError as e: print(f"Error Fetching all changes and merging: {e}") -<<<<<<< HEAD - try: subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push -u origin %COMPUTERNAME%", shell=True) print("Pushing to branch") except subprocess.CalledProcessError as e: print(f"Error pushing to branch: {e}") - -if __name__ == "__main__": - prompt = UserPrompt(False,True) - UpdateScripts(prompt, "", "", "", "", "").update_scripts() -======= - + try: subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push", shell=True) print("Pushing to branch") except subprocess.CalledProcessError as e: print(f"Error pushing to branch: {e}") ->>>>>>> 280ed72674f2db574e3208a4a92accb631ed9253 + +if __name__ == "__main__": + prompt = UserPrompt(False,True) + UpdateScripts(prompt, "", "", "", "", "").update_scripts() From 069be72f554a0a1a30817a7f65117e39a09d8fad Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Wed, 21 Feb 2024 12:47:59 +0000 Subject: [PATCH 05/33] fix path in pythonwrap --- installation_and_upgrade/pythonwrap.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/pythonwrap.bat b/installation_and_upgrade/pythonwrap.bat index 1235dac7..4503cd6a 100644 --- a/installation_and_upgrade/pythonwrap.bat +++ b/installation_and_upgrade/pythonwrap.bat @@ -1,5 +1,5 @@ @ECHO OFF setlocal set PYTHONPATH=%1 -python %2 %3 +C:/Instrument/Apps/Python3/python3.exe %2 %3 endlocal \ No newline at end of file From 694b790fcc152528dad8c46e0ba1b5415ba468f1 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 10:53:33 +0000 Subject: [PATCH 06/33] Change push to set upstream origin --- .../ibex_install_utils/tasks/update_scripts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index d089f862..726bc9b1 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -23,7 +23,7 @@ def update_scripts(self): print(f"Error Fetching all changes and merging: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push -u origin %COMPUTERNAME%", shell=True) + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) print("Pushing to branch") except subprocess.CalledProcessError as e: print(f"Error pushing to branch: {e}") @@ -37,3 +37,6 @@ def update_scripts(self): if __name__ == "__main__": prompt = UserPrompt(False,True) UpdateScripts(prompt, "", "", "", "", "").update_scripts() + + + From 209e8a5ad821d6083fb34b8350902d1d5f0db511 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 15:59:12 +0000 Subject: [PATCH 07/33] Add Jenkinsfile, bat file, and change user prompt behaviour to default to y for Jenkins pipline to run --- .../Jenkinsfile_update_scripts | 56 +++++++++++++++++++ .../call_update_scripts.bat | 5 ++ .../tasks/update_scripts.py | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 installation_and_upgrade/Jenkinsfile_update_scripts create mode 100644 installation_and_upgrade/call_update_scripts.bat diff --git a/installation_and_upgrade/Jenkinsfile_update_scripts b/installation_and_upgrade/Jenkinsfile_update_scripts new file mode 100644 index 00000000..38cc7f35 --- /dev/null +++ b/installation_and_upgrade/Jenkinsfile_update_scripts @@ -0,0 +1,56 @@ +#!groovy + +pipeline { + // using same agnert as ConfigCheck job + agent { + label { + label 'ConfigCheck' + } + } + + triggers { + cron('H 8 * * *') + } + + environment { + SSH_CREDENTIALS = credentials('SSH') + TEST_INSTRUMENT_LIST = "${TEST_INSTRUMENT_LIST}" + USE_TEST_INSTRUMENT_LIST = "${USE_TEST_INSTRUMENT_LIST}" + DEBUG_MODE = "${DEBUG_MODE}" + } + + stages { + stage('Checkout') { + steps { + timeout(time: 2, unit: 'HOURS') { + retry(5) { + checkout scm + } + } + } + } + + stage('Check Instrument/Scripts can have master merged into it') { + steps { + echo 'Check Instrument/Scripts can have a clean merge master, and then merge master into it' + timeout(time: 1, unit: 'HOURS') { + bat ''' + call call_update_scripts.bat + ''' + } + } + } + } + + post { + always { + logParser([ + projectRulePath: 'parse_rules', + parsingRulesPath: '', + showGraphs: true, + unstableOnWarning: true, + useProjectRule: true, + ]) + } + } +} \ No newline at end of file diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat new file mode 100644 index 00000000..ad07eae9 --- /dev/null +++ b/installation_and_upgrade/call_update_scripts.bat @@ -0,0 +1,5 @@ +setlocal +REM Requires Python3 and python-ssh to be + + +pythonwrap.bat ./ ibex_install_utils\tasks\update_scripts.py \ No newline at end of file diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 726bc9b1..ddbc43ee 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -35,7 +35,7 @@ def update_scripts(self): print(f"Error pushing to branch: {e}") if __name__ == "__main__": - prompt = UserPrompt(False,True) + prompt = UserPrompt(True,False) UpdateScripts(prompt, "", "", "", "", "").update_scripts() From f09efdd93015871e67e2d39cb91960a68922a957 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 16:18:25 +0000 Subject: [PATCH 08/33] Change path to call_update_scripts.bat --- installation_and_upgrade/Jenkinsfile_update_scripts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/Jenkinsfile_update_scripts b/installation_and_upgrade/Jenkinsfile_update_scripts index 38cc7f35..575dada6 100644 --- a/installation_and_upgrade/Jenkinsfile_update_scripts +++ b/installation_and_upgrade/Jenkinsfile_update_scripts @@ -35,7 +35,7 @@ pipeline { echo 'Check Instrument/Scripts can have a clean merge master, and then merge master into it' timeout(time: 1, unit: 'HOURS') { bat ''' - call call_update_scripts.bat + call installation_and_upgrade/call_update_scripts.bat ''' } } From 71bad20bf1a7ccfb489681faf8a56503ecfd3c41 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 16:24:19 +0000 Subject: [PATCH 09/33] Change path to pythonwrap.bat for Jenkins pipeline --- installation_and_upgrade/call_update_scripts.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat index ad07eae9..24177b31 100644 --- a/installation_and_upgrade/call_update_scripts.bat +++ b/installation_and_upgrade/call_update_scripts.bat @@ -1,5 +1,5 @@ setlocal REM Requires Python3 and python-ssh to be - -pythonwrap.bat ./ ibex_install_utils\tasks\update_scripts.py \ No newline at end of file +call +installation_and_upgrade\pythonwrap.bat .\ ibex_install_utils\tasks\update_scripts.py \ No newline at end of file From 4f0d6e765bbf1b14ff988a49b597bf988997a730 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 16:27:15 +0000 Subject: [PATCH 10/33] Change path to update_scripts.py for Jenkins pipeline --- installation_and_upgrade/call_update_scripts.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat index 24177b31..c4b4ad61 100644 --- a/installation_and_upgrade/call_update_scripts.bat +++ b/installation_and_upgrade/call_update_scripts.bat @@ -2,4 +2,4 @@ setlocal REM Requires Python3 and python-ssh to be call -installation_and_upgrade\pythonwrap.bat .\ ibex_install_utils\tasks\update_scripts.py \ No newline at end of file +installation_and_upgrade\pythonwrap.bat .\ installation_and_upgrade\ibex_install_utils\tasks\update_scripts.py \ No newline at end of file From c5812e956b346d3477b50b3bf56fe286ca08fa7e Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Thu, 22 Feb 2024 16:53:23 +0000 Subject: [PATCH 11/33] Change path to root for Jenkins pipeline --- installation_and_upgrade/call_update_scripts.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat index c4b4ad61..82b01ed6 100644 --- a/installation_and_upgrade/call_update_scripts.bat +++ b/installation_and_upgrade/call_update_scripts.bat @@ -2,4 +2,5 @@ setlocal REM Requires Python3 and python-ssh to be call -installation_and_upgrade\pythonwrap.bat .\ installation_and_upgrade\ibex_install_utils\tasks\update_scripts.py \ No newline at end of file +installation_and_upgrade\pythonwrap.bat .\installation_and_upgrade installation_and_upgrade\ibex_install_utils\tasks\update_scripts.py +if %errorlevel% neq 0 exit /b %errorlevel% \ No newline at end of file From bdfff5f07b63b485fbfee71397aecd70acc4fb0d Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Tue, 27 Feb 2024 14:59:03 +0000 Subject: [PATCH 12/33] change merge master to merge origin/master --- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index ddbc43ee..ff84ef67 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -17,7 +17,7 @@ def update_scripts(self): print(f"Error checking out to instrument branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git fetch --all && git merge master", shell=True) + subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) print("Fetching all changes and merging") except subprocess.CalledProcessError as e: print(f"Error Fetching all changes and merging: {e}") From d2eb0faa0bc96f6b1fde85ecaba3dbbda44d367b Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Wed, 28 Feb 2024 11:25:55 +0000 Subject: [PATCH 13/33] Add /d after cd, change update_scripts.bat structure --- installation_and_upgrade/call_update_scripts.bat | 11 ++++++----- .../ibex_install_utils/tasks/update_scripts.py | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat index 82b01ed6..61557d99 100644 --- a/installation_and_upgrade/call_update_scripts.bat +++ b/installation_and_upgrade/call_update_scripts.bat @@ -1,6 +1,7 @@ setlocal -REM Requires Python3 and python-ssh to be - -call -installation_and_upgrade\pythonwrap.bat .\installation_and_upgrade installation_and_upgrade\ibex_install_utils\tasks\update_scripts.py -if %errorlevel% neq 0 exit /b %errorlevel% \ No newline at end of file +call "%~dp0define_latest_genie_python.bat" +IF %errorlevel% neq 0 EXIT /b %errorlevel% +set "PYTHONPATH=." +"%LATEST_PYTHON%" %~dp0ibex_install_utils\tasks\update_scripts.py +REM c:\instrument\apps\python3\python.exe %~dp0ibex_install_utils\tasks\update_scripts.py +if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index ff84ef67..bcdd0afd 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -11,25 +11,25 @@ class UpdateScripts(BaseTasks): def update_scripts(self): try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) print("Checked out to the instrument branch") except subprocess.CalledProcessError as e: print(f"Error checking out to instrument branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) print("Fetching all changes and merging") except subprocess.CalledProcessError as e: print(f"Error Fetching all changes and merging: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) print("Pushing to branch") except subprocess.CalledProcessError as e: print(f"Error pushing to branch: {e}") try: - subprocess.check_call(f"cd {SCRIPTS_BASE_DIR} && git push", shell=True) + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push", shell=True) print("Pushing to branch") except subprocess.CalledProcessError as e: print(f"Error pushing to branch: {e}") From ebf96d1fac65223a733fecf84527f7e119ebc085 Mon Sep 17 00:00:00 2001 From: ISISBuildServer Date: Wed, 28 Feb 2024 11:33:39 +0000 Subject: [PATCH 14/33] revert update_scripts.bat to previous version --- installation_and_upgrade/call_update_scripts.bat | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/installation_and_upgrade/call_update_scripts.bat b/installation_and_upgrade/call_update_scripts.bat index 61557d99..140c5753 100644 --- a/installation_and_upgrade/call_update_scripts.bat +++ b/installation_and_upgrade/call_update_scripts.bat @@ -1,7 +1,5 @@ setlocal -call "%~dp0define_latest_genie_python.bat" -IF %errorlevel% neq 0 EXIT /b %errorlevel% -set "PYTHONPATH=." -"%LATEST_PYTHON%" %~dp0ibex_install_utils\tasks\update_scripts.py -REM c:\instrument\apps\python3\python.exe %~dp0ibex_install_utils\tasks\update_scripts.py + +call +installation_and_upgrade\pythonwrap.bat .\installation_and_upgrade installation_and_upgrade\ibex_install_utils\tasks\update_scripts.py if %errorlevel% neq 0 exit /b %errorlevel% From d2d30230317c7b6ef9ec105257c4bd03ea8ab25d Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Thu, 29 Feb 2024 14:56:48 +0000 Subject: [PATCH 15/33] delete unnecessary file --- installation_and_upgrade/ibex_install_utils/update_scripts.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 installation_and_upgrade/ibex_install_utils/update_scripts.txt diff --git a/installation_and_upgrade/ibex_install_utils/update_scripts.txt b/installation_and_upgrade/ibex_install_utils/update_scripts.txt deleted file mode 100644 index e69de29b..00000000 From 2299de48d7ed0718d822149cdf8da5007a5ca22b Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Thu, 29 Feb 2024 17:11:12 +0000 Subject: [PATCH 16/33] Created general method for automatic merge in git_tasks.py; implemented into update_scripts.py Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/git_tasks.py | 56 ++++++++++++++++++- .../tasks/update_scripts.py | 50 +++++++++-------- 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index d905dfee..0de7def4 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -2,9 +2,12 @@ from ibex_install_utils.task import task from ibex_install_utils.tasks import BaseTasks -from ibex_install_utils.tasks.common_paths import EPICS_PATH +from ibex_install_utils.tasks.common_paths import EPICS_PATH, SETTINGS_CONFIG_PATH +from ibex_install_utils.exceptions import ErrorInRun, ErrorInTask from genie_python import genie as g import re +import git +import os class GitTasks(BaseTasks): @@ -62,3 +65,54 @@ def checkout_to_release_branch(self): # print("Switched to existing release branch") # except subprocess.CalledProcessError as e: # print(f"Error switching to existing release branch and push: {e}") + + #decorator class to check that the machine name matches a git branch + def inst_name_matches_branch(): + repo = git.Repo( + os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name()) + ) + if repo.active_branch.name != BaseTasks._get_machine_name(): + print( + f"Git branch, '{repo.active_branch}', is not the same as machine name ,'{BaseTasks._get_machine_name()}' " + ) + raise ErrorInTask("Git branch is not the same as machine name") + + def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, repo): + f""" + Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {repo} + """ + manual_prompt = ( + "Merge the master configurations branch into the instrument configuration. " + "From C:\Instrument\Settings\config\[machine name] run:\n" + " 0. Clean up any in progress merge (e.g. git merge --abort)\n" + " 1. git checkout master\n" + " 2. git pull\n" + " 3. git checkout [machine name]\n" + " 4. git merge master\n" + " 5. Resolve any merge conflicts\n" + " 6. git push\n" + ) + + automatic_prompt = "Attempt automatic merge?" + + if self.prompt.confirm_step(automatic_prompt): + try: + try: + print(f" fetch: {repo.git.fetch()}") + print(f" merge: {repo.git.merge(f'{branch_to_merge_from}')}") + except git.GitCommandError as e: + # do gc and prune to remove issues with stale references + # this does a pack that takes a while, hence not do every time + print(f"Retrying git operations after a prune due to {e}") + print(f" gc: {repo.git.gc(prune='now')}") + print(f" prune: {repo.git.remote('prune', 'origin')}") + print(f" fetch: {repo.git.fetch()}") + print(f" merge: {repo.git.merge(f'{branch_to_merge_from}')}") + # no longer push let the instrument do that on start up if needed + except git.GitCommandError as e: + print( + f"Error doing automatic merge, please perform the merge manually: {e}" + ) + self.prompt.prompt_and_raise_if_not_yes(manual_prompt) + else: + self.prompt.prompt_and_raise_if_not_yes(manual_prompt) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index bcdd0afd..5cba995a 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -2,6 +2,7 @@ from ibex_install_utils.task import task from ibex_install_utils.tasks import BaseTasks +from ibex_install_utils.tasks.git_tasks import GitTasks from ibex_install_utils.tasks.common_paths import SCRIPTS_BASE_DIR from ibex_install_utils.user_prompt import UserPrompt @@ -9,30 +10,33 @@ class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") def update_scripts(self): + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}") + git_instance = GitTasks() + git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) - try: - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) - print("Checked out to the instrument branch") - except subprocess.CalledProcessError as e: - print(f"Error checking out to instrument branch: {e}") - - try: - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) - print("Fetching all changes and merging") - except subprocess.CalledProcessError as e: - print(f"Error Fetching all changes and merging: {e}") - - try: - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) - print("Pushing to branch") - except subprocess.CalledProcessError as e: - print(f"Error pushing to branch: {e}") - - try: - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push", shell=True) - print("Pushing to branch") - except subprocess.CalledProcessError as e: - print(f"Error pushing to branch: {e}") + #try: + # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) + # print("Checked out to the instrument branch") + #except subprocess.CalledProcessError as e: + # print(f"Error checking out to instrument branch: {e}") +# + #try: + # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) + # print("Fetching all changes and merging") + #except subprocess.CalledProcessError as e: + # print(f"Error Fetching all changes and merging: {e}") + # + #try: + # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) + # print("Pushing to branch") + #except subprocess.CalledProcessError as e: + # print(f"Error pushing to branch: {e}") + # + #try: + # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push", shell=True) + # print("Pushing to branch") + #except subprocess.CalledProcessError as e: + #print(f"Error pushing to branch: {e}") if __name__ == "__main__": prompt = UserPrompt(True,False) From 11c569600724e8851f2c40c1bf9e10b25cd92606 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Thu, 29 Feb 2024 17:15:52 +0000 Subject: [PATCH 17/33] Add try/except clause to body of update_scripts.py Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 5cba995a..18c1c3f5 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -10,9 +10,12 @@ class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") def update_scripts(self): - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}") - git_instance = GitTasks() - git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) + try: + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}") + git_instance = GitTasks() + git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) + except subprocess.CalledProcessError as e: + print(f"{e}") #try: # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) From ddb20b04b2c79b93181f53d55996faeb4acbad3d Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Thu, 29 Feb 2024 17:16:48 +0000 Subject: [PATCH 18/33] Add shell=True Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 18c1c3f5..42c0e61a 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -11,7 +11,7 @@ class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") def update_scripts(self): try: - subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}") + subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) git_instance = GitTasks() git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) except subprocess.CalledProcessError as e: From 09a9288f7e1463b9edf6d47166580b4b978010ba Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Thu, 29 Feb 2024 17:19:30 +0000 Subject: [PATCH 19/33] Add empty args to GitTasks Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 42c0e61a..18e4a61e 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -12,7 +12,7 @@ class UpdateScripts(BaseTasks): def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) - git_instance = GitTasks() + git_instance = GitTasks('','','','','') git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) except subprocess.CalledProcessError as e: print(f"{e}") From 0248bf4dfc8d87e406a065384a798ea213a0dbf1 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 11:51:59 +0000 Subject: [PATCH 20/33] Add @task decorator to automatic merge function, in order to give it access to BaseTasks' prompt function Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/git_tasks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index 0de7def4..212efca3 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -4,6 +4,7 @@ from ibex_install_utils.tasks import BaseTasks from ibex_install_utils.tasks.common_paths import EPICS_PATH, SETTINGS_CONFIG_PATH from ibex_install_utils.exceptions import ErrorInRun, ErrorInTask +from ibex_install_utils.user_prompt import UserPrompt from genie_python import genie as g import re import git @@ -66,7 +67,7 @@ def checkout_to_release_branch(self): # except subprocess.CalledProcessError as e: # print(f"Error switching to existing release branch and push: {e}") - #decorator class to check that the machine name matches a git branch + #Method to check that the machine name matches a git branch def inst_name_matches_branch(): repo = git.Repo( os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name()) @@ -77,6 +78,7 @@ def inst_name_matches_branch(): ) raise ErrorInTask("Git branch is not the same as machine name") + @task(f"Attempt automatic merge of one branch into another") def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, repo): f""" Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {repo} From 0f11479b6d25c8a44fffb2d61523cc55c1386d4a Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 12:03:27 +0000 Subject: [PATCH 21/33] Fixed typo of "confirm_steps" Co-authored-by: dtmaclaren --- installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index 212efca3..e2cbe22b 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -97,7 +97,7 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to automatic_prompt = "Attempt automatic merge?" - if self.prompt.confirm_step(automatic_prompt): + if self.prompt.confirm_steps(automatic_prompt): try: try: print(f" fetch: {repo.git.fetch()}") From 13db87a58498289b139c0015f3919c257ff472c7 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 12:07:22 +0000 Subject: [PATCH 22/33] Changed "confirm_step" to "confirm_steps" in task.py Co-authored-by: dtmaclaren --- installation_and_upgrade/ibex_install_utils/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/task.py b/installation_and_upgrade/ibex_install_utils/task.py index 1cd14bda..df1cadf5 100644 --- a/installation_and_upgrade/ibex_install_utils/task.py +++ b/installation_and_upgrade/ibex_install_utils/task.py @@ -41,7 +41,7 @@ def task(task_name, attribute_name="prompt"): def _task_with_name_decorator(func): def _wrapper(self_of_decorated_method, *args, **kwargs): prompt = getattr(self_of_decorated_method, attribute_name) - if prompt.confirm_step(task_name): + if prompt.confirm_steps(task_name): print(f"{task_name} ...") while True: if _run_task_to_completion(task_name, prompt, self_of_decorated_method, func, args, kwargs): From 1a92c9215433decdf93eb860c1d9d23dfaf4c6b0 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 13:41:06 +0000 Subject: [PATCH 23/33] Changed confirm_steps back to confirm_step. Added self.prompt to GitTasks instance in update_scripts.py Co-authored-by: dtmaclaren --- installation_and_upgrade/ibex_install_utils/task.py | 2 +- installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py | 3 +-- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/task.py b/installation_and_upgrade/ibex_install_utils/task.py index df1cadf5..1cd14bda 100644 --- a/installation_and_upgrade/ibex_install_utils/task.py +++ b/installation_and_upgrade/ibex_install_utils/task.py @@ -41,7 +41,7 @@ def task(task_name, attribute_name="prompt"): def _task_with_name_decorator(func): def _wrapper(self_of_decorated_method, *args, **kwargs): prompt = getattr(self_of_decorated_method, attribute_name) - if prompt.confirm_steps(task_name): + if prompt.confirm_step(task_name): print(f"{task_name} ...") while True: if _run_task_to_completion(task_name, prompt, self_of_decorated_method, func, args, kwargs): diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index e2cbe22b..a4f80215 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -78,7 +78,6 @@ def inst_name_matches_branch(): ) raise ErrorInTask("Git branch is not the same as machine name") - @task(f"Attempt automatic merge of one branch into another") def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, repo): f""" Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {repo} @@ -97,7 +96,7 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to automatic_prompt = "Attempt automatic merge?" - if self.prompt.confirm_steps(automatic_prompt): + if self.prompt.confirm_step(automatic_prompt): try: try: print(f" fetch: {repo.git.fetch()}") diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 18e4a61e..cb7f4c3a 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -12,7 +12,7 @@ class UpdateScripts(BaseTasks): def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) - git_instance = GitTasks('','','','','') + git_instance = GitTasks(self.prompt,'','','','') git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) except subprocess.CalledProcessError as e: print(f"{e}") From b088a852278f835f178fbb51b523ba1317b06253 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:01:18 +0000 Subject: [PATCH 24/33] Added git.Repo instance to git_tasks.py Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/git_tasks.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index a4f80215..b1b84880 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -78,9 +78,10 @@ def inst_name_matches_branch(): ) raise ErrorInTask("Git branch is not the same as machine name") - def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, repo): + @task(f"Attempt automatic merge of one branch into another") + def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, dir): f""" - Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {repo} + Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {dir} """ manual_prompt = ( "Merge the master configurations branch into the instrument configuration. " @@ -95,7 +96,7 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to ) automatic_prompt = "Attempt automatic merge?" - + repo = git.Repo(dir) if self.prompt.confirm_step(automatic_prompt): try: try: @@ -117,3 +118,19 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to self.prompt.prompt_and_raise_if_not_yes(manual_prompt) else: self.prompt.prompt_and_raise_if_not_yes(manual_prompt) + +if __name__ == "__main__": + """For running task standalone + Must be called with pythonpath set to `/installation_and_upgrade` + as that is the root of this module and all our imports work that way. + + This effectively means to call `set PYTHONPATH=. && python ibex_install_utils/tasks/backup_tasks.py` + from the installation_and_upgrade directory in terminal. + """ + print("") + + #! Copying older backups to share will likely fail on developer machines + prompt = UserPrompt(False, True) + + git_instance = GitTasks(prompt,'','','','') + git_instance.automatic_merge_of_git_remote("branch1", "branch2", "C:/test") From ae045adb159ff4a25d8379b56c80f2716d2133d4 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:05:47 +0000 Subject: [PATCH 25/33] removed {} from Scripts base dir call Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index cb7f4c3a..3dd6a1b4 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -13,7 +13,7 @@ def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) git_instance = GitTasks(self.prompt,'','','','') - git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", {SCRIPTS_BASE_DIR}) + git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", SCRIPTS_BASE_DIR) except subprocess.CalledProcessError as e: print(f"{e}") From 252d97201f5ad10c42e6c5309b35948d049a16dd Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:12:06 +0000 Subject: [PATCH 26/33] Removed comments, update manual prompt message of automatic_merge method Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/git_tasks.py | 10 ++++---- .../tasks/update_scripts.py | 24 ------------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index b1b84880..46dc76f8 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -84,13 +84,13 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {dir} """ manual_prompt = ( - "Merge the master configurations branch into the instrument configuration. " - "From C:\Instrument\Settings\config\[machine name] run:\n" + f"Merge the {branch_to_merge_from} branch into the {branch_to_merge_to} branch. " + f"From {dir} run:\n" " 0. Clean up any in progress merge (e.g. git merge --abort)\n" - " 1. git checkout master\n" + f" 1. git checkout {branch_to_merge_from}\n" " 2. git pull\n" - " 3. git checkout [machine name]\n" - " 4. git merge master\n" + f" 3. git checkout {branch_to_merge_to}\n" + f" 4. git merge {branch_to_merge_from})\n" " 5. Resolve any merge conflicts\n" " 6. git push\n" ) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 3dd6a1b4..b8bc5a4f 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -16,30 +16,6 @@ def update_scripts(self): git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", SCRIPTS_BASE_DIR) except subprocess.CalledProcessError as e: print(f"{e}") - - #try: - # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git checkout %COMPUTERNAME% || git checkout -b %COMPUTERNAME%", shell=True) - # print("Checked out to the instrument branch") - #except subprocess.CalledProcessError as e: - # print(f"Error checking out to instrument branch: {e}") -# - #try: - # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git fetch --all && git merge origin/master", shell=True) - # print("Fetching all changes and merging") - #except subprocess.CalledProcessError as e: - # print(f"Error Fetching all changes and merging: {e}") - # - #try: - # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push --set-upstream origin %COMPUTERNAME%", shell=True) - # print("Pushing to branch") - #except subprocess.CalledProcessError as e: - # print(f"Error pushing to branch: {e}") - # - #try: - # subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR} && git push", shell=True) - # print("Pushing to branch") - #except subprocess.CalledProcessError as e: - #print(f"Error pushing to branch: {e}") if __name__ == "__main__": prompt = UserPrompt(True,False) From 69fc533036b9c8d174b6d097a50f05e57331a0ed Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:21:48 +0000 Subject: [PATCH 27/33] Remove extra ), put %COMPUTERNAME% into fstring Co-authored-by: dtmaclaren --- installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py | 2 +- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index 46dc76f8..c682f363 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -90,7 +90,7 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to f" 1. git checkout {branch_to_merge_from}\n" " 2. git pull\n" f" 3. git checkout {branch_to_merge_to}\n" - f" 4. git merge {branch_to_merge_from})\n" + f" 4. git merge {branch_to_merge_from}\n" " 5. Resolve any merge conflicts\n" " 6. git push\n" ) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index b8bc5a4f..9f54a366 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -13,7 +13,7 @@ def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) git_instance = GitTasks(self.prompt,'','','','') - git_instance.automatic_merge_of_git_remote("origin/master", "%COMPUTERNAME%", SCRIPTS_BASE_DIR) + git_instance.automatic_merge_of_git_remote("origin/master", f"%COMPUTERNAME%", SCRIPTS_BASE_DIR) except subprocess.CalledProcessError as e: print(f"{e}") From f9b848d649e9d9a7790d2aa58a578e28d9a58dc7 Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:24:34 +0000 Subject: [PATCH 28/33] Add print statement to test COMPUTERNAME Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 9f54a366..37574178 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -19,6 +19,7 @@ def update_scripts(self): if __name__ == "__main__": prompt = UserPrompt(True,False) + print(f"%COMPUTERNAME%") UpdateScripts(prompt, "", "", "", "", "").update_scripts() From a8345b0d28f8df65815c5b746685b4ace381245b Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:28:25 +0000 Subject: [PATCH 29/33] Created global for COMPUTERNAME from BaseTasks' get_machine_name() method Co-authored-by: dtmaclaren --- .../ibex_install_utils/tasks/update_scripts.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 37574178..f986a609 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -6,6 +6,8 @@ from ibex_install_utils.tasks.common_paths import SCRIPTS_BASE_DIR from ibex_install_utils.user_prompt import UserPrompt +COMPUTERNAME = BaseTasks._get_machine_name() + class UpdateScripts(BaseTasks): @task(f"Update scripts repo by merging master branch into instrument branch?") @@ -13,7 +15,7 @@ def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) git_instance = GitTasks(self.prompt,'','','','') - git_instance.automatic_merge_of_git_remote("origin/master", f"%COMPUTERNAME%", SCRIPTS_BASE_DIR) + git_instance.automatic_merge_of_git_remote("origin/master", COMPUTERNAME, SCRIPTS_BASE_DIR) except subprocess.CalledProcessError as e: print(f"{e}") From e9af8263a457995ffc5a9d2f668ec25a94958f0d Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:40:34 +0000 Subject: [PATCH 30/33] Put manual prompt into right spot Co-authored-by: dtmaclaren Co-authored-by: zsoltkebel --- installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py | 2 +- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index c682f363..13663221 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -115,7 +115,7 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to print( f"Error doing automatic merge, please perform the merge manually: {e}" ) - self.prompt.prompt_and_raise_if_not_yes(manual_prompt) + self.prompt.prompt_and_raise_if_not_yes(manual_prompt) else: self.prompt.prompt_and_raise_if_not_yes(manual_prompt) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index f986a609..90ce674d 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -21,7 +21,7 @@ def update_scripts(self): if __name__ == "__main__": prompt = UserPrompt(True,False) - print(f"%COMPUTERNAME%") + print(COMPUTERNAME) UpdateScripts(prompt, "", "", "", "", "").update_scripts() From df7cbf65e43e98431ed264e5da6055ac0d29dc8b Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 14:44:38 +0000 Subject: [PATCH 31/33] Made task prompt message more clear Co-authored-by: dtmaclaren Co-authored-by: zsoltkebel --- .../ibex_install_utils/tasks/update_scripts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 90ce674d..197fc5d5 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -10,7 +10,7 @@ class UpdateScripts(BaseTasks): - @task(f"Update scripts repo by merging master branch into instrument branch?") + @task(f"Update Instrument/Scripts repo by merging 'origin/master' branch into {COMPUTERNAME} branch?") def update_scripts(self): try: subprocess.check_call(f"cd /d {SCRIPTS_BASE_DIR}", shell=True) From e9ab25af87a779c95d687ae3285339df43e1039c Mon Sep 17 00:00:00 2001 From: esmithExperimentControls Date: Fri, 1 Mar 2024 15:07:54 +0000 Subject: [PATCH 32/33] Added cd /d and git checkout call in git_tasks steps of automatic merge Co-authored-by: dtmaclaren --- installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py | 3 +++ .../ibex_install_utils/tasks/update_scripts.py | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index 13663221..81bf4ab4 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -100,6 +100,9 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to if self.prompt.confirm_step(automatic_prompt): try: try: + subprocess.check_call(f"cd /d {dir}", shell=True) + print(f" cd: {dir}") + print(f" checkout: {repo.git.checkout(f'{branch_to_merge_to}')}") print(f" fetch: {repo.git.fetch()}") print(f" merge: {repo.git.merge(f'{branch_to_merge_from}')}") except git.GitCommandError as e: diff --git a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py index 197fc5d5..00eb828f 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/update_scripts.py @@ -23,6 +23,3 @@ def update_scripts(self): prompt = UserPrompt(True,False) print(COMPUTERNAME) UpdateScripts(prompt, "", "", "", "", "").update_scripts() - - - From a1c8871a0790aee70b738c1f47d3808fe587273e Mon Sep 17 00:00:00 2001 From: Freddie Akeroyd Date: Sun, 9 Mar 2025 11:56:00 +0000 Subject: [PATCH 33/33] ruff --- .../ibex_install_utils/tasks/git_tasks.py | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py index 776fff03..e2c25323 100644 --- a/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py +++ b/installation_and_upgrade/ibex_install_utils/tasks/git_tasks.py @@ -1,15 +1,15 @@ +import os import re import subprocess +import git + +from ibex_install_utils.exceptions import ErrorInTask from ibex_install_utils.task import task from ibex_install_utils.tasks import BaseTasks from ibex_install_utils.tasks.common_paths import EPICS_PATH, SETTINGS_CONFIG_PATH -from ibex_install_utils.exceptions import ErrorInRun, ErrorInTask from ibex_install_utils.user_prompt import UserPrompt -from genie_python import genie as g -import re -import git -import os + class GitTasks(BaseTasks): @task(f"Show Git status in {EPICS_PATH}") @@ -92,28 +92,32 @@ def checkout_to_release_branch(self) -> None: print(f"Error checking out to new release branch and push: {e}") print("Branch may previously exist either locally or remotely - intervention required") -# something for the future in case creting new beranch fails - maybe one exists we want to use? -# try: -# subprocess.check_call(f"cd {EPICS_PATH} && git checkout %COMPUTERNAME%", shell=True) -# print("Switched to existing release branch") -# except subprocess.CalledProcessError as e: -# print(f"Error switching to existing release branch and push: {e}") - - #Method to check that the machine name matches a git branch - def inst_name_matches_branch(): - repo = git.Repo( - os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name()) - ) + # something for the future in case creating new branch fails + # maybe one exists we want to use? + # try: + # subprocess.check_call(f"cd {EPICS_PATH} && git checkout %COMPUTERNAME%", + # shell=True) + # print("Switched to existing release branch") + # except subprocess.CalledProcessError as e: + # print(f"Error switching to existing release branch and push: {e}") + + # Method to check that the machine name matches a git branch + def inst_name_matches_branch(self) -> None: + repo = git.Repo(os.path.join(SETTINGS_CONFIG_PATH, BaseTasks._get_machine_name())) if repo.active_branch.name != BaseTasks._get_machine_name(): print( - f"Git branch, '{repo.active_branch}', is not the same as machine name ,'{BaseTasks._get_machine_name()}' " + f"Git branch, '{repo.active_branch}', is not the same as machine name ," + f"'{BaseTasks._get_machine_name()}' " ) raise ErrorInTask("Git branch is not the same as machine name") - @task(f"Attempt automatic merge of one branch into another") - def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to, dir): + @task("Attempt automatic merge of one branch into another") + def automatic_merge_of_git_remote( + self, branch_to_merge_from: str, branch_to_merge_to: str, dir: str + ) -> None: f""" - Attempt an automatic merge of one branch {branch_to_merge_from} to another, {branch_to_merge_to} in {dir} + Attempt an automatic merge of one branch + {branch_to_merge_from} to another, {branch_to_merge_to} in {dir} """ manual_prompt = ( f"Merge the {branch_to_merge_from} branch into the {branch_to_merge_to} branch. " @@ -126,10 +130,10 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to " 5. Resolve any merge conflicts\n" " 6. git push\n" ) - + automatic_prompt = "Attempt automatic merge?" repo = git.Repo(dir) - if self.prompt.confirm_step(automatic_prompt): + if self.prompt.confirm_step(automatic_prompt): try: try: subprocess.check_call(f"cd /d {dir}", shell=True) @@ -147,25 +151,25 @@ def automatic_merge_of_git_remote(self, branch_to_merge_from, branch_to_merge_to print(f" merge: {repo.git.merge(f'{branch_to_merge_from}')}") # no longer push let the instrument do that on start up if needed except git.GitCommandError as e: - print( - f"Error doing automatic merge, please perform the merge manually: {e}" - ) + print(f"Error doing automatic merge, please perform the merge manually: {e}") self.prompt.prompt_and_raise_if_not_yes(manual_prompt) else: self.prompt.prompt_and_raise_if_not_yes(manual_prompt) + if __name__ == "__main__": """For running task standalone Must be called with pythonpath set to `/installation_and_upgrade` as that is the root of this module and all our imports work that way. - This effectively means to call `set PYTHONPATH=. && python ibex_install_utils/tasks/backup_tasks.py` + This effectively means to call + `set PYTHONPATH=. && python ibex_install_utils/tasks/backup_tasks.py` from the installation_and_upgrade directory in terminal. """ print("") #! Copying older backups to share will likely fail on developer machines prompt = UserPrompt(False, True) - - git_instance = GitTasks(prompt,'','','','') + + git_instance = GitTasks(prompt, "", "", "", "") git_instance.automatic_merge_of_git_remote("branch1", "branch2", "C:/test")