This repository was archived by the owner on Mar 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAppConfig.py
More file actions
118 lines (103 loc) · 4.22 KB
/
AppConfig.py
File metadata and controls
118 lines (103 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import sys
from status_updater import StatusUpdater
class AppConfig:
_instance = None
def __new__(cls, base_path=None):
if not cls._instance:
cls._instance = super(AppConfig, cls).__new__(cls)
cls._instance._initialize(base_path)
return cls._instance
def _initialize(self, base_path):
if not hasattr(self, "base_path"): # Prevent reinitialization
# Determine the base path based on the environment
self.base_path = base_path or self.get_default_base_path()
self.miniconda_path = os.path.join(self.base_path, "miniconda3")
self.env_path = os.path.join(self.base_path, "env") # Open WebUI environment
self.env_pipelines_path = os.path.join(self.base_path, "env_pipelines") # Pipelines environment
self.pipelines_repo_path = os.path.join(self.base_path, "pipelines")
self.conda_exe = os.path.join(self.miniconda_path, "Scripts", "conda.exe")
@staticmethod
def get_default_base_path():
"""
Determines the default base path:
- On Windows: Uses USERPROFILE to store in `OpenWebUI` under the user's home directory.
- On other OS: Uses the current working directory or a fallback directory.
"""
if os.name == 'nt': # Windows
return os.path.join(os.environ['USERPROFILE'], 'OpenWebUI')
else: # Unix-like systems
if getattr(sys, 'frozen', False): # Running as a PyInstaller executable
return os.path.dirname(sys.executable)
else: # Running as a Python script
return os.path.abspath(os.getcwd())
@property
def is_miniconda_installed(self):
"""
Checks if Miniconda is installed by verifying the presence of conda.exe.
"""
return os.path.exists(self.conda_exe)
@property
def has_openwebui_env(self):
"""
Checks if the Open WebUI environment is set up.
Ensures Miniconda is installed first.
"""
if not self.is_miniconda_installed:
print("Miniconda is not installed.")
return False
if not os.path.exists(self.env_path):
print("Open WebUI environment is not set up.")
return False
return True
@property
def has_pipelines_env(self):
"""
Checks if the Pipelines environment is set up.
Ensures Miniconda is installed first.
"""
if not self.is_miniconda_installed:
print("Miniconda is not installed.")
return False
if not os.path.exists(self.env_pipelines_path):
print("Pipelines environment is not set up.")
return False
return True
@property
def status_display(self):
"""Get or create the StatusDisplay."""
if self._status_display is None:
raise AttributeError("StatusDisplay has not been initialized.")
return self._status_display
@status_display.setter
def status_display(self, display):
"""Set the StatusDisplay and initialize StatusUpdater."""
self._status_display = display
components = display.get_components()
self._status_updater = StatusUpdater(*components)
@property
def status_updater(self):
"""Access the StatusUpdater."""
if self._status_updater is None:
raise AttributeError("StatusUpdater has not been initialized.")
return self._status_updater
def start_spinner(self):
"""Start the spinner."""
if hasattr(self.status_display, "spinner"):
self.status_display.spinner.start()
def stop_spinner(self):
"""Stop the spinner."""
if hasattr(self.status_display, "spinner"):
self.status_display.spinner.stop()
def __str__(self):
"""
String representation for debugging.
"""
return (
f"Base Path: {self.base_path}\n"
f"Miniconda Path: {self.miniconda_path}\n"
f"Environment Path: {self.env_path}\n"
f"Pipelines Environment Path: {self.env_pipelines_path}\n"
f"Pipelines Repo Path: {self.pipelines_repo_path}\n"
f"Conda Executable: {self.conda_exe}\n"
)