utils_devops 0.1.149__py3-none-any.whl → 0.1.150__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -534,24 +534,23 @@ def _inject_environment_variables(
534
534
  ) -> str:
535
535
  """
536
536
  Creates a command string that safely injects environment variables.
537
- Works for both Windows and Linux remote targets.
538
537
  """
539
538
  if not environment:
540
539
  return base_command
541
540
 
542
- # Create a temporary script to set environment and run the command
543
541
  env_lines = []
544
- if systems.is_linux :
542
+ if systems.is_linux:
545
543
  # Linux syntax: export VAR='value'
546
544
  for key, value in environment.items():
545
+ print(f"DEBUG _inject_environment_variables: key='{key}', value='{value}', type={type(value)}") # DEBUG
547
546
  escaped_value = value.replace("'", "'\"'\"'")
548
547
  env_lines.append(f"export {key}='{escaped_value}'")
549
548
  env_setup = " && ".join(env_lines)
550
549
  prefix = f"{env_setup} && "
551
- elif systems.is_windows :
550
+ elif systems.is_windows:
552
551
  # Windows syntax (PowerShell)
553
552
  for key, value in environment.items():
554
- # Escape for PowerShell
553
+ print(f"DEBUG _inject_environment_variables: key='{key}', value='{value}', type={type(value)}") # DEBUG
555
554
  escaped_value = value.replace("'", "''").replace("`", "``")
556
555
  env_lines.append(f"$env:{key}='{escaped_value}'")
557
556
  env_setup = "; ".join(env_lines)
@@ -559,6 +558,41 @@ def _inject_environment_variables(
559
558
 
560
559
  return f"{prefix}{base_command}"
561
560
 
561
+ def _detect_remote_os(client) -> str:
562
+ """
563
+ Detect the operating system of the remote SSH host.
564
+ Returns: "linux", "windows", or "unknown"
565
+ """
566
+ try:
567
+ # Try Linux command first
568
+ stdin, stdout, stderr = client.exec_command("uname -s", timeout=5)
569
+ output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
570
+ if "linux" in output or "darwin" in output:
571
+ return "linux"
572
+ except:
573
+ pass
574
+
575
+ try:
576
+ # Try Windows command
577
+ stdin, stdout, stderr = client.exec_command("ver", timeout=5)
578
+ output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
579
+ if "windows" in output or "microsoft" in output:
580
+ return "windows"
581
+ except:
582
+ pass
583
+
584
+ # Try PowerShell (Windows)
585
+ try:
586
+ stdin, stdout, stderr = client.exec_command("Get-Host", timeout=5)
587
+ output = stdout.read().decode('utf-8', errors='ignore').strip().lower()
588
+ if "powershell" in output or "windows" in output:
589
+ return "windows"
590
+ except:
591
+ pass
592
+
593
+ # Default to linux (backward compatibility)
594
+ return "linux"
595
+
562
596
  def ssh_execute_command(
563
597
  host: str,
564
598
  command: Union[str, List[str]],
@@ -600,10 +634,15 @@ def ssh_execute_command(
600
634
  else:
601
635
  command_str = command
602
636
 
637
+ with ssh_connect(
638
+ host, username, password, key_file, port, **kwargs
639
+ ) as client:
640
+ # 1. DETECT REMOTE OS
641
+ remote_os = _detect_remote_os(client)
603
642
 
604
643
  # Add environment variables
605
644
  if environment:
606
- command_str = _inject_environment_variables(environment, command_str)
645
+ command_str = _inject_environment_variables(environment, command_str,remote_os=remote_os)
607
646
 
608
647
  # Add sudo
609
648
  if sudo:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: utils_devops
3
- Version: 0.1.149
3
+ Version: 0.1.150
4
4
  Summary: Lightweight DevOps utilities for automation scripts: config editing (YAML/JSON/INI/.env), templating, diffing, and CLI tools
5
5
  License: MIT
6
6
  Keywords: devops,automation,nginx,cli,jinja2,yaml,config,diff,templating,logging,docker,compose,file-ops
@@ -17,9 +17,9 @@ utils_devops/extras/network_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
17
17
  utils_devops/extras/nginx_ops.py,sha256=FcfwGSuvcG5OX7UXPJpSTEMEBGYeT2g_I4kbTf-xY0w,100648
18
18
  utils_devops/extras/notification_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  utils_devops/extras/performance_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- utils_devops/extras/ssh_ops.py,sha256=jLbroOoYA_v96eXUkhzj77itpYl2Dr6k5mnD6wGHq2k,74812
20
+ utils_devops/extras/ssh_ops.py,sha256=ui4qghmccxTjJ5DYhmJxpL-kg1B-_wg0pV8qhNih5pc,76226
21
21
  utils_devops/extras/vault_ops.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- utils_devops-0.1.149.dist-info/METADATA,sha256=iOYqaVIlWWwEnvYvbzw0LVnJrrqGrMrejyPTdDtlRPU,1903
23
- utils_devops-0.1.149.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
- utils_devops-0.1.149.dist-info/entry_points.txt,sha256=ei3B6ZL5yu6dOq-U1r8wsBdkXeg63RAyV7m8_ADaE6k,53
25
- utils_devops-0.1.149.dist-info/RECORD,,
22
+ utils_devops-0.1.150.dist-info/METADATA,sha256=u-ZKPBea28D3uAiivhG_873hzV6j_YSANR2q1oJhh7Y,1903
23
+ utils_devops-0.1.150.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
24
+ utils_devops-0.1.150.dist-info/entry_points.txt,sha256=ei3B6ZL5yu6dOq-U1r8wsBdkXeg63RAyV7m8_ADaE6k,53
25
+ utils_devops-0.1.150.dist-info/RECORD,,