-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CTX-6123: Added --verbose flag for all commands that could have detai… #241
base: develop
Are you sure you want to change the base?
Changes from 5 commits
fe350d5
c4e4b78
2a37e11
98737e4
114e51b
8b07079
fb6115e
c6fff72
628274b
cff9c74
da4cb80
5156231
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,14 @@ | |
from ..modules.utils import onBeforeCommandExecute, checkEnvironment | ||
from ..modules.update import activateAutoUpdate, getNodeStatus | ||
from ...utils import docker | ||
from ...configuration import UserConfiguration, NodeConfiguration, InvalidConfiguration, ConfigurationNotFound | ||
from ...configuration import NodeConfiguration, InvalidConfiguration, ConfigurationNotFound | ||
|
||
|
||
@click.command() | ||
@click.option("--image", type = str, help = "Docker image url") | ||
@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") | ||
@onBeforeCommandExecute(node_module.initializeNodeConfiguration) | ||
def start(image: Optional[str]) -> None: | ||
def start(image: Optional[str], verbose: bool = False) -> None: | ||
nodeConfig = NodeConfiguration.load() | ||
|
||
if node_module.isRunning(): | ||
|
@@ -65,7 +66,8 @@ def start(image: Optional[str]) -> None: | |
|
||
|
||
@click.command() | ||
def stop() -> None: | ||
@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") | ||
def stop(verbose: bool = False) -> None: | ||
nodeConfig = NodeConfiguration.load() | ||
|
||
if not node_module.isRunning(): | ||
|
@@ -78,8 +80,9 @@ def stop() -> None: | |
@click.command() | ||
@click.option("-y", "autoAccept", is_flag = True, help = "Accepts all prompts.") | ||
@click.option("-n", "autoDecline", is_flag = True, help = "Declines all prompts.") | ||
@click.option("--verbose", "verbose", is_flag = True, help = "Shows detailed output of command execution.") | ||
@onBeforeCommandExecute(node_module.initializeNodeConfiguration) | ||
def update(autoAccept: bool, autoDecline: bool) -> None: | ||
def update(autoAccept: bool, autoDecline: bool, verbose: bool = False) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
if autoAccept and autoDecline: | ||
ui.errorEcho("Only one of the flags (\"-y\" or \"-n\") can be used at the same time.") | ||
return | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
|
||
import click | ||
|
||
from .ui import errorEcho | ||
from ...configuration import CONFIG_DIR | ||
|
||
|
||
class ClickExceptionInterceptor(click.Group): | ||
|
||
|
@@ -37,5 +40,9 @@ def invoke(self, ctx: click.Context) -> Any: | |
self.handleException(ctx, exc) | ||
|
||
def handleException(self, ctx: click.Context, exc: BaseException) -> None: | ||
click.echo(click.style(str(exc), fg = "red")) | ||
logPath = CONFIG_DIR / "logs" | ||
logFiles = list(logPath.glob("*.log")) | ||
latestLogFile = max(logFiles, key = lambda f: f.stat().st_mtime) | ||
|
||
errorEcho(f"Exception: {str(exc)}.\nYou can see detailed logs here: {latestLogFile}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An error occured. You can see the detailed logs at {filepath} |
||
logging.getLogger("cli").debug(exc, exc_info = exc) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ | |
|
||
from . import ui | ||
from .utils import isGPUAvailable | ||
from .ui import progressEcho, successEcho | ||
from ...node import NodeMode | ||
from ..settings import CLISettings | ||
from ...cryptography import rsa | ||
from ...networking import networkManager, NetworkRequestError | ||
from ...utils import CommandException, docker | ||
|
@@ -47,26 +50,27 @@ class ImageType(Enum): | |
|
||
def pull(image: str) -> None: | ||
try: | ||
ui.progressEcho(f"Fetching image {image}...") | ||
docker.imagePull(image) | ||
ui.successEcho(f"Image {image} successfully fetched.") | ||
progressEcho(f"Fetching image {image}...") | ||
docker.imagePull(image, CLISettings.verbose) | ||
|
||
successEcho(f"Image {image} successfully fetched.") | ||
except BaseException as ex: | ||
logging.getLogger("cli").debug(ex, exc_info = ex) | ||
raise NodeException("Failed to fetch latest node version.") | ||
|
||
|
||
def isRunning() -> bool: | ||
return docker.containerRunning(config_defaults.DOCKER_CONTAINER_NAME) | ||
return docker.containerRunning(config_defaults.DOCKER_CONTAINER_NAME, CLISettings.verbose) | ||
|
||
|
||
def exists() -> bool: | ||
return docker.containerExists(config_defaults.DOCKER_CONTAINER_NAME) | ||
return docker.containerExists(config_defaults.DOCKER_CONTAINER_NAME, CLISettings.verbose) | ||
|
||
|
||
def start(dockerImage: str, nodeConfig: NodeConfiguration) -> None: | ||
try: | ||
ui.progressEcho("Starting Coretex Node...") | ||
docker.createNetwork(config_defaults.DOCKER_CONTAINER_NETWORK) | ||
docker.createNetwork(config_defaults.DOCKER_CONTAINER_NETWORK, CLISettings.verbose) | ||
|
||
environ = { | ||
"CTX_API_URL": os.environ["CTX_API_URL"], | ||
|
@@ -102,7 +106,8 @@ def start(dockerImage: str, nodeConfig: NodeConfiguration) -> None: | |
nodeConfig.sharedMemory, | ||
nodeConfig.cpuCount, | ||
environ, | ||
volumes | ||
volumes, | ||
CLISettings.verbose | ||
) | ||
|
||
ui.successEcho("Successfully started Coretex Node.") | ||
|
@@ -113,8 +118,8 @@ def start(dockerImage: str, nodeConfig: NodeConfiguration) -> None: | |
|
||
def clean() -> None: | ||
try: | ||
docker.removeContainer(config_defaults.DOCKER_CONTAINER_NAME) | ||
docker.removeNetwork(config_defaults.DOCKER_CONTAINER_NETWORK) | ||
docker.removeContainer(config_defaults.DOCKER_CONTAINER_NAME, CLISettings.verbose) | ||
docker.removeNetwork(config_defaults.DOCKER_CONTAINER_NETWORK, CLISettings.verbose) | ||
except BaseException as ex: | ||
logging.getLogger("cli").debug(ex, exc_info = ex) | ||
raise NodeException("Failed to clean inactive Coretex Node.") | ||
|
@@ -133,7 +138,7 @@ def deactivateNode(id: Optional[int]) -> None: | |
def stop(nodeId: Optional[int] = None) -> None: | ||
try: | ||
ui.progressEcho("Stopping Coretex Node...") | ||
docker.stopContainer(config_defaults.DOCKER_CONTAINER_NAME) | ||
docker.stopContainer(config_defaults.DOCKER_CONTAINER_NAME, CLISettings.verbose) | ||
|
||
if nodeId is not None: | ||
deactivateNode(nodeId) | ||
|
@@ -178,16 +183,16 @@ def getTagFromImageUrl(image: str) -> str: | |
return "latest" | ||
|
||
|
||
def shouldUpdate(image: str) -> bool: | ||
def shouldUpdate(image: str, ) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comma |
||
repository = getRepoFromImageUrl(image) | ||
try: | ||
imageJson = docker.imageInspect(image) | ||
imageJson = docker.imageInspect(image, CLISettings.verbose) | ||
except CommandException: | ||
# imageInspect() will raise an error if image doesn't exist locally | ||
return True | ||
|
||
try: | ||
manifestJson = docker.manifestInspect(image) | ||
manifestJson = docker.manifestInspect(image, CLISettings.verbose) | ||
except CommandException: | ||
return False | ||
|
||
|
@@ -358,7 +363,7 @@ def _configureInitScript() -> str: | |
|
||
|
||
def checkResourceLimitations() -> None: | ||
_, ramLimit = docker.getResourceLimits() | ||
_, ramLimit = docker.getResourceLimits(CLISettings.verbose) | ||
|
||
if ramLimit < config_defaults.MINIMUM_RAM: | ||
raise RuntimeError( | ||
|
@@ -372,7 +377,7 @@ def configureNode(advanced: bool) -> NodeConfiguration: | |
ui.highlightEcho("[Node Configuration]") | ||
nodeConfig = NodeConfiguration({}) # create new empty node config | ||
|
||
cpuLimit, ramLimit = docker.getResourceLimits() | ||
cpuLimit, ramLimit = docker.getResourceLimits(CLISettings.verbose) | ||
swapLimit = docker.getDockerSwapLimit() | ||
|
||
nodeConfig.name = ui.clickPrompt("Node name", type = str) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ | |
import requests | ||
|
||
from . import ui | ||
import platform | ||
|
||
from ..settings import CLISettings | ||
from ...configuration import DEFAULT_VENV_PATH | ||
from ...utils.process import command | ||
|
||
|
@@ -181,6 +184,18 @@ def onBeforeCommandExecute( | |
def decorator(f: Callable[..., Any]) -> Callable[..., Any]: | ||
@wraps(f) | ||
def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
ctxInfoDict = click.get_current_context().to_info_dict() | ||
try: | ||
params = ctxInfoDict["command"]["commands"][click.get_current_context().invoked_subcommand]["params"] | ||
for param in params: | ||
if param["name"] == "verbose" and param["flag_value"] == True: | ||
CLISettings.verbose = True | ||
except: | ||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set verbose to false here |
||
|
||
# if ctx.params.get('verbose'): | ||
# VERBOSE = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this comment be removed? |
||
|
||
if click.get_current_context().invoked_subcommand in excludeSubcommands: | ||
return f(*args, **kwargs) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .settings import CLISettings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class CLISettings: | ||
|
||
verbose = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to have
verbose
defined explicitly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes