Skip to content

Commit

Permalink
Added setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniDiazTech committed Apr 16, 2021
1 parent 757e4a0 commit d4f9fb1
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 19 deletions.
Empty file added __init__.py
Empty file.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
@hook.subscribe.startup_once
def start_once():
home = os.path.expanduser('~')
subprocess.call([home + '/.config/qtile/autostart.sh'])
subprocess.call([home + '/.local/bin/autostart'])

@hook.subscribe.client_new
def dialogs(window):
Expand Down
File renamed without changes.
150 changes: 132 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Os level operations
import os
from getpass import getuser

# Determinates if the program is installed
from shutil import which

# Get the OS I'm in
import platform
Expand All @@ -11,17 +15,30 @@

def print_program_welcome():

row = "=" * 35

row = "=" * 55

sep = "||"

welcome = "SETUP SCRIPT OF DANIEL'S QTILE CONFIG".center(len(row) - len(sep) * 2)

welcome = sep + welcome + sep


print(row)

print("")

print("SETUP SCRIPT OF DANIEL'S QTILE CONFIG".center(len(row), "*"))

print(welcome)

print("")

print(row)
print(row + "\n")

print(f"Hi there {getuser()}, you are about to setup Qtile".center(len(row)))

print("\n" + row)


def print_current_dir():
print(f"Currently you are in {os.getcwd()} directory")
Expand Down Expand Up @@ -66,7 +83,6 @@ def check_local_folder_exists():
return os.path.exists(local)



def create_local_install_folder(local_bin):
"""
Creates local bin folder
Expand All @@ -80,32 +96,130 @@ def create_local_install_folder(local_bin):
except OSError:
raise OSError(f"Creation of the directory {local_bin} failed")
else:
print (f"Successfully created the directory {local_bin}")
print(f"Successfully created the directory {local_bin}")

def get_response(message="yes/no"):
"""
returns -> bool
"""
while True:
response = input(message).lower()

if response == "yes":
return True
elif response == "no":
return False
else:
print("\nSorry your response must be yes or no\n")
continue


LOCAL_BIN = get_local_bin(get_home_path())

def link_scripts(path):

path = os.path.abspath(path)
if not os.path.exists(path):
raise OSError("Sorry that path doesn't exist")


os.chdir(path)

i = 0


for file_ in os.listdir(path):
file_path = os.path.abspath(file_)

file_name = file_.split(".")[0]

link_path = LOCAL_BIN + f"/{file_name}"

if os.path.exists(link_path):
print("You have already in path", file_name)
continue

os.link(file_path, link_path)

def check_response(response):
i += 1

return f"Linked {i} files to .local/bin"


def get_dependencies(software_path="software.txt"):
"""software_path -> path of software.txt
response = response.lower()
returns list of dependencies
"""

if response == "yes":
return True
elif response == "no":
return False
else:
return "repeat"
if not os.path.exists(software_path):
print(f"The file {software_path} wasn't found. Please clone again or provide one")

if get_response("Continue without dependencies warnings? [yes/no]"):
print("Dependencies won't be shown")
return None
else:
print("Clone again or provide a file.")
exit()

software = []

def main():
with open(software_path, "r") as file_:
for line in file_:
software.append(line.strip())

return software

def check_dependencies(dependencies=None):
"""dependencies -> list
returns -> str programs that aren't installed
"""
if dependencies is None:
return ""

not_installed = []

for program in dependencies:
if which(program) is not None:
continue

not_installed.append(program)

first_row = "The following software is not installed, some scripts may not work\n"

if not_installed:
return first_row + "\n".join(not_installed)
else:
return ""

def main():

print_program_welcome()

if not get_correct_os():
raise OSError("Sorry Qtile is only supported in Linux")

if not check_local_folder_exists():
print(".local/bin folder don't detected")
print("")
response = input("Do you want to create that directory [yes, no]>> ")
print("\n.local/bin folder doesn't exists\n")

response = get_response(message="Do you want to create that directory [yes, no] >> ")

if not response:
print("Setup can't continue if .local/bin doesn't exists")
print("Rerun the script or set up the scripts manually")
exit()

print("Creating .local/bin/folder")
create_local_install_folder(LOCAL_BIN)


dependencies = get_dependencies()
scripts_path = "./scripts"
print(check_dependencies(dependencies=dependencies))
print(link_scripts(path=scripts_path))


if __name__ == "__main__":
main()

5 changes: 5 additions & 0 deletions software.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
picom
nitrogen
megasync
xfce4-clipman
playerctl

0 comments on commit d4f9fb1

Please sign in to comment.