Skip to content

Commit

Permalink
Version 1.5.1
Browse files Browse the repository at this point in the history
Version 1.5.1
  • Loading branch information
hammy275 authored Apr 12, 2020
2 parents 7eb1d28 + f546e7c commit 23d48ec
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 35 deletions.
8 changes: 4 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

###VERSIONS###

version = "1.5.0"
prog_internal_version = 82
file_version = 13
version = "1.5.1"
prog_internal_version = 87
file_version = 14

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

Expand Down Expand Up @@ -76,7 +76,7 @@ def read_config(key):
try:
return db["options"][key]
except KeyError:
if key in ["Verbose", "AutoInstall", "SkipQuestions"]:
if key in ["Verbose", "AutoInstall", "SkipQuestions", "UpdateURLPrograms"]:
return False
elif key == "ShellFile":
return get_shell_file()
Expand Down
54 changes: 54 additions & 0 deletions generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,60 @@
except ImportError:
pass # This will be caught by tarstall.py, let's not worry about it here.


def file_browser(root_dir):
"""File Browser.
File browser for CLI that allows the choosing of files in folders.
Args:
root_dir (str): Path to top directory. Anything above this will be unaccessible
Returns:
str: path/to/file/from/root_dir/file.txt (Path to the selected file from root_dir (NOT FROM / !!!!)
"""
root_dir = config.full(root_dir)
os.chdir(root_dir)
all_files = os.listdir()
folders = []
files = []
for f in all_files:
if os.path.isdir("./{}".format(f)):
folders.append(f)
else:
files.append(f)
msg = "Folders: " + ' '.join(folders) + "\n" + "Files: " + ' '.join(files)
file_chosen = 'Cool fact. This line was originally written on line 163.'
current_folder_path = []
while file_chosen not in files:
all_files = os.listdir()
folders = []
files = []
for f in all_files:
if os.path.isdir("./{}".format(f)):
folders.append(f)
else:
files.append(f)
msg = "Folders: " + ' '.join(folders) + "\n" + "Files: " + ' '.join(files)
file_chosen = input(msg + '\n\nPlease enter a file listed above. If you would like to cancel, type exit. If you would like to go up a directory, type "..": ')
if file_chosen == "exit":
return None
elif file_chosen in folders:
os.chdir(config.full("./{}".format(file_chosen)))
current_folder_path.append(file_chosen)
elif file_chosen == "..":
if os.getcwd() == root_dir:
pprint("\nCan't go up a directory!\n")
else:
os.chdir(config.full(".."))
if current_folder_path != []:
extra_slash = "/"
else:
extra_slash = ""
return "/".join(current_folder_path) + extra_slash + file_chosen


def ask(question):
"""Get Any User Input.
Expand Down
38 changes: 28 additions & 10 deletions prog_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ def update_script(program, script_path):
script_path (str): Path to script to run as an/after update.
Returns:
str: "Bad path" if the path doesn't exist, "Success" otherwise.
str: "Bad path" if the path doesn't exist, "Success" on success, and "Wiped" on clear.
"""
if script_path == "":
config.db["programs"][program]["post_upgrade_script"] = None
return "Wiped"
if not config.exists(config.full(script_path)):
return "Bad path"
config.db["programs"][program]["post_upgrade_script"] = config.full(script_path)
Expand Down Expand Up @@ -217,7 +220,9 @@ def update_programs():
statuses = {}
generic.progress(progress)
for p in config.db["programs"].keys():
if config.db["programs"][p]["git_installed"] or config.db["programs"][p]["post_upgrade_script"] or config.db["programs"][p]["update_url"]:
if not config.db["programs"][p]["update_url"] and (config.db["programs"][p]["git_installed"] or config.db["programs"][p]["post_upgrade_script"]):
statuses[p] = update_program(p)
elif (config.db["programs"][p]["update_url"] and config.read_config("UpdateURLPrograms")):
statuses[p] = update_program(p)
progress += increment
generic.progress(progress)
Expand Down Expand Up @@ -346,6 +351,10 @@ def tarstall_startup(start_fts=False, del_lock=False, old_upgrade=False):
for program in config.db["programs"]:
config.db["programs"][program]["has_path"] = False
config.db["programs"][program]["binlinks"] = []

