From bc9aa1d4901642d63de40b93d616e5f0c86c9020 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 12 Feb 2025 10:39:52 -0600 Subject: [PATCH 1/2] output not print --- machine/main.py | 3 ++- machine/subcommands/create.py | 8 ++++---- machine/subcommands/destroy.py | 4 ++-- machine/subcommands/list.py | 8 ++++---- machine/subcommands/list_domain.py | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/machine/main.py b/machine/main.py index 6b11b57..5800cb9 100644 --- a/machine/main.py +++ b/machine/main.py @@ -3,6 +3,7 @@ from machine import config from machine import constants from machine.di import d +from machine.log import output from machine.subcommands import create, destroy, list, projects, ssh_keys, domains, list_domain from machine.types import CliOptions, MainCmdCtx from machine.util import load_session_id @@ -30,7 +31,7 @@ def main(context, debug, quiet, verbose, dry_run, config_file, session_id): @main.command() @click.pass_context def version(context): - print("Version command") + output("Version command") main.add_command(create.command, "create") diff --git a/machine/subcommands/create.py b/machine/subcommands/create.py index 5100363..bcf9ac6 100644 --- a/machine/subcommands/create.py +++ b/machine/subcommands/create.py @@ -3,7 +3,7 @@ import time from machine.config import get_machine from machine.di import d -from machine.log import fatal_error, info, debug +from machine.log import fatal_error, info, debug, output from machine.types import MainCmdCtx, TAG_MACHINE_CREATED, TAG_MACHINE_TYPE_PREFIX from machine.util import projectFromName, sshKeyFromName from machine.cloud_config import get_user_data @@ -99,9 +99,9 @@ def command(context, name, tag, type, region, machine_size, image, wait_for_ip, droplet.create() if droplet.id: if d.opt.quiet: - print(f"{droplet.id}") + output(f"{droplet.id}") else: - print(f"New droplet created with id: {droplet.id}") + output(f"New droplet created with id: {droplet.id}") # If requested, assign to a specified project if config.project: project_name = config.project @@ -119,7 +119,7 @@ def command(context, name, tag, type, region, machine_size, image, wait_for_ip, droplet.load() ip_address = droplet.ip_address if d.opt.verbose: - print("Waiting for droplet IP address") + output("Waiting for droplet IP address") if d.opt.quiet: info(f"{ip_address}") else: diff --git a/machine/subcommands/destroy.py b/machine/subcommands/destroy.py index bf8e06b..1245f23 100644 --- a/machine/subcommands/destroy.py +++ b/machine/subcommands/destroy.py @@ -2,7 +2,7 @@ import digitalocean from machine.di import d -from machine.log import debug, fatal_error +from machine.log import debug, fatal_error, output from machine.util import dnsRecordIdFromName, is_machine_created from machine.types import MainCmdCtx @@ -40,7 +40,7 @@ def command(context, confirm, delete_dns, all, droplet_ids): ) if confirm: - print( + output( "Type YES (not y or yes or Yes) to confirm that you want to permanently" f' DELETE/DESTROY droplet "{name}" (id: {droplet.id})' ) diff --git a/machine/subcommands/list.py b/machine/subcommands/list.py index 32f26ac..4994ace 100644 --- a/machine/subcommands/list.py +++ b/machine/subcommands/list.py @@ -2,23 +2,23 @@ import json import digitalocean -from machine.log import fatal_error +from machine.log import fatal_error, output from machine.types import MainCmdCtx, TAG_MACHINE_TYPE_PREFIX, TAG_MACHINE_SESSION_PREFIX from machine.util import get_machine_type, is_machine_created, is_same_session, droplet_to_json_obj def print_normal(droplets): for droplet in droplets: - print(f"{droplet.name} ({droplet.id}, {droplet.region['slug']}, {get_machine_type(droplet)}): {droplet.ip_address}") + output(f"{droplet.name} ({droplet.id}, {droplet.region['slug']}, {get_machine_type(droplet)}): {droplet.ip_address}") def print_quiet(droplets): for droplet in droplets: - print(droplet.id) + output(droplet.id) def print_json(droplets): - print(json.dumps([droplet_to_json_obj(d) for d in droplets])) + output(json.dumps([droplet_to_json_obj(d) for d in droplets])) @click.command(help="List machines") diff --git a/machine/subcommands/list_domain.py b/machine/subcommands/list_domain.py index daf0e0f..aa8bd19 100644 --- a/machine/subcommands/list_domain.py +++ b/machine/subcommands/list_domain.py @@ -2,19 +2,19 @@ import digitalocean import json -from machine.log import fatal_error +from machine.log import fatal_error, output from machine.types import MainCmdCtx, TAG_MACHINE_SESSION_PREFIX from machine.util import dns_record_to_json_obj def print_normal(records, zone): for record in records: - print(f"{record.name}\t{record.type}\t{record.data}") + output(f"{record.name}\t{record.type}\t{record.data}") def print_quiet(records): for record in records: - print(record.name) + output(record.name) def print_json(records, droplets, zone): @@ -22,7 +22,7 @@ def print_json(records, droplets, zone): for r in records: droplet = next((d for d in droplets if r.data == d.ip_address), None) simplified.append(dns_record_to_json_obj(r, zone, droplet)) - print(json.dumps(simplified)) + output(json.dumps(simplified)) @click.command(help="List domain records") From e579fd0b504a83d05bbae0a1d9c7bea178e2af19 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Thu, 5 Jun 2025 15:00:46 -0500 Subject: [PATCH 2/2] Updates for python 3.12 / Ubuntu 24 --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index f0e42cf..115ad3a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ click==8.1.7 python-digitalocean==1.17.0 -ruamel.yaml==0.17.32 -ruamel.yaml.clib==0.2.7 +ruamel.yaml==0.18.12 +ruamel.yaml.clib==0.2.12 requests==2.32.3 expandvars==1.0.0 flake8