mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-11-09 22:41:03 +01:00
Optimized ressources
This commit is contained in:
parent
d9d6c8060a
commit
c38d517ad3
@ -4,22 +4,23 @@ import sys
|
||||
import time
|
||||
|
||||
def run_command(command):
|
||||
process = None
|
||||
try:
|
||||
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
output = []
|
||||
|
||||
# Iterate over the output lines
|
||||
for line in iter(process.stdout.readline, b''):
|
||||
decoded_line = line.decode()
|
||||
output.append(decoded_line)
|
||||
sys.stdout.write(decoded_line)
|
||||
|
||||
process.stdout.close()
|
||||
return_code = process.wait()
|
||||
if return_code:
|
||||
# Join the output list to create a single string
|
||||
full_output = ''.join(output)
|
||||
raise subprocess.CalledProcessError(return_code, command, output=full_output.encode())
|
||||
|
||||
finally:
|
||||
if process and process.stdout:
|
||||
process.stdout.close()
|
||||
|
||||
def git_pull(directory):
|
||||
os.chdir(directory)
|
||||
|
Loading…
Reference in New Issue
Block a user