Pylint settings

This commit is contained in:
Firq 2024-07-05 16:05:35 +02:00
parent be932ea9c4
commit a99b81b0c7
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
12 changed files with 140 additions and 3 deletions
dockge_cli/client

View file

@ -7,6 +7,10 @@ from ...service.communicate import DockgeConnection
from ..utils import stack_formatter, status_formatter, generic_formatter, get_credential_parser
class ExecutionCommands():
"""
Helper class that provides all the static methods in an organized way
This is an abstraction layer of the CLI, as those functions only do little preprocessing before calling the actural DockgeConnection
"""
@staticmethod
def __setup():
con = DockgeConnection()
@ -15,6 +19,9 @@ class ExecutionCommands():
@staticmethod
def host(extra_args):
"""
host command binding
"""
if len(extra_args) > 0:
res = urlparse(extra_args[0])
if all([res.scheme, res.netloc]):
@ -26,6 +33,9 @@ class ExecutionCommands():
@staticmethod
def login(extra_args):
"""
login command binding
"""
if len(extra_args) > 0:
credentials = get_credential_parser().parse_args(extra_args, namespace=Credentials)
storage.put("username", credentials.username, encoded=True)
@ -36,21 +46,33 @@ class ExecutionCommands():
@staticmethod
def logout(_):
"""
logout command binding
"""
storage.remove("username")
storage.remove("password")
@staticmethod
def exit(_):
"""
exit command binding
"""
storage.clear()
@staticmethod
def list(_):
"""
list command binding
"""
con = ExecutionCommands.__setup()
stack_formatter(con.list_stacks())
con.disconnect()
@staticmethod
def status(extra_args):
"""
status command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -59,6 +81,9 @@ class ExecutionCommands():
@staticmethod
def restart(extra_args):
"""
restart command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -67,6 +92,9 @@ class ExecutionCommands():
@staticmethod
def update(extra_args):
"""
update command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -75,6 +103,9 @@ class ExecutionCommands():
@staticmethod
def stop(extra_args):
"""
stop command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -83,6 +114,9 @@ class ExecutionCommands():
@staticmethod
def start(extra_args):
"""
start command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -91,6 +125,9 @@ class ExecutionCommands():
@staticmethod
def down(extra_args):
"""
down command binding
"""
if extra_args is None:
raise ValueError
con = ExecutionCommands.__setup()
@ -99,4 +136,7 @@ class ExecutionCommands():
@staticmethod
def help():
"""
exit command binding - This should never be invoked
"""
print("WTF")

View file

@ -6,6 +6,10 @@ from ..models import Arguments
from .commandprovider.factory import commands
def parse_arguments():
"""
Create a parser and parse the arguments of sys.argv based on the Arguments Namespace
Returns arguments and extra arguments separately
"""
parser = argparse.ArgumentParser(
prog="dockge_cli",
description="CLI interface for interacting with Dockge",)

View file

@ -1,6 +1,9 @@
from .commandprovider.factory import commands
def display_help(extra_args):
"""
Display help dialogues for each command
"""
if not extra_args:
print(f"{commands['help'].description}")
return
@ -11,6 +14,10 @@ def display_help(extra_args):
print(f"{commands[extra_args[0]].description}")
def run(command, args):
"""
Runs a given command with the provided args
Alsso automatically maps the given command string to the correct Command class
"""
if command not in commands:
raise ValueError("Invalid Command")
@ -25,4 +32,4 @@ def run(command, args):
display_help(args)
return
c.binding(args)
c.bind(args)

View file

@ -3,6 +3,9 @@ from tabulate import tabulate
from ..models import StackStatus
def get_credential_parser():
"""
Creates a new parser for login credentials
"""
credentialparser = argparse.ArgumentParser(
prog="login",
description="Subparser for login credentials provided by CI"
@ -12,6 +15,9 @@ def get_credential_parser():
return credentialparser
def stack_formatter(stacks):
"""
Prints a given stack list formatted as a table
"""
if not stacks["ok"]:
raise RuntimeError("Stack GET didn't work")
@ -22,11 +28,17 @@ def stack_formatter(stacks):
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
def status_formatter(status):
"""
Prints the status for a given stack
"""
print(f"Is Stack Ok? {'Yes' if status['ok'] else 'No'}")
headers = ["Container", "Status"]
table = [[k, v] for k, v in status["serviceStatusList"].items()]
print(tabulate(table, headers=headers, tablefmt="github"), "\n")
def generic_formatter(status):
"""
Prints a generic dockge message
"""
print(f"Is Ok? {'Yes' if status['ok'] else 'No'}")
print(f"Stack status: {status['msg']}")