ErisPulse 1.0.13__py3-none-any.whl → 1.0.14__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.
ErisPulse/envManager.py DELETED
@@ -1,227 +0,0 @@
1
- import os
2
- import json
3
- import sqlite3
4
- import importlib.util
5
- from pathlib import Path
6
-
7
- class EnvManager:
8
- _instance = None
9
- db_path = os.path.join(os.path.dirname(__file__), "config.db")
10
-
11
- def __new__(cls, *args, **kwargs):
12
- if not cls._instance:
13
- cls._instance = super().__new__(cls)
14
- cls._instance.dev_mode = kwargs.get('dev_mode', False)
15
- return cls._instance
16
-
17
- def __init__(self, dev_mode=False):
18
- if not hasattr(self, "_initialized"):
19
- self.dev_mode = dev_mode
20
- self._init_db()
21
-
22
- def _init_db(self):
23
- os.makedirs(os.path.dirname(self.db_path), exist_ok=True)
24
-
25
- conn = sqlite3.connect(self.db_path)
26
- cursor = conn.cursor()
27
- cursor.execute("""
28
- CREATE TABLE IF NOT EXISTS config (
29
- key TEXT PRIMARY KEY,
30
- value TEXT NOT NULL
31
- )
32
- """)
33
- cursor.execute("""
34
- CREATE TABLE IF NOT EXISTS modules (
35
- module_name TEXT PRIMARY KEY,
36
- status INTEGER NOT NULL,
37
- version TEXT,
38
- description TEXT,
39
- author TEXT,
40
- dependencies TEXT,
41
- optional_dependencies TEXT,
42
- pip_dependencies TEXT
43
- )
44
- """)
45
- conn.commit()
46
- conn.close()
47
-
48
- def get(self, key, default=None):
49
- try:
50
- with sqlite3.connect(self.db_path) as conn:
51
- cursor = conn.cursor()
52
- cursor.execute("SELECT value FROM config WHERE key = ?", (key,))
53
- result = cursor.fetchone()
54
- if result:
55
- try:
56
- return json.loads(result[0])
57
- except json.JSONDecodeError:
58
- return result[0]
59
- return default
60
- except sqlite3.OperationalError as e:
61
- if "no such table" in str(e):
62
- self._init_db()
63
- return self.get(key, default)
64
- else:
65
- raise
66
-
67
- def set(self, key, value):
68
- serialized_value = json.dumps(value) if isinstance(value, (dict, list)) else str(value)
69
- conn = sqlite3.connect(self.db_path)
70
- cursor = conn.cursor()
71
- cursor.execute("INSERT OR REPLACE INTO config (key, value) VALUES (?, ?)", (key, serialized_value))
72
- conn.commit()
73
- conn.close()
74
-
75
- def delete(self, key):
76
- conn = sqlite3.connect(self.db_path)
77
- cursor = conn.cursor()
78
- cursor.execute("DELETE FROM config WHERE key = ?", (key,))
79
- conn.commit()
80
- conn.close()
81
-
82
- def clear(self):
83
- conn = sqlite3.connect(self.db_path)
84
- cursor = conn.cursor()
85
- cursor.execute("DELETE FROM config")
86
- conn.commit()
87
- conn.close()
88
-
89
- def load_env_file(self):
90
- env_file = Path("env.py")
91
- if env_file.exists():
92
- spec = importlib.util.spec_from_file_location("env_module", env_file)
93
- env_module = importlib.util.module_from_spec(spec)
94
- spec.loader.exec_module(env_module)
95
- for key, value in vars(env_module).items():
96
- if not key.startswith("__") and isinstance(value, (dict, list, str, int, float, bool)):
97
- self.set(key, value)
98
- def set_module_status(self, module_name, status):
99
- with sqlite3.connect(self.db_path) as conn:
100
- cursor = conn.cursor()
101
- cursor.execute("""
102
- UPDATE modules SET status = ? WHERE module_name = ?
103
- """, (int(status), module_name))
104
- conn.commit()
105
-
106
- def get_module_status(self, module_name):
107
- with sqlite3.connect(self.db_path) as conn:
108
- cursor = conn.cursor()
109
- cursor.execute("""
110
- SELECT status FROM modules WHERE module_name = ?
111
- """, (module_name,))
112
- result = cursor.fetchone()
113
- return bool(result[0]) if result else True
114
-
115
- def set_all_modules(self, modules_info):
116
- with sqlite3.connect(self.db_path) as conn:
117
- cursor = conn.cursor()
118
- for module_name, module_info in modules_info.items():
119
- meta = module_info.get('info', {}).get('meta', {})
120
- dependencies = module_info.get('info', {}).get('dependencies', {})
121
- cursor.execute("""
122
- INSERT OR REPLACE INTO modules (
123
- module_name, status, version, description, author,
124
- dependencies, optional_dependencies, pip_dependencies
125
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
126
- """, (
127
- module_name,
128
- int(module_info.get('status', True)),
129
- meta.get('version', ''),
130
- meta.get('description', ''),
131
- meta.get('author', ''),
132
- json.dumps(dependencies.get('requires', [])),
133
- json.dumps(dependencies.get('optional', [])),
134
- json.dumps(dependencies.get('pip', []))
135
- ))
136
- conn.commit()
137
-
138
- def get_all_modules(self):
139
- with sqlite3.connect(self.db_path) as conn:
140
- cursor = conn.cursor()
141
- cursor.execute("SELECT * FROM modules")
142
- rows = cursor.fetchall()
143
- modules_info = {}
144
- for row in rows:
145
- module_name, status, version, description, author, dependencies, optional_dependencies, pip_dependencies = row
146
- modules_info[module_name] = {
147
- 'status': bool(status),
148
- 'info': {
149
- 'meta': {
150
- 'version': version,
151
- 'description': description,
152
- 'author': author,
153
- 'pip_dependencies': json.loads(pip_dependencies) if pip_dependencies else []
154
- },
155
- 'dependencies': {
156
- 'requires': json.loads(dependencies) if dependencies else [],
157
- 'optional': json.loads(optional_dependencies) if optional_dependencies else [],
158
- 'pip': json.loads(pip_dependencies) if pip_dependencies else []
159
- }
160
- }
161
- }
162
- return modules_info
163
-
164
- def set_module(self, module_name, module_info):
165
- with sqlite3.connect(self.db_path) as conn:
166
- cursor = conn.cursor()
167
- meta = module_info.get('info', {}).get('meta', {})
168
- dependencies = module_info.get('info', {}).get('dependencies', {})
169
- cursor.execute("""
170
- INSERT OR REPLACE INTO modules (
171
- module_name, status, version, description, author,
172
- dependencies, optional_dependencies, pip_dependencies
173
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
174
- """, (
175
- module_name,
176
- int(module_info.get('status', True)),
177
- meta.get('version', ''),
178
- meta.get('description', ''),
179
- meta.get('author', ''),
180
- json.dumps(dependencies.get('requires', [])),
181
- json.dumps(dependencies.get('optional', [])),
182
- json.dumps(dependencies.get('pip', []))
183
- ))
184
- conn.commit()
185
-
186
- def get_module(self, module_name):
187
- with sqlite3.connect(self.db_path) as conn:
188
- cursor = conn.cursor()
189
- cursor.execute("SELECT * FROM modules WHERE module_name = ?", (module_name,))
190
- row = cursor.fetchone()
191
- if row:
192
- module_name, status, version, description, author, dependencies, optional_dependencies, pip_dependencies = row
193
- return {
194
- 'status': bool(status),
195
- 'info': {
196
- 'meta': {
197
- 'version': version,
198
- 'description': description,
199
- 'author': author,
200
- 'pip_dependencies': json.loads(pip_dependencies) if pip_dependencies else []
201
- },
202
- 'dependencies': {
203
- 'requires': json.loads(dependencies) if dependencies else [],
204
- 'optional': json.loads(optional_dependencies) if optional_dependencies else [],
205
- 'pip': json.loads(pip_dependencies) if pip_dependencies else []
206
- }
207
- }
208
- }
209
- return None
210
-
211
- def update_module(self, module_name, module_info):
212
- self.set_module(module_name, module_info)
213
-
214
- def remove_module(self, module_name):
215
- with sqlite3.connect(self.db_path) as conn:
216
- cursor = conn.cursor()
217
- cursor.execute("DELETE FROM modules WHERE module_name = ?", (module_name,))
218
- conn.commit()
219
- return cursor.rowcount > 0
220
-
221
- def __getattr__(self, key):
222
- try:
223
- return self.get(key)
224
- except KeyError:
225
- raise AttributeError(f"配置项 {key} 不存在")
226
-
227
- env = EnvManager()
ErisPulse/errors.py DELETED
@@ -1,16 +0,0 @@
1
- class CycleDependencyError(Exception):
2
- def __init__(self, message):
3
- self.message = message
4
- super().__init__(self.message)
5
-
6
-
7
- class InvalidDependencyError(Exception):
8
- def __init__(self, message):
9
- self.message = message
10
- super().__init__(self.message)
11
-
12
-
13
- class InvalidModuleError(Exception):
14
- def __init__(self, message):
15
- self.message = message
16
- super().__init__(self.message)
@@ -1,11 +0,0 @@
1
- ErisPulse/__init__.py,sha256=dh9zmUfcxnMGBWZqrOaQf0cTL5tGur74JEu_X_y-7Ek,6445
2
- ErisPulse/__main__.py,sha256=s_SI3U9alSV2vHhHsVdvnA-lksBeFrXqowF5mXwYd_o,40295
3
- ErisPulse/envManager.py,sha256=xUtzP8CWT0KnyyYE8Fm_5UB2VsMi1ODLHMKUoGCWwO4,9304
4
- ErisPulse/errors.py,sha256=DwIQ2nx3GyxSY0ogoeezTSP11MwSVFeR1tx7obkP9Rs,430
5
- ErisPulse/logger.py,sha256=Axlne7pLIsx1baq__37_rn_GGwlz8d6Bet-nuUR0eEc,1419
6
- ErisPulse/util.py,sha256=6SawalGTS7y_TbTY8W6SMTIRN5Z2TgJoHZwQ8zaE_k0,1111
7
- erispulse-1.0.13.dist-info/METADATA,sha256=Rk6UQcjSbK_fOq31HFjdf5wbD7hrZMeXr8cCywrtOW8,2989
8
- erispulse-1.0.13.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
9
- erispulse-1.0.13.dist-info/entry_points.txt,sha256=AjKvOdYR7QGXVpEJhjUYUwV2JluE4lm9vNbknC3hjOM,155
10
- erispulse-1.0.13.dist-info/top_level.txt,sha256=Lm_qtkVvNJR8_dXh_qEDdl_12cZGpic-i4HUlVVUMZc,10
11
- erispulse-1.0.13.dist-info/RECORD,,