@ -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 in BranchRestoreBool == True :
if in Previous BranchRestoreBool == 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 :
"""