Refactor for consistent string quoting and formatting
Some checks failed
Ansible Lint Check / check-ansible (push) Successful in 5s
Nix Format Check / check-format (push) Successful in 1m14s
Python Lint Check / check-python (push) Failing after 7s

This commit is contained in:
2025-09-23 13:53:29 +00:00
parent 2e5a06e9d5
commit 40063cfe6b
4 changed files with 59 additions and 32 deletions

View File

@@ -230,7 +230,10 @@ def get_sudo_password_from_1password(username, hostname):
printfe("red", f"Failed to fetch password from 1Password: {e.stderr.strip()}")
return None
except FileNotFoundError:
printfe("red", "Error: 'op' command not found. Please ensure 1Password CLI is installed and in your PATH.")
printfe(
"red",
"Error: 'op' command not found. Please ensure 1Password CLI is installed and in your PATH.",
)
return None
except Exception as e:
printfe("red", f"An unexpected error occurred while fetching password: {e}")
@@ -247,13 +250,11 @@ def main():
"--ansible", "-A", action="store_true", help="Upgrade Ansible packages"
)
parser.add_argument(
"--ansible-verbose",
"--ansible-verbose",
action="store_true",
help="Upgrade Ansible packages with verbose output",
)
parser.add_argument(
"--tags", type=str, help="Run only specific Ansible tags"
)
parser.add_argument("--tags", type=str, help="Run only specific Ansible tags")
parser.add_argument(
"--full-speed", "-F", action="store_true", help="Use all available cores"
)
@@ -262,7 +263,10 @@ def main():
)
parser.add_argument(
"--skip-check", "-s", action="store_true", help="Skip checking for dotfiles updates"
"--skip-check",
"-s",
action="store_true",
help="Skip checking for dotfiles updates",
)
args = parser.parse_args()
@@ -290,6 +294,7 @@ def main():
# Set cores and jobs based on full-speed flag
if args.full_speed:
import multiprocessing
cores = jobs = multiprocessing.cpu_count()
else:
cores = 8
@@ -385,14 +390,20 @@ def main():
sudo_password = None
if not os.isatty(sys.stdin.fileno()):
printfe("yellow", "Warning: Not running in an interactive terminal. Cannot fetch password from 1Password.")
printfe(
"yellow",
"Warning: Not running in an interactive terminal. Cannot fetch password from 1Password.",
)
ansible_cmd.append("--ask-become-pass")
else:
sudo_password = get_sudo_password_from_1password(username, hostname)
if sudo_password:
ansible_cmd.extend(["--become-pass-file", "-"])
else:
printfe("yellow", "Could not fetch password from 1Password. Falling back to --ask-become-pass.")
printfe(
"yellow",
"Could not fetch password from 1Password. Falling back to --ask-become-pass.",
)
ansible_cmd.append("--ask-become-pass")
if args.tags:
@@ -406,7 +417,7 @@ def main():
# Execute the Ansible command, passing password via stdin if available
if sudo_password:
result = subprocess.run(ansible_cmd, input=sudo_password.encode('utf-8'))
result = subprocess.run(ansible_cmd, input=sudo_password.encode("utf-8"))
else:
result = subprocess.run(ansible_cmd)