diff --git a/multiball/__init__.py b/multiball/__init__.py index 49e0fc1..a5f830a 100644 --- a/multiball/__init__.py +++ b/multiball/__init__.py @@ -1 +1 @@ -__version__ = "0.7.0" +__version__ = "0.7.1" diff --git a/multiball/__main__.py b/multiball/__main__.py index 2d18f85..c792eb5 100644 --- a/multiball/__main__.py +++ b/multiball/__main__.py @@ -31,8 +31,9 @@ from .fabtools import HostSet from .tools import (load_bare_server_list, load_config, load_sshconfig_server_list) -oprint = print -from .style import print, STYLES +_print = print +from .style import print_style as print +from .style import STYLES class MultiballCommandException(BaseException): pass @@ -117,19 +118,19 @@ class Multiball: self.ssh_config = Path(sc).expanduser() newhosts = load_sshconfig_server_list( Path(sc).expanduser()) - print(f"Loaded {len(newhosts)} host(s) from {sc}") + print(f"Loaded {len(newhosts)} host(s) from {sc}") self.allhosts.update(newhosts) if bareconfigs := config.get('hostlists'): for sc in bareconfigs.split(','): newhosts = load_bare_server_list(Path(sc).expanduser()) - print(f"Loaded {len(newhosts)} host(s) from {sc}") + print(f"Loaded {len(newhosts)} host(s) from {sc}") self.allhosts.update(newhosts) else: self.ssh_config = Path("~/.ssh/ssh_config").expanduser() print( - f"Warning: no [config] section in {configFile}. Using fallbacks.") + f"Warning: no [config] section in {configFile}. Using fallbacks.", style="error") self.allhosts = load_sshconfig_server_list(self.ssh_config) # setup state and environment @@ -165,17 +166,17 @@ class Multiball: """ if args.lower().startswith("off"): self.safety = False - print("** Safety OFF. Now unsafe.") + print("** Safety OFF. Now unsafe!", style="unsafe") else: self.safety = True - print("** Safety ON.") + print("** Safety ON.", style="safe") def command_echo(self, command, args): """ Echo string fixme put string interpolation here so that state variables can be printed """ - print(f"{args}") + print(f"{args}") def command_environment(self, command, args): """ @@ -211,7 +212,7 @@ class Multiball: if result and (result[0] in 'Yys'): return True else: - print("(no)") + print("(no)") raise MBCommandAbort def command_arguments(self, command, args): @@ -223,9 +224,9 @@ class Multiball: """ if not self._is_scripting or not self._script_frame_arguments: if not self._is_scripting: - print("does nothing outside of script") + print("does nothing outside of script", style="alert") else: - print("arguments required") + print("arguments required", style="error") raise MBCommandAbort return @@ -236,9 +237,9 @@ class Multiball: """ if not self._is_scripting or self.safety: if not self._is_scripting: - print("does nothing outside of script") + print("does nothing outside of script", style="alert") else: - print("cannot run in safety mode") + print("cannot run in safety mode", style="error") raise MBCommandAbort return @@ -251,7 +252,7 @@ class Multiball: # FIXME: We need to make aliases store multiple entries, and save should take the whole alias not just # the last command. if (not self.last_run): - print("Nothing to log.") + print("Nothing to log.", style="alert") return tstamp = datetime.datetime.now().strftime("%Y-%m-%d-%H%M%Z") outfilename = f"{tstamp}.multiball.log" @@ -260,7 +261,7 @@ class Multiball: if (not outfilename.endswith(".log")): outfilename = outfilename + ".log" - print(f"Writing {outfilename} for command `{self.last_run['cmd']}`.") + print(f"Writing {outfilename} for command `{self.last_run['cmd']}`.", style="alert") with (open(outfilename, 'w')) as out: out.writelines([f"command: {self.last_run['cmd']}\n", "-------------------------------------------\n" @@ -271,13 +272,13 @@ class Multiball: def _print_targetlist(self, tlist=None, keyword='Targeting'): if not tlist: tlist = self.targethosts - print(f"{keyword} {len(self.targethosts)} hosts:") + print(f"{keyword} {len(self.targethosts)} hosts:") print(' '.join(tlist)) def _print_help(self): for item in COMMANDS.values(): m = ', '.join(item[0]) + ' - ' + item[1] - print(f"{m}") + print(f"{m}", style="bright") print("Other entries run command on targets.") def _run_command(self, command: str): @@ -389,10 +390,10 @@ class Multiball: except MBCommandRun: # remote command! if self.safety: - print(f"would run `{command}` on targethosts") - print("Safety is ON. `/safety off` to turn off.") + print(f"would run `{command}` on targethosts", style="bright") + print("Safety is ON. `/safety off` to turn off.", style="alert") else: - print(f"running `{command}` on targethosts") + print(f"running `{command}` on targethosts", style="bright") self._run_remote_command(command) def cmd_prompt(self): @@ -447,7 +448,7 @@ def multiball(argv): print('Need at least one --command') return 1 - print(f"Multiball {__version__}.") + print(f"Multiball {__version__}.", style="alert") mb = Multiball() if (args.all): @@ -467,7 +468,7 @@ def multiball(argv): return 0 ## Interactive mode - print(f"Welcome to Multiball {__version__}. type /help for help.") + print(f"Welcome to Multiball {__version__}. type /help for help.", style="alert") mb = Multiball() while (True): # loop on prompt @@ -484,7 +485,7 @@ def main(): sys.exit(0) except Exception as inst: # fixme log exception - print(f"Exception! {inst}{message}"), style=STYLES) + message = " ".join([str(a) for a in args]) - -def print_style(message, style): print_formatted_text(FormattedText([(f"class:{style}", message)]), style=STYLES)