Skip to content

Commit

Permalink
2.0.0β release
Browse files Browse the repository at this point in the history
  • Loading branch information
dotargz committed Nov 16, 2023
1 parent ebe45a6 commit fd6a578
Show file tree
Hide file tree
Showing 17 changed files with 649 additions and 192 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
dist/
super_env/
data/history.json
assets/data/*
*.pyc
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

14 changes: 14 additions & 0 deletions commands-to-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if command == "run" and WINDOWS == True:
if "".join(command_params).replace(" ", "") == "":
return_text = "Error: No file specified.\n"
else:
cmdToRun = "start " + " ".join(command_params)
cmd = " ".join(command_params)
print("Running: " + cmd)
os.system(cmdToRun)
if "-s" not in command_flags:
return_text = f"Running {cmd}...\n"
else:
return_text = ""
elif command == "tkz":
return_text = f"{str(self.advanced_tokenize(full_command))}\n"
340 changes: 166 additions & 174 deletions main.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a = Analysis(
['main.py'],
pathex=[],
binaries=[],
datas=[("assets", "assets")],
datas=[("assets", "assets"), ("programs", "programs")],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand Down
19 changes: 19 additions & 0 deletions programs/date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ------------------------------------------------------------------------------------
# Date.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------
import datetime

def run(system, command_params, command_flags):
return_text = ""
try:
now = datetime.datetime.now()
current_date = now.strftime("%a %m/%d/%y")
return_text += f"The current date is: {current_date}\n"
except PermissionError:
return_text += "Error: ICMP Permission denied.\n"
return return_text
13 changes: 13 additions & 0 deletions programs/echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ------------------------------------------------------------------------------------
# Echo.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------
def run(system, command_params, command_flags):
return_text = ""
for param in command_params:
return_text += param + " "
return return_text + "\n"
17 changes: 17 additions & 0 deletions programs/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ------------------------------------------------------------------------------------
# Help.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------

def run(system, command_params, command_flags):
return_text = ""
list_commands = ", ".join(system.programs)
list_system_commands = ", ".join(system.system_commands)
return_text += "Available commands: " + list_commands + "\n"
return_text += "Available system commands: " + list_system_commands + "\n"
return return_text

19 changes: 19 additions & 0 deletions programs/hostname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ------------------------------------------------------------------------------------
# Hostname.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------
import socket as s

def run(system, command_params, command_flags):
return_text = ""
try:
return_text += s.gethostname() + "\n"
except PermissionError:
return_text += "Error: ICMP Permission denied.\n"
except RuntimeError:
return_text += f"Error: Could not find hostname '{command_params[0]}'.\n"
return return_text
105 changes: 105 additions & 0 deletions programs/manual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# ------------------------------------------------------------------------------------
# manual.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# Lists the manual for a given program using the program's metadata fields.
# ------------------------------------------------------------------------------------

metadata = {
"name": "manual",
"description": "Lists the manual for a given program",
"version": "1.0.0",
"author": "dotargz",
"dependencies": [],
"superterm_version": ">=1.1.0",
"usage": "manual <program> [--verbose]",
"flags": {
"--verbose": "Display verbose manual with increased indentation",
},
"arguments": {
"<program>": "Name of the program to get the manual for",
},
"examples": [
{
"description": "Display manual for 'example_program'",
"command": "manual example_program",
},
{
"description": "Display verbose manual with increased indentation",
"command": "manual example_program --verbose",
},
],
"license": "MIT",
"repository": "https://github.com/dotargz/SuperTerm/",
"Issues": "https://github.com/dotargz/SuperTerm/issues",
"maintainers": [
{
"name": "dotargz",
"email": "[email protected]",
},
],
}


def toTitleCase(string):
def tTC(string):
if len(string) == 0:
return ""
if len(string) == 1:
return string.upper()
if string == "superterm":
return "SuperTerm"
tmp = string[0].upper() + string[1:].lower()
return tmp
# take a sentence and title case each word
tmp = string.split("_")
tmp = [tTC(word) for word in tmp]
return " ".join(tmp)

def run(system, command_params, command_flags):
indent = 0
def format_metadata(metadata, indent):
output = ""
if "--verbose" in command_flags:
for key, value in metadata.items():
if isinstance(value, dict):
output += f"{toTitleCase(key)}:\n{format_metadata(value, indent + 1)}"
elif isinstance(value, list):
output += f"{toTitleCase(key)}:\n"
for item in value:
if isinstance(item, dict):
output += format_metadata(item, indent + 1) + "\n"
elif isinstance(item, list):
output += f"{' ' * (indent+1)}- {item}\n"
elif isinstance(item, str):
output += f"{' ' * (indent+1)}- {item}\n"
else:
output += f"{' ' * indent}{toTitleCase(key)}: {value if value is not None else 'None'}\n"
else:
if "name" in metadata and "description" in metadata:
output += f"{toTitleCase(metadata['name'])}: {metadata['description']}\n"
if "usage" in metadata:
output += f"Usage: {metadata['usage']}\n"
return output

if len(command_params) == 0:
return "Error: No program specified\n"
program = command_params[0]

if program not in system.programs:
return f"Error: Program '{program}' not found\n"

program_metadata = system.get_program_metadata(program)

if program_metadata is None:
return f"'{program}' does not have any metadata associated with it.\n"

return_text = format_metadata(program_metadata, 0)

# if the program in question has metadata values that are not in this program's metadata, then it is likely that the program is setting its own metadata, and a warning should be displayed
if len(set(program_metadata.keys()) - set(metadata.keys())) > 0:
return_text += f"\nWarning: The program '{program}' is setting non-standard metadata values.\nWarning: This program may not be compatible with this version of SuperTerm.\n"

return return_text

41 changes: 41 additions & 0 deletions programs/nslookup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ------------------------------------------------------------------------------------
# NSlookup.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
# ------------------------------------------------------------------------------------
import socket as s

metadata = {
"name": "nslookup",
"description": "Lookup the IP address of a hostname.",
"version": "1.0.0",
"author": "dotargz",
"dependencies": ["socket"],
"superterm_version": ">=1.0.0",
"usage": "nslookup <hostname>"
}

def pad(tmp):
max_length = 15
tmp += " " * (max_length - len(tmp))
return tmp

def run(system, command_params, command_flags):
try:
host = command_params[0]
ipv4 = s.gethostbyname(host)
ipv6_data = s.getaddrinfo(host, "7") # echo port
result = ""
result += pad('Server:') + f"{ipv4}\n"
result += pad('Address:') + f"{ipv4}#7\n"
result += f"\n"
result += f"Non-authoritative answer:\n"
result += pad('Name:') + f"{host.lower()}\n"
result += pad('Address:') + f"{ipv4}\n"
result += pad('Name:') + f"{host.lower()}\n"
result += pad('Address:') + f"{str(ipv6_data[0][4][0])}\n"
return result
except IndexError:
return "Error: No url specified\n"
except s.gaierror:
return f"Error: Could not find hostname '{command_params[0]}'.\n"
24 changes: 24 additions & 0 deletions programs/ping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ------------------------------------------------------------------------------------
# Ping.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------
import pythonping

def run(system, command_params, command_flags):
return_text = ""
try:
ping_list = pythonping.ping(
command_params[0], verbose=True, size=2)
for response in ping_list:
return_text += f"{response}\n"
except PermissionError:
return_text += "Error: ICMP Permission denied.\n"
except RuntimeError:
return_text += f"Error: Could not find hostname '{command_params[0]}'.\n"
except IndexError:
return_text += "Error: No hostname specified.\n"
return return_text
96 changes: 96 additions & 0 deletions programs/stenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ------------------------------------------------------------------------------------
# STenv.py for SuperTerm
# Author: dotargz
# Date: 2023-11-14
#
# WARNING: Legacy SuperTerm code, uses the return_text paradigm
# When creating new programs, you may simply return a string and it will be printed
# ------------------------------------------------------------------------------------
import json

metadata = {
"name": "stenv",
"description": "Set, get, and delete environment variables.",
"version": "1.0.0",
"author": "dotargz",
"dependencies": ['json'],
"superterm_version": ">=2.0.0",
"usage": "stenv <set|get|del|list> [key] [value]",
"flags": {
"--all": "Delete all environment variables when using 'del'",
},
"arguments": {
"set": "Set an environment variable",
"get": "Get an environment variable",
"del": "Delete an environment variable",
"list": "List all environment variables",
},
"examples": [
{
"description": "Set environment variable 'test' to 'value'",
"command": "stenv set test value",
},
{
"description": "Get environment variable 'test'",
"command": "stenv get test",
},
],
"license": "MIT",
"repository": "https://github.com/dotargz/SuperTerm/",
"Issues": "https://github.com/dotargz/SuperTerm/issues",
"maintainers": [
{
"name": "dotargz",
"email": "[email protected]",
},
],
}

# This program is used to set, get, and delete environment variables.
def run(system, command_params, command_flags):
return_text = ""
if len(command_params) == 0:
return_text = "Error: No parameter specified.\n"
else:
if command_params[0] == "set":
if len(command_params) == 3:
system.alias.set_env(command_params[1], command_params[2])
return_text = f"Set environment variable '{command_params[1]}' to '{command_params[2]}'\n"
else:
return_text = "Error: Invalid syntax.\n"
elif command_params[0] == "get":
if len(command_params) == 2:
env = system.alias.get_env(command_params[1])
if env == None:
return_text = f"Error: Environment variable '{command_params[1]}' not found.\n"
else:
return_text = f"Environment variable '{command_params[1]}' is set to '{env}'\n"
else:
return_text = "Error: Invalid syntax.\n"
elif command_params[0] == "del":
if len(command_params) == 2:
env = system.alias.get_env(command_params[1])
if env == None:
return_text = f"Error: Environment variable '{command_params[1]}' not found.\n"
else:
system.alias.set_env(command_params[1], None, True)
return_text = f"Environment variable '{command_params[1]}' deleted.\n"
elif len(command_flags) == 1:
if command_flags[0] == "--all":
with open(system.alias.resource_path("assets/data/environment.json"), "w") as f:
json.dump({}, f)
return_text = "All environment variables deleted.\n"
else:
return_text = "Error: Invalid syntax.\n"
elif command_params[0] == "list":
try:
with open(system.alias.resource_path("assets/data/environment.json"), "r") as f:
env = json.load(f)
for key in env:
return_text += f"{key}: {env[key]}\n"
except Exception as e:
return_text = "Error: Could not load environment variables.\n"
return_text += f"Error Message: {e}\n"
else:
return_text = "Error: Invalid parameter.\n"
return return_text
Loading

0 comments on commit fd6a578

Please sign in to comment.