diff --git a/.flake8 b/.flake8 index 8c1c66b..e15d858 100644 --- a/.flake8 +++ b/.flake8 @@ -9,10 +9,8 @@ per-file-ignores= # Disable redefinition warning for exception handlers hyperglass/api.py:F811 # Disable classmethod warning for validator decorators - hyperglass/models/*.py:N805,E0213,R0903 - hyperglass/configuration/models/*.py:N805,E0213,R0903 - # Disable string length warnings so one can actually read the commands - hyperglass/configuration/models/*.py:E501,C0301 + hyperglass/api/models/*.py:N805,E0213,R0903 + hyperglass/configuration/models/*.py:N805,E0213,R0903,E501,C0301 hyperglass/api/models/response.py:E501,C0301 ignore=W503,C0330,R504,D202 select=B, BLK, C, D, E, F, I, II, N, P, PIE, S, R, W diff --git a/cli/schema.py b/cli/schema.py deleted file mode 100644 index 025c0ad..0000000 --- a/cli/schema.py +++ /dev/null @@ -1,51 +0,0 @@ -"""Build docs tables from schema.""" - -HEADERS = ["Field", "Description", "Type", "Default"] - - -def build_table(data, level): - table = [HEADERS] - - for prop, attrs in data.items(): - if attrs.get("level", 0) == 0: - table.append( - [ - prop, - attrs.get("description", ""), - attrs.get("type", attrs.get("anyOf", "")), - attrs.get("default", ""), - ] - ) - return table - - -def process_object(obj): - definitions = obj.pop("definitions", {}) - properties = obj.pop("properties") - level = obj.pop("level", 0) - - top_properties = {} - - for key, value in properties.items(): - if value["title"] not in definitions: - top_properties.update({key: value}) - - data = build_table(data=top_properties, level=level) - return data - - -def schema_top_level(): - from hyperglass.configuration.models.params import Params - - schema = Params.schema() - definitions = schema.get("definitions") - - tables = {} - top_level = process_object(schema) - tables.update({schema["title"]: top_level}) - - for k, v in definitions.items(): - if isinstance(v, dict) and "allOf" not in v: - tables.update({k: process_object(v)}) - - return tables diff --git a/develop.py b/develop.py deleted file mode 100644 index 8c24192..0000000 --- a/develop.py +++ /dev/null @@ -1,35 +0,0 @@ -"""Devloper functions.""" - -# Standard Library Imports -import os - - -def count_lines(directory): - """Count lines of code. - - Arguments: - directory {str} -- Path to count - - Returns: - {int} -- Line count - """ - lines = 0 - excluded = ("\n",) - for thing in os.listdir(directory): - thing = os.path.join(directory, thing) - if os.path.isfile(thing): - if thing.endswith(".py"): - with open(thing, "r") as f: - readlines = [ - line - for line in f.readlines() - if line not in excluded and not line.startswith("#") - ] - lines += len(readlines) - - for thing in os.listdir(directory): - thing = os.path.join(directory, thing) - if os.path.isdir(thing): - lines += count_lines(thing) - - return lines diff --git a/hyperglass/__init__.py b/hyperglass/__init__.py index fc72e74..7934b54 100644 --- a/hyperglass/__init__.py +++ b/hyperglass/__init__.py @@ -49,7 +49,7 @@ import stackprinter # Project # Project Imports # flake8: noqa: F401 -from hyperglass import api, util, constants, execution, exceptions, configuration +from hyperglass import api, cli, util, constants, execution, exceptions, configuration stackprinter.set_excepthook() diff --git a/cli/__init__.py b/hyperglass/cli/__init__.py similarity index 63% rename from cli/__init__.py rename to hyperglass/cli/__init__.py index f8d74e9..58a8a84 100644 --- a/cli/__init__.py +++ b/hyperglass/cli/__init__.py @@ -3,7 +3,7 @@ import stackprinter # Project -from cli import echo, util, static, commands, formatting, schema # noqa: F401 +from hyperglass.cli import commands stackprinter.set_excepthook(style="darkbg2") diff --git a/cli/commands.py b/hyperglass/cli/commands.py similarity index 72% rename from cli/commands.py rename to hyperglass/cli/commands.py index 1363c70..8bd7f68 100644 --- a/cli/commands.py +++ b/hyperglass/cli/commands.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """CLI Command definitions.""" # Standard Library @@ -8,8 +7,8 @@ from pathlib import Path import click # Project -from cli.echo import error, value, cmd_help -from cli.util import ( +from hyperglass.cli.echo import error, value, cmd_help +from hyperglass.cli.util import ( build_ui, fix_ownership, migrate_config, @@ -17,8 +16,8 @@ from cli.util import ( migrate_systemd, start_web_server, ) -from cli.static import LABEL, CLI_HELP, E -from cli.formatting import HelpColorsGroup, HelpColorsCommand, random_colors +from hyperglass.cli.static import LABEL, CLI_HELP, E +from hyperglass.cli.formatting import HelpColorsGroup, HelpColorsCommand, random_colors # Define working directory WORKING_DIR = Path(__file__).parent @@ -29,13 +28,7 @@ WORKING_DIR = Path(__file__).parent help=CLI_HELP, help_headers_color=LABEL, help_options_custom_colors=random_colors( - "build-ui", - "start", - "migrate-examples", - "systemd", - "permissions", - "secret", - "docs-schema", + "build-ui", "start", "migrate-examples", "systemd", "permissions", "secret" ), ) def hg(): @@ -142,34 +135,3 @@ def generate_secret(length): gen_secret = secrets.token_urlsafe(length) value("Secret", gen_secret) - - -@hg.command( - "docs-schema", - help=cmd_help(E.BOOKS, "Generate docs schema"), - cls=HelpColorsCommand, - help_options_custom_colors=random_colors("-p"), -) -@click.option( - "-p", "--print", "print_table", is_flag=True, help="Print table to console" -) -def build_docs_schema(print_table): - from rich.console import Console - from rich.table import Table - from cli.schema import schema_top_level - - data = schema_top_level() - - if print_table: - console = Console() - - for section, table_data in data.items(): - table = Table(show_header=True, header_style="bold magenta") - for col in table_data[0]: - table.add_column(col) - - for row in table_data[1::]: - table.add_row(*(str(i) for i in row)) - - click.echo(console.print(section, style="bold red")) - click.echo(console.print(table)) diff --git a/cli/echo.py b/hyperglass/cli/echo.py similarity index 97% rename from cli/echo.py rename to hyperglass/cli/echo.py index f325ed3..de9b13a 100644 --- a/cli/echo.py +++ b/hyperglass/cli/echo.py @@ -3,7 +3,7 @@ import click # Project -from cli.static import ( +from hyperglass.cli.static import ( CL, NL, WS, diff --git a/cli/formatting.py b/hyperglass/cli/formatting.py similarity index 100% rename from cli/formatting.py rename to hyperglass/cli/formatting.py diff --git a/cli/static.py b/hyperglass/cli/static.py similarity index 100% rename from cli/static.py rename to hyperglass/cli/static.py diff --git a/cli/util.py b/hyperglass/cli/util.py similarity index 97% rename from cli/util.py rename to hyperglass/cli/util.py index 4d0ff30..04a8c78 100644 --- a/cli/util.py +++ b/hyperglass/cli/util.py @@ -6,8 +6,8 @@ from pathlib import Path import click # Project -from cli.echo import info, error, status, success -from cli.static import CL, NL, WS, VALUE, SUCCESS, E +from hyperglass.cli.echo import info, error, status, success +from hyperglass.cli.static import CL, NL, WS, VALUE, SUCCESS, E PROJECT_ROOT = Path(__file__).parent.parent diff --git a/hyperglass/configuration/models/vrfs.py b/hyperglass/configuration/models/vrfs.py index 82eb851..9b52f94 100644 --- a/hyperglass/configuration/models/vrfs.py +++ b/hyperglass/configuration/models/vrfs.py @@ -73,21 +73,16 @@ class AccessList6(HyperglassModel): "permit", title="Action", description="Permit or deny any networks contained within the prefix.", - # regex="permit|deny", ) ge: conint(ge=0, le=128) = Field( 0, title="Greater Than or Equal To", description="Similar to `ge` in a Cisco prefix-list, the `ge` field defines the **bottom** threshold for prefix size. For example, a value of `64` would result in a query for `2001:db8::/48` being denied, but a query for `2001:db8::1/128` would be permitted. If this field is set to a value smaller than the `network` field's prefix length, this field's value will be overwritten to the prefix length of the prefix in the `network` field.", - # ge=0, - # le=128, ) le: conint(ge=0, le=128) = Field( 128, title="Less Than or Equal To", description="Similar to `le` in a Cisco prefix-list, the `le` field defines the **top** threshold for prefix size. For example, a value of `64` would result in a query for `2001:db8::/48` being permitted, but a query for `2001:db8::1/128` would be denied.", - # ge=0, - # le=128, ) @validator("ge") diff --git a/manage.py b/hyperglass/console.py similarity index 78% rename from manage.py rename to hyperglass/console.py index b6a71a7..a1a7aed 100755 --- a/manage.py +++ b/hyperglass/console.py @@ -2,7 +2,7 @@ """hyperglass CLI management tool.""" # Project -from cli import CLI +from hyperglass.cli import CLI if __name__ == "__main__": CLI()