Created
March 13, 2020 07:04
-
-
Save kamilion/c59285a4aa0ac9de23a86c7af2b11694 to your computer and use it in GitHub Desktop.
hooky, a really terrible package manager shell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
__author__="[email protected]" | |
import simpleeval | |
import apt | |
import readline | |
import os | |
import atexit | |
HISTFILE = os.path.join(os.environ["HOME"], ".hooky", ".hooky-history") | |
def update_repos(): | |
print("Updating repositories") | |
def install(package): | |
print("Installing " + package) | |
pkg = cache[package] | |
pkg.mark_install() | |
res = cache.commit(fprogress, iprogress) | |
def remove(package): | |
print("Removing " + package) | |
pkg = cache[package] | |
pkg.mark_delete() | |
res = cache.commit(fprogress, iprogress) | |
def purge(package): | |
print("Purging " + package) | |
pkg = cache[package] | |
pkg.mark_delete(True) | |
res = cache.commit(fprogress, iprogress) | |
def main(): | |
try: | |
readline.read_history_file(HISTFILE) | |
except IOError: | |
pass | |
readline.parse_and_bind('tab: complete') | |
commander = simpleeval.SimpleEval() | |
commander.functions["update"] = update_repos | |
commander.functions["install"] = install | |
commander.functions["remove"] = remove | |
commander.functions["purge"] = purge | |
while True: | |
command_line = input("hooky> ") | |
if command_line in "exit quit bye".split(): | |
return | |
if command_line: | |
try: | |
commander.eval(command_line) | |
except simpleeval.FunctionNotDefined: | |
print("I don't know that token.") | |
cache = apt.Cache(apt.progress.text.OpProgress()) | |
fprogress = apt.progress.text.AcquireProgress() | |
iprogress = apt.progress.base.InstallProgress() | |
if __name__ == "__main__": | |
try: | |
main() | |
except EOFError: | |
print() | |
atexit.register(readline.write_history_file, HISTFILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment