Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
kotazzz committed Jan 31, 2021
1 parent 8d80cb5 commit f6a5645
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 797 deletions.
60 changes: 29 additions & 31 deletions NewLifeUtils/CustomShellModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"same_command": [
"Console commands with the same names were registered.",
"Here is a list of registered console commands (their names):",
"{list}"
]
"{list}",
],
}

create_config("shell_translation", "lang.yml", "shell", default_translation)
Expand All @@ -31,9 +31,9 @@

class Shell(object):
def __init__(
self,
name=translation.default_cmd_name,
about=translation.default_cmd_description,
self,
name=translation.default_cmd_name,
about=translation.default_cmd_description,
):
self.run_state = "init"
self.cmdname = name
Expand All @@ -57,9 +57,7 @@ def __init__(
new_rea_pattern="{cyan}[{time}] {lightcyan}{tag}{snow} : {mediumslateblue}{readed}",
)

@self.register_command(
"exit", ["quit"], translation.exit_description, [], []
)
@self.register_command("exit", ["quit"], translation.exit_description, [], [])
def exit_(console):
console.run_state = "quit"

Expand Down Expand Up @@ -105,10 +103,10 @@ class CLR:
f'{CLR.SOPT}[{"] [".join(command["optional"])}]{CLR.R} '
)
helpPage += (
f'\t{CLR.CMD}{command["command"]}\n'
+ f'\t\t{CLR.CMDDSK}Description {CLR.R}: {CLR.CMDDSK}{command["description"]}\n'
+ f'\t\t{CLR.ALS}Aliases {CLR.R}: {CLR.ALSTXT}{", ".join(command["aliases"])}\n'
+ f"\t\t{CLR.STTL}Usage {CLR.R}: {syntax}{CLR.R}\n"
f'\t{CLR.CMD}{command["command"]}\n'
+ f'\t\t{CLR.CMDDSK}Description {CLR.R}: {CLR.CMDDSK}{command["description"]}\n'
+ f'\t\t{CLR.ALS}Aliases {CLR.R}: {CLR.ALSTXT}{", ".join(command["aliases"])}\n'
+ f"\t\t{CLR.STTL}Usage {CLR.R}: {syntax}{CLR.R}\n"
)
tip(helpPage, f"{console.cmdname} HELP")
elif console.paramCount == 1:
Expand All @@ -128,10 +126,10 @@ class CLR:
if command["optional"]:
syntax += f'{CLR.SOPT}[{"] [".join(command["optional"])}]{CLR.R} '
helpPage += (
f'\t{CLR.CMD}{command["command"]}\n'
+ f'\t\t{CLR.CMDDSK}Description: {command["description"]}\n'
+ f'\t\t{CLR.ALS}Aliases: {CLR.ALSTXT}{", ".join(command["aliases"])}\n'
+ f"\t\t{CLR.CMDDSK}Usage: {syntax}{CLR.R}\n"
f'\t{CLR.CMD}{command["command"]}\n'
+ f'\t\t{CLR.CMDDSK}Description: {command["description"]}\n'
+ f'\t\t{CLR.ALS}Aliases: {CLR.ALSTXT}{", ".join(command["aliases"])}\n'
+ f"\t\t{CLR.CMDDSK}Usage: {syntax}{CLR.R}\n"
)
tip(helpPage, f"{console.cmdname} HELP")
finded = True
Expand Down Expand Up @@ -227,13 +225,13 @@ def unregister_by_name(self, name):
wrn(f"You can't get rid of the {name} command")

def register_command(
self,
command,
aliases=[],
description="my simple command",
required=[],
optional=["param"],
skipcheck=False,
self,
command,
aliases=[],
description="my simple command",
required=[],
optional=["param"],
skipcheck=False,
):
def register_from_decorator(command_function):
self.registered_commands.append(
Expand Down Expand Up @@ -309,15 +307,15 @@ def insert_print(self, type, text, tag=""):

def check_params(self):
return (
not (
self.paramCount
> (
len(self.current_executing["required"])
+ len(self.current_executing["optional"])
)
or self.paramCount < len(self.current_executing["required"])
not (
self.paramCount
> (
len(self.current_executing["required"])
+ len(self.current_executing["optional"])
)
or self.current_executing["skipcheck"]
or self.paramCount < len(self.current_executing["required"])
)
or self.current_executing["skipcheck"]
)

def run(self):
Expand Down
4 changes: 2 additions & 2 deletions NewLifeUtils/ExceptModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"warning": "Warn",
"error": "Error",
"fatal": "Fatal error",
"wrong": "Something wrong..."
"wrong": "Something wrong...",
}
create_config("except_translation", "lang.yml", "exceptsettings", default_lang)
translation = get_pointyaml("except_translation")
Expand All @@ -24,7 +24,7 @@ def except_print(exception, exception_type="err", tb=True):
error_text += f"{translation.type}: {type(exception).__name__}\n\n"

if exception.args == 0:
error_text += f'{translation.unknown}\n'
error_text += f"{translation.unknown}\n"
else:
error_text += (
f'{translation["about"]}:\n\t{(chr(10) + chr(9)).join(exception.args)}\t\n'
Expand Down
4 changes: 1 addition & 3 deletions NewLifeUtils/FileModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def create_config(alias, filename, folderpath, default_obj={}):
create_dirs(directory)
if not os.path.exists(os.path.join(directory, filename)) or rawread(alias) == "":
f = open(os.path.join(directory, filename), "w")
yaml_write = yaml.dump(
default_obj,
default_flow_style=False)
yaml_write = yaml.dump(default_obj, default_flow_style=False)
file_rewrite(alias, yaml_write)
return False

Expand Down
Loading

0 comments on commit f6a5645

Please sign in to comment.