Skip to content

Commit

Permalink
Merge pull request #36 from hammy3502/beta
Browse files Browse the repository at this point in the history
Version 1.6.0
  • Loading branch information
hammy275 authored Jul 8, 2020
2 parents c0e1ef5 + a376e5a commit 872c256
Show file tree
Hide file tree
Showing 11 changed files with 735 additions and 208 deletions.
43 changes: 35 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

###VERSIONS###

version = "1.5.3"
prog_internal_version = 94
file_version = 15
version = "1.6.0"
prog_internal_version = 108
file_version = 17

#############

Expand Down Expand Up @@ -59,11 +59,36 @@ def get_shell_file():
elif "zsh" in shell:
vprint("Auto-detected zsh")
return ".zshrc"
elif "fish" in shell:
vprint("Auto-detected fish")
return ".config/fish/config.fish"
else:
vprint("Couldn't auto-detect shell environment!")
return None


def get_shell_path():
"""Get Shell Path.
Attempts to automatically obtain the file used by the user's shell for PATH,
variable exporting, etc.
Returns:
str: Full path to the shell file.
"""
shell_file = get_shell_file()
if shell_file:
if shell_file == ".bashrc":
return full("~/.bashrc")
elif shell_file == ".zshrc":
return full("~/.zshrc")
elif "fish" in shell_file:
return full("~/.config/fish/config.fish")
else:
return None


def read_config(key):
"""Read config value.
Expand All @@ -78,7 +103,7 @@ def read_config(key):
except KeyError:
if key in ["Verbose", "AutoInstall", "SkipQuestions", "UpdateURLPrograms"]:
return False
elif key in ["PressEnterKey"]:
elif key in ["PressEnterKey", "WarnMissingDeps"]:
return True
elif key == "ShellFile":
return get_shell_file()
Expand Down Expand Up @@ -214,7 +239,7 @@ def name(program):
"""
program_internal_name = re.sub(r'.*/', '/', program)
extension_length = len(extension(program))
program_internal_name = program_internal_name[1:(len(program_internal_name) - extension_length)]
program_internal_name = program_internal_name[program_internal_name.find('/')+1:(len(program_internal_name) - extension_length)]
return program_internal_name


Expand Down Expand Up @@ -250,9 +275,11 @@ def extension(program):
return program[-3:].lower()
elif program[-4:].lower() in ['.zip', '.rar', '.git']:
return program[-4:]
else:
# Default to returning the last 7 characters
elif program[-7:].lower() in ['.tar.gz', '.tar.xz']:
return program[-7:]
else:
# Default to returning everything after the last .
return program[program.rfind("."):]


def exists(file_name):
Expand Down Expand Up @@ -451,7 +478,7 @@ def char_check(name):
}
"programs": {
"package": {
"git_installed": False,
"install_type": "default",
"post_upgrade_script": None,
"desktops": [
"desktop_file_name"
Expand Down
48 changes: 44 additions & 4 deletions generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,48 @@ def ask_file(question):
return values["answer"]


def get_input(question, options, default, gui_labels=[]):
def easy_get_action(options, replacements=[]):
"""Easy get_input()
options should contain a list of dictionaries, each representing an option.
Dictionary should be layed out as such:
{
"shorthand": "b", # One or two letters representing the option (the selector in CLI mode)
"gui-label": "Create binlinks", # The label for the option to show in the GUI
"description": "Create binlinks for {program}", # The description of the action being performed
"is-default": False # Optional. If specified and set to True, will be the default option on an enter press.*
}
*: Note: If multiple parameters are passed in as default, only the first one will actually be the default.
Note: If default is not specified for any options, the last option will be the default.
Args:
options (dict[]): See dictionary format above.
replacements (dict[]): The key should be what you want to replace and the value be what you're replacing with.
"""
gui_labels = []
options_list = []
default = None
msg = "Select an option:"
for option in options:
selector = option["shorthand"].lower()
try:
is_default = option["is-default"]
except KeyError:
is_default = False
if is_default or (default is None and option is options[len(options) - 1]):
default = option["shorthand"]
selector = selector.upper()
gui_labels.append(option["gui-label"])
options_list.append(option["shorthand"])
msg += "\n" + selector + " - " + option["description"]
for replacement in replacements:
msg = msg.replace(list(replacement.keys())[0], list(replacement.values())[0])
return get_input(msg, options_list, default, gui_labels, True)


def get_input(question, options, default, gui_labels=[], from_easy=False):
"""Get User Input.
Get user input, except make sure the input provided matches one of the options we're looking for
Expand All @@ -154,7 +195,7 @@ def get_input(question, options, default, gui_labels=[]):
if config.mode == "cli":
options_form = list(options) # Otherwise, Python would "link" options_form with options
options_form[options_form.index(default)] = options_form[options_form.index(default)].upper()
if len(options) > 3:
if len(options) > 3 or from_easy:
question += "\n[" + "/".join(options_form) + "]"
else:
question += " [" + "/".join(options_form) + "]"
Expand Down Expand Up @@ -209,8 +250,7 @@ def endi(state):
"""
if state:
return "enabled"
else:
return "disabled"
return "disabled"


def pprint(st, title="tarstall-gui"):
Expand Down
19 changes: 11 additions & 8 deletions install_tarstall
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def setup():
# Checks
status("Checking for anything missing for tarstall setup")
supported_package_managers = ["apt", "apt-get", "dnf", "pacman"]
supported_shells = ["bash", "zsh"]
supported_shells = ["bash", "zsh", "fish"]
if which("sudo") is None:
status("Please install 'sudo'!")
sys.exit(1)
Expand All @@ -107,6 +107,7 @@ def setup():
if sshell in shell:
shell_supported = True
break
msg = "All of the checks passed!"
if not shell_supported:
msg = "WARNING: YOUR SHELL IS NOT SUPPORTED!\n\nYOU WILL HAVE TO MANUALLY ADD ~/.tarstall/tarstall_execs TO YOUR PATH, " \
"AND ANY PATH/BINLINK FUNCTIONS WILL NOT WORK!\nWOULD YOU LIKE TO PROCEED WITH INSTALLATION ANYWAYS?"
Expand All @@ -115,15 +116,17 @@ def setup():
if should_proceed.lower() != "yes":
status("Installation cancelled!")
sys.exit(1)
print("All of the checks passed!\n\n\n")
msg = "All of the checks besides the shell check passed, while the shell check was skipped by the user!"
print("{}\n\n\n".format(msg))

# User information
status("Welcome!\nThis installer is going to install tarstall! You'll need to enter your sudo password at some points. " +
"This will use your distro's package manager along with pip to install the dependencies required for tarstall!")
cancel = input("When you're ready to start installation, press ENTER! If you would like to cancel, type 'c', then press ENTER!")
if cancel.lower() == 'c':
status("Cancelling tarstall setup...")
sys.exit()
if not os.path.isfile("/tmp/dont-ask-me"):
status("Welcome!\nThis installer is going to install tarstall! You'll need to enter your sudo password at some points. " +
"This will use your distro's package manager along with pip to install the dependencies required for tarstall!")
cancel = input("When you're ready to start installation, press ENTER! If you would like to cancel, type 'c', then press ENTER!")
if cancel.lower() == 'c':
status("Cancelling tarstall setup...")
sys.exit()

# Install requirements obtained through package manager
status("Installing tarstall's package requirements")
Expand Down
Loading

0 comments on commit 872c256

Please sign in to comment.