Refactor for consistent string quoting and formatting
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user