From 3f5a8e56873e85e470bc35827129f6c73ced9672 Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sun, 20 Feb 2022 19:33:20 +0300 Subject: [PATCH] Managers. Git is ready - try to test --- Orchestrator/ControlPanel/CP_Test.py | 5 ++ Orchestrator/OrchestratorSettings.py | 8 ++- .../pyOpenRPA/Orchestrator/Managers/Git.py | 55 +++++++++++++------ .../Orchestrator/__Orchestrator__.py | 3 +- 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/Orchestrator/ControlPanel/CP_Test.py b/Orchestrator/ControlPanel/CP_Test.py index 01c7e402..46c5e732 100644 --- a/Orchestrator/ControlPanel/CP_Test.py +++ b/Orchestrator/ControlPanel/CP_Test.py @@ -45,8 +45,13 @@ def JSInitGenerator(): """ return lJSCheckVersion +def test(): + #Orchestrator.WebRequestGet() + Orchestrator.WebRequestResponseSend("Hello my friend!") + #Orchestrator settings def SettingsUpdate(inGSettings): # New way to add CP defs in orchestrator - no gSettings.. Orchestrator.WebCPUpdate(inGSettings=inGSettings, inCPKeyStr="TEST", inHTMLRenderDef=CPRender, inJSONGeneratorDef=JSONGenerator, inJSInitGeneratorDef=JSInitGenerator) + Orchestrator.WebURLConnectDef(inMethodStr="GET", inURLStr="/test", inMatchTypeStr="Equal", inDef=test, inUACBool=False) return inGSettings \ No newline at end of file diff --git a/Orchestrator/OrchestratorSettings.py b/Orchestrator/OrchestratorSettings.py index fccaf7dd..164da1e4 100644 --- a/Orchestrator/OrchestratorSettings.py +++ b/Orchestrator/OrchestratorSettings.py @@ -1,4 +1,6 @@ -import psutil, datetime, logging, os, sys # stdout from logging +import psutil, datetime, logging, os, sys + +from pyOpenRPA.Orchestrator.__Orchestrator__ import OrchestratorLoggerGet # stdout from logging # Config settings lPyOpenRPASourceFolderPathStr = r"..\Sources" # Path for test pyOpenRPA package @@ -16,7 +18,8 @@ if not Orchestrator.OrchestratorIsAdmin(): else: gSettings = Orchestrator.GSettingsGet() #gSettings = SettingsTemplate.Create(inModeStr="BASIC") # Create GSettings with basic configuration - no more config is available from the box - you can create own - + # Set the debug level + OrchestratorLoggerGet().setLevel(logging.DEBUG) # TEST Add User ND - Add Login ND to superuser of the Orchestrator lUACClientDict = SettingsTemplate.__UACClientAdminCreate__() Orchestrator.UACUpdate(inGSettings=gSettings, inADLoginStr="ND", inADStr="", inADIsDefaultBool=True, inURLList=[], inRoleHierarchyAllowedDict=lUACClientDict) @@ -33,3 +36,4 @@ else: # Call the orchestrator def Orchestrator.Orchestrator(inGSettings=gSettings, inDumpRestoreBool=False) + diff --git a/Sources/pyOpenRPA/Orchestrator/Managers/Git.py b/Sources/pyOpenRPA/Orchestrator/Managers/Git.py index dd6e6f9b..00b7d6b0 100644 --- a/Sources/pyOpenRPA/Orchestrator/Managers/Git.py +++ b/Sources/pyOpenRPA/Orchestrator/Managers/Git.py @@ -6,6 +6,8 @@ from . import Process from typing import List +from pyOpenRPA import Orchestrator + class Git(): mAgentHostNameStr = None @@ -60,7 +62,6 @@ class Git(): for lProcessItem in self.mProcessList: lProcessItem.StatusRestore() - def __OSCMDShell__(self, inCMDStr): """ Detect the way of use and send the cmd. Wait for command execution! @@ -92,15 +93,39 @@ class Git(): return lCMDResultStr def BranchRevIsLast(self, inBranchLocalStr: str, inBranchRemoteStr: str) -> bool: - pass + """Get fetch and check if local branch revision is last (if check with remote) + + :param inBranchLocalStr: _description_ + :type inBranchLocalStr: str + :param inBranchRemoteStr: _description_ + :type inBranchRemoteStr: str + :return: _description_ + :rtype: bool + """ lIsLastBool = False + self.Fetch() lLocalBranchRevStr = self.BranchRevGet(inBranchNameStr=inBranchLocalStr) lRemoteBranchRevStr = self.BranchRevGet(inBranchNameStr=inBranchRemoteStr) if lLocalBranchRevStr == lRemoteBranchRevStr: lIsLastBool = True return lIsLastBool - def BranchRevLastGet(self, inBranchLocalStr: str, inBranchRemoteStr: str, inBranchRestoreBool: bool = True): + + def BranchRevLastGetInterval(self, inBranchLocalStr: str, inBranchRemoteStr: str, inPreviousBranchRestoreBool: bool = True, inIntervalSecFloat: float = 60.0): + """Periodically check if revision is last + + :param inBranchLocalStr: _description_ + :type inBranchLocalStr: str + :param inBranchRemoteStr: _description_ + :type inBranchRemoteStr: str + :param inPreviousBranchRestoreBool: _description_, defaults to True + :type inPreviousBranchRestoreBool: bool, optional + :param inIntervalSecFloat: _description_, defaults to 60.0 + :type inIntervalSecFloat: float, optional + """ + Orchestrator.OrchestratorScheduleGet().every(inIntervalSecFloat).seconds().do(self.BranchRevLastGet, inBranchLocalStr, inBranchRemoteStr, inPreviousBranchRestoreBool) + + def BranchRevLastGet(self, inBranchLocalStr: str, inBranchRemoteStr: str, inPreviousBranchRestoreBool: bool = True): """Do some action to get the last revision :param inBranchLocalStr: [description] @@ -108,8 +133,11 @@ class Git(): :param inBranchRemoteStr: [description] :type inBranchRemoteStr: str """ + Orchestrator.OrchestratorLoggerGet().debug(f"Managers.Git ({self.mAbsPathStr}): self.BranchRevLastGet has been init") # check if the correct revision + lCMDResultStr = None if self.BranchRevIsLast(inBranchLocalStr=inBranchLocalStr, inBranchRemoteStr=inBranchRemoteStr) == False: + Orchestrator.OrchestratorLoggerGet().debug(f"Managers.Git ({self.mAbsPathStr}): self.BranchRevLastGet, new revision has been detected - start to merge") lBranchNameCurrentStr = self.BranchNameGet() # reset all changes in local folder self.Clear() @@ -118,17 +146,10 @@ class Git(): # merge lCMDStr = f"cd \"{self.mAbsPathUpperStr}\" && git merge {inBranchRemoteStr}" lCMDResultStr = self.__OSCMDShell__(inCMDStr=lCMDStr) - if inBranchRestoreBool == True: + if inPreviousBranchRestoreBool == True: # checkout to the source branch which was self.BranchCheckout(inBranchNameStr=lBranchNameCurrentStr) - - def BranchRevCheck(self, inBranchRemoteStr): - """Check if branch is last. If not last -> do some actions to get last - - :param inBranchRemoteStr: [description] - :type inBranchRemoteStr: [type] - """ - pass + return lCMDResultStr def BranchNameGet(self) -> str: """Get the current local branch name @@ -141,10 +162,10 @@ class Git(): return lCMDResultStr def BranchCheckout(self, inBranchNameStr): - pass - f"git clean -f -d" # Очистить от лишних файлов - - f"git checkout {inBranchNameStr}" + self.Clear() + lCMDStr = f"cd \"{self.mAbsPathUpperStr}\" && git checkout {inBranchNameStr}" + lCMDResultStr = self.__OSCMDShell__(inCMDStr=lCMDStr) + return lCMDResultStr def Clear(self): """Clear the all changes in the local folder. Get up to the current revision @@ -155,6 +176,7 @@ class Git(): # f"git reset --hard" # Откатить файлы, которые отслеживаются Git и которые были изменены lCMDStr = f"cd \"{self.mAbsPathUpperStr}\" && git reset --hard" lCMDResultStr = self.__OSCMDShell__(inCMDStr=lCMDStr) + return lCMDResultStr def Fetch(self): """ @@ -167,6 +189,7 @@ class Git(): """ lCMDStr = f"cd \"{self.mAbsPathUpperStr}\" && git fetch" lCMDResultStr = self.__OSCMDShell__(inCMDStr=lCMDStr) + return lCMDResultStr def GitExists(inAgentHostNameStr: str, inAgentUserNameStr: str, inGitPathStr: str) -> bool: """ diff --git a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py index 714aa4de..6e8d465c 100644 --- a/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py +++ b/Sources/pyOpenRPA/Orchestrator/__Orchestrator__.py @@ -529,7 +529,7 @@ def OrchestratorRestart(inGSettings=None): os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) sys.exit(0) -def OrchestratorLoggerGet(): +def OrchestratorLoggerGet() -> logging.Logger: """ Get the logger from the Orchestrator @@ -537,6 +537,7 @@ def OrchestratorLoggerGet(): """ return GSettingsGet().get("Logger",None) + def OrchestratorScheduleGet() -> schedule: """ Get the schedule (schedule.readthedocs.io) from the Orchestrator