|
2 | 2 | import json
|
3 | 3 | import re
|
4 | 4 | import shutil
|
| 5 | +import urllib.request |
| 6 | +import urllib.error |
5 | 7 | from datetime import datetime
|
6 | 8 | from functools import partial
|
7 | 9 | from typing import Any, Dict, List, Tuple
|
8 | 10 |
|
9 |
| -import requests |
10 | 11 | from PySide6.QtCore import *
|
11 | 12 | from PySide6.QtGui import *
|
12 | 13 | from PySide6.QtWidgets import *
|
13 |
| -from dotenv import load_dotenv |
14 | 14 |
|
15 | 15 | import lora_conversion
|
16 | 16 | import presets
|
@@ -44,7 +44,7 @@ def __init__(self, args: List[str]) -> None:
|
44 | 44 | self.setGeometry(100, 100, width, height)
|
45 | 45 | self.setWindowFlag(Qt.FramelessWindowHint)
|
46 | 46 |
|
47 |
| - load_dotenv() # Loads the .env file |
| 47 | + self.load_dotenv() # Loads the .env file |
48 | 48 |
|
49 | 49 | # Configuration
|
50 | 50 | self.model_dir_name = os.environ.get("AUTOGGUF_MODEL_DIR_NAME", "models")
|
@@ -805,6 +805,41 @@ def __init__(self, args: List[str]) -> None:
|
805 | 805 |
|
806 | 806 | self.logger.info(AUTOGGUF_INITIALIZATION_COMPLETE)
|
807 | 807 |
|
| 808 | + def load_dotenv(self): |
| 809 | + if not os.path.isfile(".env"): |
| 810 | + self.logger.warning(".env file not found.") |
| 811 | + return |
| 812 | + |
| 813 | + try: |
| 814 | + with open(".env") as f: |
| 815 | + for line in f: |
| 816 | + # Strip leading/trailing whitespace |
| 817 | + line = line.strip() |
| 818 | + |
| 819 | + # Ignore comments and empty lines |
| 820 | + if not line or line.startswith("#"): |
| 821 | + continue |
| 822 | + |
| 823 | + # Match key-value pairs (unquoted and quoted values) |
| 824 | + match = re.match(r"^([^=]+)=(.*)$", line) |
| 825 | + if not match: |
| 826 | + self.logger.warning(f"Could not parse line: {line}") |
| 827 | + continue |
| 828 | + |
| 829 | + key, value = match.groups() |
| 830 | + |
| 831 | + # Remove any surrounding quotes from the value |
| 832 | + if value.startswith(("'", '"')) and value.endswith(("'", '"')): |
| 833 | + value = value[1:-1] |
| 834 | + |
| 835 | + # Decode escape sequences |
| 836 | + value = bytes(value, "utf-8").decode("unicode_escape") |
| 837 | + |
| 838 | + # Set the environment variable |
| 839 | + os.environ[key.strip()] = value.strip() |
| 840 | + except Exception as e: |
| 841 | + self.logger.error(f"Error loading .env: {e}") |
| 842 | + |
808 | 843 | def load_plugins(self) -> Dict[str, Dict[str, Any]]:
|
809 | 844 | plugins = {}
|
810 | 845 | plugin_dir = "plugins"
|
@@ -881,17 +916,22 @@ def apply_plugins(self) -> None:
|
881 | 916 |
|
882 | 917 | def check_for_updates(self) -> None:
|
883 | 918 | try:
|
884 |
| - response = requests.get( |
885 |
| - "https://api.github.com/repos/leafspark/AutoGGUF/releases/latest" |
886 |
| - ) |
887 |
| - response.raise_for_status() # Raise an exception for bad status codes |
| 919 | + url = "https://api.github.com/repos/leafspark/AutoGGUF/releases/latest" |
| 920 | + req = urllib.request.Request(url) |
| 921 | + |
| 922 | + with urllib.request.urlopen(req) as response: |
| 923 | + if response.status != 200: |
| 924 | + raise urllib.error.HTTPError( |
| 925 | + url, response.status, "HTTP Error", response.headers, None |
| 926 | + ) |
| 927 | + |
| 928 | + latest_release = json.loads(response.read().decode("utf-8")) |
| 929 | + latest_version = latest_release["tag_name"].replace("v", "") |
888 | 930 |
|
889 |
| - latest_release = response.json() |
890 |
| - latest_version = latest_release["tag_name"].replace("v", "") |
| 931 | + if latest_version > AUTOGGUF_VERSION.replace("v", ""): |
| 932 | + self.prompt_for_update(latest_release) |
891 | 933 |
|
892 |
| - if latest_version > AUTOGGUF_VERSION.replace("v", ""): |
893 |
| - self.prompt_for_update(latest_release) |
894 |
| - except requests.exceptions.RequestException as e: |
| 934 | + except urllib.error.URLError as e: |
895 | 935 | self.logger.warning(f"{ERROR_CHECKING_FOR_UPDATES} {e}")
|
896 | 936 |
|
897 | 937 | def prompt_for_update(self, release) -> None:
|
|
0 commit comments