printers-tests/main.py

44 lines
1.0 KiB
Python
Raw Permalink Normal View History

import subprocess
# list_files = subprocess.run(["ls", "-l"])
# print("The exit code was: %d" % list_files.returncode)
def remove_last_line(s):
return s[:s.rfind('\n')]
def root_user_error():
print("You is root user. Exit")
exit(0)
def return_current_user():
user = subprocess.run(["whoami"], stdout=subprocess.PIPE, text=True)
user.stdout = remove_last_line(user.stdout)
return(user.stdout)
# def return_home_dir():
# user_directory = subprocess.run(["ls"], stdout=subprocess.PIPE, text=True, input="~")
# user_directory.stdout = remove_last_line(user_directory.stdout)
def this_command_exist_or_not(command):
result = subprocess.run([command], stdout=subprocess.DEVNULL)
if result.stdout == "":
return()
def main():
# this_command_exist_or_not("lpinfo")
# install packages from packagelist without python
user = return_current_user()
if user == "root":
root_user_error()
print("You are not root")
# get printers names
if __name__ == '__main__':
main()