From 2da5dbe5f3df50a82e3289ab2bf807dbb8dadb9d Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 01:35:45 +0000 Subject: [PATCH] Add env_pro core modules --- app/env_pro/utils/helpers.py | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/env_pro/utils/helpers.py diff --git a/app/env_pro/utils/helpers.py b/app/env_pro/utils/helpers.py new file mode 100644 index 0000000..97e2a73 --- /dev/null +++ b/app/env_pro/utils/helpers.py @@ -0,0 +1,55 @@ +"""Helper utilities for env-pro.""" + +import os +import sys +from pathlib import Path +from typing import Optional, Dict + + +def find_env_file(project_root: Optional[Path] = None) -> Optional[Path]: + """Find the .env file in the project.""" + if project_root is None: + project_root = Path.cwd() + + for env_file in [".env", ".env.local", ".env-profiles/default/.env"]: + path = project_root / env_file + if path.exists(): + return path + + return None + + +def parse_key_value_pair(pair: str) -> tuple: + """Parse a KEY=VALUE string into a tuple.""" + if "=" in pair: + key, value = pair.split("=", 1) + return key.strip(), value.strip() + return pair.strip(), "" + + +def is_encrypted(value: str) -> bool: + """Check if a value appears to be encrypted.""" + import base64 + try: + data = base64.b64decode(value) + import json + json.loads(data) + return True + except (base64.binascii.Error, json.JSONDecodeError): + return False + + +def get_editor() -> str: + """Get the editor to use for interactive editing.""" + return os.environ.get("EDITOR", os.environ.get("VISUAL", "vim")) + + +def shell_expand(path: str) -> str: + """Expand shell variables in a path.""" + return os.path.expandvars(os.path.expanduser(path)) + + +def is_valid_env_key(key: str) -> bool: + """Check if a string is a valid environment variable name.""" + import re + return bool(re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", key))