mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-06-30 04:20:43 +00:00
Split lib.py into util Package
This commit is contained in:
parent
08c0933b27
commit
aaadf596ba
10 changed files with 579 additions and 548 deletions
53
util/Command.py
Normal file
53
util/Command.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/bin/python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def execute(command, use_os=False):
|
||||
'''Execute bash command
|
||||
|
||||
Arguments:
|
||||
command {str} -- full command
|
||||
|
||||
Keyword Arguments:
|
||||
os {bool} -- should the os module be used instead of subprocess (default: {False})
|
||||
|
||||
Returns:
|
||||
int/bool -- returncode/True if os is used
|
||||
'''
|
||||
if not use_os:
|
||||
command = command.split(' ')
|
||||
return subprocess.call(command)
|
||||
else:
|
||||
os.system(command)
|
||||
return True
|
||||
|
||||
|
||||
def get_output(command):
|
||||
'''Get standard output of command
|
||||
|
||||
Arguments:
|
||||
command {str} -- full command
|
||||
|
||||
Returns:
|
||||
str -- stdout
|
||||
'''
|
||||
command = command.split(' ')
|
||||
return subprocess.run(command,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||
|
||||
|
||||
def get_return_code(command):
|
||||
'''Get return code of command
|
||||
|
||||
Arguments:
|
||||
command {str} -- full command
|
||||
|
||||
Returns:
|
||||
int -- returncode
|
||||
'''
|
||||
command = command.split(' ')
|
||||
return subprocess.run(command,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE).returncode
|
Loading…
Add table
Add a link
Reference in a new issue