From a455a3eab403b461729041d2d837ec456295dfd2 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Mon, 22 Jun 2020 23:21:32 +0500 Subject: [PATCH] execute git commands from the repo folder --- plogical/processUtilities.py | 18 +++++++++++++----- websiteFunctions/website.py | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index fdd5e6990..84cb278ed 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -179,7 +179,7 @@ class ProcessUtilities(multi.Thread): time.sleep(2) @staticmethod - def sendCommand(command, user=None): + def sendCommand(command, user=None, dir=None): try: ret = ProcessUtilities.setupUDSConnection() @@ -201,12 +201,20 @@ class ProcessUtilities(multi.Thread): if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(ProcessUtilities.token + command) - sock.sendall((ProcessUtilities.token + command).encode('utf-8')) + if dir == None: + sock.sendall((ProcessUtilities.token + command).encode('utf-8')) + else: + command = '%s-d %s %s' % (ProcessUtilities.token, dir, command) + sock.sendall(command.encode('utf-8')) else: - command = '%s-u %s %s' % (ProcessUtilities.token, user, command) + if dir == None: + command = '%s-u %s %s' % (ProcessUtilities.token, user, command) + else: + command = '%s-u %s -d %s %s' % (ProcessUtilities.token, user, dir, command) command = command.replace('sudo', '') if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(command) + sock.sendall(command.encode('utf-8')) data = "" @@ -250,7 +258,7 @@ class ProcessUtilities(multi.Thread): return 0 @staticmethod - def outputExecutioner(command, user=None, shell = None): + def outputExecutioner(command, user=None, shell = None, dir = None): try: if getpass.getuser() == 'root': if os.path.exists(ProcessUtilities.debugPath): @@ -264,7 +272,7 @@ class ProcessUtilities(multi.Thread): if type(command) == list: command = " ".join(command) - return ProcessUtilities.sendCommand(command, user)[:-1] + return ProcessUtilities.sendCommand(command, user, dir)[:-1] except BaseException as msg: logging.writeToFile(str(msg) + "[outputExecutioner:188]") diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index 319908436..6cfd0a546 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -4208,14 +4208,14 @@ StrictHostKeyChecking no GitLogs(owner=self.web, type='INFO', message='Running: %s' % (command)).save() - result = ProcessUtilities.outputExecutioner(command, self.web.externalApp) + result = ProcessUtilities.outputExecutioner(command, self.web.externalApp, None, self.folder) GitLogs(owner=self.web, type='INFO', message='Result: %s' % (result)).save() else: GitLogs(owner=self.web, type='INFO', message='Running: %s' % (gitConf['commands'])).save() - result = ProcessUtilities.outputExecutioner(gitConf['commands'], self.web.externalApp) + result = ProcessUtilities.outputExecutioner(gitConf['commands'], self.web.externalApp, None, self.folder) GitLogs(owner=self.web, type='INFO', message='Result: %s' % (result)).save()