@ -6,6 +6,8 @@ from . import Process
from typing import List
from typing import List
from pyOpenRPA import Orchestrator
class Git ( ) :
class Git ( ) :
mAgentHostNameStr = None
mAgentHostNameStr = None
@ -60,7 +62,6 @@ class Git():
for lProcessItem in self . mProcessList :
for lProcessItem in self . mProcessList :
lProcessItem . StatusRestore ( )
lProcessItem . StatusRestore ( )
def __OSCMDShell__ ( self , inCMDStr ) :
def __OSCMDShell__ ( self , inCMDStr ) :
"""
"""
Detect the way of use and send the cmd . Wait for command execution !
Detect the way of use and send the cmd . Wait for command execution !
@ -92,15 +93,39 @@ class Git():
return lCMDResultStr
return lCMDResultStr
def BranchRevIsLast ( self , inBranchLocalStr : str , inBranchRemoteStr : str ) - > bool :
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
lIsLastBool = False
self . Fetch ( )
lLocalBranchRevStr = self . BranchRevGet ( inBranchNameStr = inBranchLocalStr )
lLocalBranchRevStr = self . BranchRevGet ( inBranchNameStr = inBranchLocalStr )
lRemoteBranchRevStr = self . BranchRevGet ( inBranchNameStr = inBranchRemoteStr )
lRemoteBranchRevStr = self . BranchRevGet ( inBranchNameStr = inBranchRemoteStr )
if lLocalBranchRevStr == lRemoteBranchRevStr :
if lLocalBranchRevStr == lRemoteBranchRevStr :
lIsLastBool = True
lIsLastBool = True
return lIsLastBool
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
""" Do some action to get the last revision
: param inBranchLocalStr : [ description ]
: param inBranchLocalStr : [ description ]
@ -108,8 +133,11 @@ class Git():
: param inBranchRemoteStr : [ description ]
: param inBranchRemoteStr : [ description ]
: type inBranchRemoteStr : str
: type inBranchRemoteStr : str
"""
"""
Orchestrator . OrchestratorLoggerGet ( ) . debug ( f " Managers.Git ( { self . mAbsPathStr } ): self.BranchRevLastGet has been init " )
# check if the correct revision
# check if the correct revision
lCMDResultStr = None
if self . BranchRevIsLast ( inBranchLocalStr = inBranchLocalStr , inBranchRemoteStr = inBranchRemoteStr ) == False :
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 ( )
lBranchNameCurrentStr = self . BranchNameGet ( )
# reset all changes in local folder
# reset all changes in local folder
self . Clear ( )
self . Clear ( )
@ -118,17 +146,10 @@ class Git():
# merge
# merge
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git merge { inBranchRemoteStr } "
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git merge { inBranchRemoteStr } "
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
if in BranchRestoreBool == True :
if in Previous BranchRestoreBool == True :
# checkout to the source branch which was
# checkout to the source branch which was
self . BranchCheckout ( inBranchNameStr = lBranchNameCurrentStr )
self . BranchCheckout ( inBranchNameStr = lBranchNameCurrentStr )
return lCMDResultStr
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
def BranchNameGet ( self ) - > str :
def BranchNameGet ( self ) - > str :
""" Get the current local branch name
""" Get the current local branch name
@ -141,10 +162,10 @@ class Git():
return lCMDResultStr
return lCMDResultStr
def BranchCheckout ( self , inBranchNameStr ) :
def BranchCheckout ( self , inBranchNameStr ) :
pass
self . Clear ( )
f " git clean -f -d " # Очистить от лишних файлов
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git checkout { inBranchNameStr } "
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
f " git checkout { inBranchNameStr } "
return lCMDResultStr
def Clear ( self ) :
def Clear ( self ) :
""" Clear the all changes in the local folder. Get up to the current revision
""" 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 и которые были изменены
# f"git reset --hard" # Откатить файлы, которые отслеживаются Git и которые были изменены
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git reset --hard "
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git reset --hard "
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
return lCMDResultStr
def Fetch ( self ) :
def Fetch ( self ) :
"""
"""
@ -167,6 +189,7 @@ class Git():
"""
"""
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git fetch "
lCMDStr = f " cd \" { self . mAbsPathUpperStr } \" && git fetch "
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
lCMDResultStr = self . __OSCMDShell__ ( inCMDStr = lCMDStr )
return lCMDResultStr
def GitExists ( inAgentHostNameStr : str , inAgentUserNameStr : str , inGitPathStr : str ) - > bool :
def GitExists ( inAgentHostNameStr : str , inAgentUserNameStr : str , inGitPathStr : str ) - > bool :
"""
"""