elif file_version == 13:
config.vprint("Adding 'UpdateURLPrograms' to config database.")
config.db["options"]["UpdateURLPrograms"] = False

config.db["version"]["file_version"] += 1
file_version = get_file_version('file')
Expand Down Expand Up @@ -450,7 +459,8 @@ def create_db():
"Verbose": False,
"AutoInstall": False,
"ShellFile": config.get_shell_file(),
"SkipQuestions": False
"SkipQuestions": False,
"UpdateURLPrograms": False
},
"version": {
"file_version": config.file_version,
Expand Down Expand Up @@ -579,7 +589,11 @@ def create_desktop(program_internal_name, name, program_file, comment="", should
if program_internal_name is not None:
exec_path = config.full("~/.tarstall/bin/{}/{}".format(program_internal_name, program_file))
path = config.full("~/.tarstall/bin/{}/".format(program_internal_name))
desktop_name = "{}-{}".format(program_file, program_internal_name)
file_name = program_file
if "/" in file_name:
file_name += ".tar.gz"
file_name = config.name(file_name)
desktop_name = "{}-{}".format(file_name, program_internal_name)
else:
exec_path = config.full(program_file)
desktop_name = name
Expand Down Expand Up @@ -673,13 +687,17 @@ def add_binlink(file_chosen, program_internal_name):
str: "Added" or "Already there"
"""
if file_chosen in config.db["programs"][program_internal_name]["binlinks"]:
name = file_chosen
if "/" in name:
name += ".tar.gz"
name = config.name(name)
if name in config.db["programs"][program_internal_name]["binlinks"]:
return "Already there"
line_to_add = 'alias ' + file_chosen + "='cd " + config.full('~/.tarstall/bin/' + program_internal_name) + \
'/ && ./' + file_chosen + "' # " + program_internal_name + "\n"
line_to_add = '\nalias ' + name + "='cd " + config.full('~/.tarstall/bin/' + program_internal_name) + \
'/ && ./' + file_chosen + "' # " + program_internal_name
config.vprint("Adding alias to bashrc")
config.add_line(line_to_add, "~/.tarstall/.bashrc")
config.db["programs"][program_internal_name]["binlinks"].append(file_chosen)
config.db["programs"][program_internal_name]["binlinks"].append(name)
config.write_db()
return "Added"

Expand All @@ -699,7 +717,7 @@ def pathify(program_internal_name):
if config.db["programs"][program_internal_name]["has_path"]:
return "Already there"
config.vprint('Adding program to PATH')
line_to_write = "export PATH=$PATH:~/.tarstall/bin/" + program_internal_name + ' # ' + program_internal_name + '\n'
line_to_write = "\nexport PATH=$PATH:~/.tarstall/bin/" + program_internal_name + ' # ' + program_internal_name
config.add_line(line_to_write, "~/.tarstall/.bashrc")
config.db["programs"][program_internal_name]["has_path"] = True
return "Complete"
Expand Down Expand Up @@ -1020,7 +1038,7 @@ def install(program, overwrite=False, reinstall=False, show_progress=True):
elif len(os.listdir()) == 1 and os.path.isdir(os.listdir()[0]):
config.vprint("Single folder detected!")
folder = os.listdir()[0]
source = config.full("/tmp/tarstall-temp/" + folder)
source = config.full("/tmp/tarstall-temp/" + folder) + '/'
dest = config.full("~/.tarstall/bin/" + program_internal_name) + '/'
else:
config.vprint('Folder in folder not detected!')
Expand Down
34 changes: 16 additions & 18 deletions tarstall_execs/tarstall
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,14 @@ v - Enable/disable verbose mode, showing more output when tarstall commands are
b - Swap branches in tarstall. Allows you to get updates sooner at the cost of possible bugs. Current branch: {b}.
m - Whether or not to use the GUI for tarstall. Currently {gui}.
s - Whether or not to skip ending questions and confirmations. Currently {skip}.
u - Whether or not to update programs that have a URL attatched to them for updating. Currently {url}.
e - Exit tarstall""".format(
au=generic.endi(config.read_config("AutoInstall")), v=generic.endi(config.read_config("Verbose")),
b=config.db["version"]["branch"], gui=generic.endi(config.read_config("Mode") == "gui"),
skip=generic.endi(config.read_config("SkipQuestions"))
skip=generic.endi(config.read_config("SkipQuestions")), url=generic.endi(config.read_config("UpdateURLPrograms"))
)
option = generic.get_input(msg, ['au', 'v', 'b', 'm', 's', 'e'], 'e',
["Autoupdate", "Verbosity", "Change Branches", "Change Interaction Mode", "Skip Questions", "Exit"])
option = generic.get_input(msg, ['au', 'v', 'b', 'm', 's', 'u', 'e'], 'e',
["Autoupdate", "Verbosity", "Change Branches", "Change Interaction Mode", "Skip Questions", "Update URL-Attatched Programs", "Exit"])
if option == 'au':
if not prog_manage.can_update:
generic.pprint("requests isn't installed, so AutoInstall cannot be enabled!")
Expand All @@ -292,6 +293,8 @@ e - Exit tarstall""".format(
key = None
elif option == 's':
key = "SkipQuestions"
elif option == 'u':
key = "UpdateURLPrograms"
elif option == 'e':
return
if key is not None:
Expand Down Expand Up @@ -322,13 +325,9 @@ def binlink(program):
"""
yn = 'y'
while yn != 'n':
files = os.listdir(config.full('~/.tarstall/bin/' + program + '/'))
generic.pprint(' '.join(files))
file_chosen = 'Cool fact. This line was originally written on line 163.'
while file_chosen not in files:
file_chosen = input('Please enter a file listed above. If you would like to cancel, type exit: ')
if file_chosen == "exit":
return
file_chosen = generic.file_browser('~/.tarstall/bin/' + program + '/')
if file_chosen is None:
return
status = prog_manage.add_binlink(file_chosen, program)
if status == "Already there":
generic.pprint("Binlink not added since it already exists!")
Expand All @@ -342,13 +341,9 @@ def desktop_wizard(program):
program (str): Program to create .desktop file of
"""
files = os.listdir(config.full('~/.tarstall/bin/' + program + '/'))
generic.pprint(' '.join(files))
program_file = '/Placeholder/'
while program_file not in files:
program_file = input('Please enter a file listed above. If you would like to cancel, type exit: ')
if program_file == "exit":
return
program_file = generic.file_browser(config.full('~/.tarstall/bin/' + program + '/'))
if program_file is None:
return
comment = "/"
while not comment.replace(" ", "").isalnum() and comment != "":
comment = input("Please input a comment for the application: ")
Expand Down Expand Up @@ -538,13 +533,16 @@ E - Exit program management""".format(program=program, git=git_msg, g=g_msg, us=
msg = """
Please input the path to a script you would like to run to upgrade an installed program.
Note: The script will be run inside your program's directory.
Warning: The shell must be specified at the top of the file (ie. "#!/bin/sh)
Leave blank to de-link the script from the program.
Warning: The shell must be specified at the top of the file (ie. "#!/bin/sh")
"""
status = prog_manage.update_script(program, generic.ask_file(msg))
if status == "Success":
generic.pprint("Update script added successfully!")
elif status == "Bad path":
generic.pprint("Script specified does not exist!")
elif status == "Wiped":
generic.pprint("Successfully removed post upgrade script.")
elif option == 'e':
break

Expand Down
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def test_get_db():
"Verbose": False,
"AutoInstall": False,
"ShellFile": config.get_shell_file(),
"SkipQuestions": False
"SkipQuestions": False,
"UpdateURLPrograms": False
},
"version": {
"file_version": config.file_version,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_prog_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def test_create_db():
"Verbose": False,
"AutoInstall": False,
"ShellFile": config.get_shell_file(),
"SkipQuestions": False
"SkipQuestions": False,
"UpdateURLPrograms": False
},
"version": {
"file_version": config.file_version,
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13.82
14.87

0 comments on commit 23d48ec

Please sign in to comment.