pixelarraylib 1.0.6__tar.gz → 1.0.8__tar.gz

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.
Files changed (47) hide show
  1. {pixelarraylib-1.0.6/pixelarraylib.egg-info → pixelarraylib-1.0.8}/PKG-INFO +1 -1
  2. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/__init__.py +1 -1
  3. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/acr.py +8 -8
  4. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/aliyun_email.py +2 -2
  5. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/billing.py +3 -3
  6. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/content_scanner.py +6 -6
  7. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/eci.py +6 -6
  8. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/eip.py +3 -3
  9. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/fc.py +2 -2
  10. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/oss.py +5 -5
  11. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/sms.py +2 -2
  12. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/sts.py +3 -3
  13. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/db_utils/mysql.py +10 -10
  14. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/db_utils/redis.py +18 -18
  15. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/decorators/decorators.py +2 -2
  16. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/scripts/__init__.py +1 -1
  17. pixelarraylib-1.0.8/pixelarraylib/scripts/nginx_proxy_to_ecs.py +163 -0
  18. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/system/common.py +6 -8
  19. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8/pixelarraylib.egg-info}/PKG-INFO +1 -1
  20. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pyproject.toml +1 -1
  21. pixelarraylib-1.0.6/pixelarraylib/scripts/nginx_proxy_to_ecs.py +0 -119
  22. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/LICENSE +0 -0
  23. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/MANIFEST.in +0 -0
  24. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/README.md +0 -0
  25. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/__main__.py +0 -0
  26. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/__init__.py +0 -0
  27. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/domain.py +0 -0
  28. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/aliyun/ecs.py +0 -0
  29. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/decorators/__init__.py +0 -0
  30. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/gitlab/__init__.py +0 -0
  31. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/gitlab/code_analyzer.py +0 -0
  32. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/gitlab/pypi_package_manager.py +0 -0
  33. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/monitor/__init__.py +0 -0
  34. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/monitor/feishu.py +0 -0
  35. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/net/request.py +0 -0
  36. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/scripts/build_website.py +0 -0
  37. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/scripts/collect_code_to_txt.py +0 -0
  38. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/scripts/create_test_case_files.py +0 -0
  39. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/scripts/remove_empty_lines.py +0 -0
  40. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib/system/__init__.py +0 -0
  41. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib.egg-info/SOURCES.txt +0 -0
  42. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib.egg-info/dependency_links.txt +0 -0
  43. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib.egg-info/entry_points.txt +0 -0
  44. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib.egg-info/requires.txt +0 -0
  45. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/pixelarraylib.egg-info/top_level.txt +0 -0
  46. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/requirements.txt +0 -0
  47. {pixelarraylib-1.0.6 → pixelarraylib-1.0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraylib
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: PixelArray Python开发工具库 - 包含阿里云服务、数据库工具、装饰器、监控等功能
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -20,7 +20,7 @@ PixelArray Python开发工具库
20
20
  from pixelarraylib.gitlab import pypi_package_manager
21
21
  """
22
22
 
23
- __version__ = "1.0.6"
23
+ __version__ = "1.0.8"
24
24
  __author__ = "PixelArray"
25
25
  __email__ = "qi.lu@pixelarrayai.com"
26
26
 
@@ -50,7 +50,7 @@ class ACRUtils:
50
50
  response = self.client.list_instance(request)
51
51
  return response.body.to_map(), True
52
52
  except Exception as e:
53
- feishu_alert.send(f"列出实例失败: {e}")
53
+ print(f"列出实例失败: {e}")
54
54
  return {}, False
55
55
 
56
56
  def create_namespace(self, instance_id: str, namespace_name: str):
@@ -72,7 +72,7 @@ class ACRUtils:
72
72
  response = self.client.create_namespace(request)
73
73
  return response.body.to_map(), True
74
74
  except Exception as e:
75
- feishu_alert.send(f"创建命名空间失败: {e}")
75
+ print(f"创建命名空间失败: {e}")
76
76
  return {}, False
77
77
 
78
78
  def delete_namespace(self, instance_id: str, namespace_name: str):
@@ -93,7 +93,7 @@ class ACRUtils:
93
93
  response = self.client.delete_namespace(request)
94
94
  return response.body.to_map(), True
95
95
  except Exception as e:
96
- feishu_alert.send(f"删除命名空间失败: {e}")
96
+ print(f"删除命名空间失败: {e}")
97
97
  return {}, False
98
98
 
99
99
  def list_namespaces(self, instance_id: str):
@@ -111,7 +111,7 @@ class ACRUtils:
111
111
  response = self.client.list_namespace(request)
112
112
  return response.body.to_map(), True
113
113
  except Exception as e:
114
- feishu_alert.send(f"列出命名空间失败: {e}")
114
+ print(f"列出命名空间失败: {e}")
115
115
  return {}, False
116
116
 
117
117
  def exists_namespace(self, instance_id: str, namespace_name: str):
@@ -167,7 +167,7 @@ class ACRUtils:
167
167
  response = self.client.create_repository(request)
168
168
  return response.body.to_map(), True
169
169
  except Exception as e:
170
- feishu_alert.send(f"创建仓库失败: {e}")
170
+ print(f"创建仓库失败: {e}")
171
171
  return {}, False
172
172
 
173
173
  def list_repositories(self, instance_id: str, namespace_name: str):
@@ -188,7 +188,7 @@ class ACRUtils:
188
188
  response = self.client.list_repository(request)
189
189
  return response.body.to_map(), True
190
190
  except Exception as e:
191
- feishu_alert.send(f"列出仓库失败: {e}")
191
+ print(f"列出仓库失败: {e}")
192
192
  return {}, False
193
193
 
194
194
  def exists_repository(
@@ -235,7 +235,7 @@ class ACRUtils:
235
235
  response = self.client.delete_repository(request)
236
236
  return response.body.to_map(), True
237
237
  except Exception as e:
238
- feishu_alert.send(f"删除仓库失败: {e}")
238
+ print(f"删除仓库失败: {e}")
239
239
  return {}, False
240
240
 
241
241
  def get_repository(
@@ -261,5 +261,5 @@ class ACRUtils:
261
261
  response = self.client.get_repository(request)
262
262
  return response.body.to_map(), True
263
263
  except Exception as e:
264
- feishu_alert.send(f"获取仓库详情失败: {e}")
264
+ print(f"获取仓库详情失败: {e}")
265
265
  return {}, False
@@ -122,9 +122,9 @@ class AliyunEmailSender:
122
122
  if response.status_code == 200:
123
123
  return True
124
124
  else:
125
- feishu_alert.send(f"发送验证邮件失败: {response}")
125
+ print(f"发送验证邮件失败: {response}")
126
126
  return False
127
127
 
128
128
  except Exception as e:
129
- feishu_alert.send(traceback.format_exc())
129
+ print(traceback.format_exc())
130
130
  return False
@@ -244,7 +244,7 @@ class BillingUtils:
244
244
  return formatted_response
245
245
 
246
246
  except Exception as e:
247
- feishu_alert.send(traceback.format_exc())
247
+ print(traceback.format_exc())
248
248
  error_response = {
249
249
  "Message": add_comment(f"Format error: {str(e)}", "Message"),
250
250
  "RequestId": add_comment(
@@ -326,7 +326,7 @@ class BillingUtils:
326
326
  return formatted_response
327
327
 
328
328
  except Exception as error:
329
- feishu_alert.send(traceback.format_exc())
329
+ print(traceback.format_exc())
330
330
  error_msg = getattr(error, "message", str(error))
331
331
  # 诊断地址
332
332
  diagnose_url = ""
@@ -473,5 +473,5 @@ class BillingUtils:
473
473
  return output_path
474
474
 
475
475
  except Exception as e:
476
- feishu_alert.send(traceback.format_exc())
476
+ print(traceback.format_exc())
477
477
  raise Exception(f"保存账单数据失败: {str(e)}")
@@ -71,7 +71,7 @@ class ContentScanner:
71
71
  else ({}, False)
72
72
  )
73
73
  except Exception as e:
74
- feishu_alert.send(traceback.format_exc())
74
+ print(traceback.format_exc())
75
75
  return {}, False
76
76
 
77
77
  def scan_image(
@@ -110,7 +110,7 @@ class ContentScanner:
110
110
  else ({}, False)
111
111
  )
112
112
  except Exception as e:
113
- feishu_alert.send(traceback.format_exc())
113
+ print(traceback.format_exc())
114
114
  return {}, False
115
115
 
116
116
  def scan_video(
@@ -151,7 +151,7 @@ class ContentScanner:
151
151
  else ("", False)
152
152
  )
153
153
  except Exception as e:
154
- feishu_alert.send(traceback.format_exc())
154
+ print(traceback.format_exc())
155
155
  return "", False
156
156
 
157
157
  def get_video_result(
@@ -181,7 +181,7 @@ class ContentScanner:
181
181
  else ({}, False)
182
182
  )
183
183
  except Exception as e:
184
- feishu_alert.send(traceback.format_exc())
184
+ print(traceback.format_exc())
185
185
  return {}, False
186
186
 
187
187
  def scan_voice(
@@ -219,7 +219,7 @@ class ContentScanner:
219
219
  else ("", False)
220
220
  )
221
221
  except Exception as e:
222
- feishu_alert.send(traceback.format_exc())
222
+ print(traceback.format_exc())
223
223
  return "", False
224
224
 
225
225
  def get_voice_result(
@@ -249,5 +249,5 @@ class ContentScanner:
249
249
  else ({}, False)
250
250
  )
251
251
  except Exception as e:
252
- feishu_alert.send(traceback.format_exc())
252
+ print(traceback.format_exc())
253
253
  return {}, False
@@ -82,7 +82,7 @@ class ECIUtils:
82
82
  )
83
83
  return response.body.to_map(), True
84
84
  except Exception as error:
85
- feishu_alert.send(f"查询可用资源失败: {error}")
85
+ print(f"查询可用资源失败: {error}")
86
86
  return {}
87
87
 
88
88
  def create_container_group(
@@ -131,7 +131,7 @@ class ECIUtils:
131
131
  if allocate_public_ip:
132
132
  response, success = self.eip_utils.allocate_eip()
133
133
  if not success:
134
- feishu_alert.send(f"创建容器组失败: 分配公网IP失败")
134
+ print(f"创建容器组失败: 分配公网IP失败")
135
135
  return {}, False
136
136
  eip_instance_id = response["AllocationId"]
137
137
  else:
@@ -163,7 +163,7 @@ class ECIUtils:
163
163
  )
164
164
  return response.body.to_map(), True
165
165
  except Exception as error:
166
- feishu_alert.send(f"创建容器组失败: {error}")
166
+ print(f"创建容器组失败: {error}")
167
167
  return {}, False
168
168
 
169
169
  def describe_container_group(self, container_group_id: str):
@@ -186,7 +186,7 @@ class ECIUtils:
186
186
  )
187
187
  return response.body.to_map()
188
188
  except Exception as error:
189
- feishu_alert.send(f"查询容器组失败: {error}")
189
+ print(f"查询容器组失败: {error}")
190
190
  return {}
191
191
 
192
192
  def list_container_groups(self):
@@ -208,7 +208,7 @@ class ECIUtils:
208
208
  )
209
209
  return response.body.to_map()
210
210
  except Exception as error:
211
- feishu_alert.send(f"查询容器组列表失败: {error}")
211
+ print(f"查询容器组列表失败: {error}")
212
212
  return {}
213
213
 
214
214
  def delete_container_group(self, container_group_id: str):
@@ -232,5 +232,5 @@ class ECIUtils:
232
232
  )
233
233
  return response.body.to_map(), True
234
234
  except Exception as error:
235
- feishu_alert.send(f"删除容器组失败: {error}")
235
+ print(f"删除容器组失败: {error}")
236
236
  return {}, False
@@ -48,7 +48,7 @@ class EIPUtils:
48
48
  )
49
49
  return response.body.to_map(), True
50
50
  except Exception as error:
51
- feishu_alert.send(f"分配EIP失败: {error}")
51
+ print(f"分配EIP失败: {error}")
52
52
  return {}, False
53
53
 
54
54
  def release_eip(self, allocation_id: str):
@@ -71,7 +71,7 @@ class EIPUtils:
71
71
  )
72
72
  return response.body.to_map(), True
73
73
  except Exception as error:
74
- feishu_alert.send(f"释放EIP失败: {error}")
74
+ print(f"释放EIP失败: {error}")
75
75
  return {}, False
76
76
 
77
77
  def list_eips(self):
@@ -92,5 +92,5 @@ class EIPUtils:
92
92
  )
93
93
  return response.body.to_map(), True
94
94
  except Exception as error:
95
- feishu_alert.send(f"查询EIP列表失败: {error}")
95
+ print(f"查询EIP列表失败: {error}")
96
96
  return {}, False
@@ -69,7 +69,7 @@ class FCUtils:
69
69
  else:
70
70
  return None, False
71
71
  # 如果所有重试都失败,返回最后一次的异常信息
72
- feishu_alert.send(
72
+ print(
73
73
  f"aliyun fc invoke_function failed after {retry} retries. Last error: {last_exception}"
74
74
  )
75
75
  return None, False
@@ -136,7 +136,7 @@ class FCUtils:
136
136
  else:
137
137
  return False
138
138
  # 如果所有重试都失败,返回最后一次的异常信息
139
- feishu_alert.send(
139
+ print(
140
140
  f"aliyun fc update_function failed after {retry} retries. Last error: {last_exception}"
141
141
  )
142
142
  return False
@@ -135,7 +135,7 @@ class OSSUtils:
135
135
  self.client.delete_object(obj.key)
136
136
  return True
137
137
  except Exception as e:
138
- feishu_alert.send(traceback.format_exc())
138
+ print(traceback.format_exc())
139
139
  return False
140
140
 
141
141
  def ls(self, prefix):
@@ -206,7 +206,7 @@ class OSSUtils:
206
206
  return True
207
207
  return False
208
208
  except Exception as e:
209
- feishu_alert.send(traceback.format_exc())
209
+ print(traceback.format_exc())
210
210
  return False
211
211
 
212
212
  def download_object(self, prefix, dir_path):
@@ -231,7 +231,7 @@ class OSSUtils:
231
231
  self.client.get_object_to_file(prefix, download_path)
232
232
  return True
233
233
  except Exception as e:
234
- feishu_alert.send(f"oss download_object error: {traceback.format_exc()}")
234
+ print(f"oss download_object error: {traceback.format_exc()}")
235
235
  return False
236
236
 
237
237
  def upload_object(self, prefix, local_path):
@@ -255,7 +255,7 @@ class OSSUtils:
255
255
  )
256
256
  return True
257
257
  except Exception as e:
258
- feishu_alert.send(traceback.format_exc())
258
+ print(traceback.format_exc())
259
259
  return False
260
260
 
261
261
  def copy_object(self, prefix, target_prefix):
@@ -274,7 +274,7 @@ class OSSUtils:
274
274
  )
275
275
  return True
276
276
  except Exception as e:
277
- feishu_alert.send(traceback.format_exc())
277
+ print(traceback.format_exc())
278
278
  return False
279
279
 
280
280
  def generate_presigned_url(self, prefix, expires_in=60 * 60 * 24):
@@ -52,8 +52,8 @@ class SMSUtils:
52
52
  response and response.status_code == 200 and response.body.code == "OK"
53
53
  )
54
54
  if not flag:
55
- feishu_alert.send(f"短信发送失败: {response}")
55
+ print(f"短信发送失败: {response}")
56
56
  return flag
57
57
  except Exception as e:
58
- feishu_alert.send("短信发送失败: " + traceback.format_exc())
58
+ print("短信发送失败: " + traceback.format_exc())
59
59
  return False
@@ -76,7 +76,7 @@ class STSUtils:
76
76
  )
77
77
  return credentials, True
78
78
  except Exception as e:
79
- feishu_alert.send(traceback.format_exc())
79
+ print(traceback.format_exc())
80
80
  return {}, False
81
81
 
82
82
  def get_oss_sts_client(self, endpoint, bucket_name):
@@ -99,7 +99,7 @@ class STSUtils:
99
99
  )
100
100
  return oss2.Bucket(auth, endpoint, bucket_name), True
101
101
  except Exception as e:
102
- feishu_alert.send(traceback.format_exc())
102
+ print(traceback.format_exc())
103
103
  return None, False
104
104
 
105
105
  def generate_presigned_url(self, prefix, expires_in=60 * 60 * 24):
@@ -120,5 +120,5 @@ class STSUtils:
120
120
  return ""
121
121
  return sts_oss_client.sign_url("GET", prefix, expires_in)
122
122
  except Exception as e:
123
- feishu_alert.send(traceback.format_exc())
123
+ print(traceback.format_exc())
124
124
  return ""
@@ -46,12 +46,12 @@ class MysqlUtils:
46
46
  break # 连接成功,跳出重试循环
47
47
  except OperationalError as e:
48
48
  if attempt < self.max_retries - 1:
49
- feishu_alert.send(
49
+ print(
50
50
  f"MySQL连接失败,正在重试 ({attempt + 1}/{self.max_retries}): {str(e)}"
51
51
  )
52
52
  time.sleep(2**attempt) # 指数退避
53
53
  else:
54
- feishu_alert.send(f"MySQL连接最终失败: {traceback.format_exc()}")
54
+ print(f"MySQL连接最终失败: {traceback.format_exc()}")
55
55
  raise
56
56
 
57
57
  def get_conn(self):
@@ -198,7 +198,7 @@ class MysqlUtils:
198
198
  print(f"插入/更新 {i} / {len(rows)} 行到 {table_name}")
199
199
  return True
200
200
  except Exception as e:
201
- feishu_alert.send(f"mysql-insert_or_update error {traceback.format_exc()}")
201
+ print(f"mysql-insert_or_update error {traceback.format_exc()}")
202
202
  return False
203
203
 
204
204
  def query(self, sql, convert_to_dict=False):
@@ -225,7 +225,7 @@ class MysqlUtils:
225
225
  return [dict(zip(columns, row)) for row in result]
226
226
  return list(result)
227
227
  except Exception as e:
228
- feishu_alert.send(f"mysql-query error {traceback.format_exc()}")
228
+ print(f"mysql-query error {traceback.format_exc()}")
229
229
  return []
230
230
  finally:
231
231
  cursor.close()
@@ -247,7 +247,7 @@ class MysqlUtils:
247
247
  return True
248
248
  except Exception as e:
249
249
  self.mysql.rollback()
250
- feishu_alert.send(f"mysql-execute error {traceback.format_exc()}")
250
+ print(f"mysql-execute error {traceback.format_exc()}")
251
251
  return False
252
252
  finally:
253
253
  cursor.close()
@@ -305,12 +305,12 @@ class MysqlUtilsAsync:
305
305
  break # 连接成功,跳出重试循环
306
306
  except Exception as e:
307
307
  if attempt < self.max_retries - 1:
308
- feishu_alert.send(
308
+ print(
309
309
  f"异步MySQL连接失败,正在重试 ({attempt + 1}/{self.max_retries}): {str(e)}"
310
310
  )
311
311
  await asyncio.sleep(2**attempt) # 指数退避
312
312
  else:
313
- feishu_alert.send(
313
+ print(
314
314
  f"异步MySQL连接最终失败: {traceback.format_exc()}"
315
315
  )
316
316
  raise
@@ -462,7 +462,7 @@ class MysqlUtilsAsync:
462
462
  print(f"插入/更新 {i} / {len(rows)} 行到 {table_name}")
463
463
  return True
464
464
  except Exception as e:
465
- feishu_alert.send(
465
+ print(
466
466
  f"mysql-insert_or_update_async error {traceback.format_exc()}"
467
467
  )
468
468
  return False
@@ -493,7 +493,7 @@ class MysqlUtilsAsync:
493
493
  return [dict(zip(columns, row)) for row in result]
494
494
  return list(result)
495
495
  except Exception as e:
496
- feishu_alert.send(f"mysql-query_async error {traceback.format_exc()}")
496
+ print(f"mysql-query_async error {traceback.format_exc()}")
497
497
  return []
498
498
  finally:
499
499
  if cursor:
@@ -519,7 +519,7 @@ class MysqlUtilsAsync:
519
519
  except Exception as e:
520
520
  async_mysql = await self.get_async_conn()
521
521
  await async_mysql.rollback()
522
- feishu_alert.send(f"mysql-execute_async error {traceback.format_exc()}")
522
+ print(f"mysql-execute_async error {traceback.format_exc()}")
523
523
  return False
524
524
  finally:
525
525
  if cursor:
@@ -34,7 +34,7 @@ class RedisUtils:
34
34
  self.redis_client.set(key, value, ex=expire_seconds)
35
35
  return True
36
36
  except Exception as e:
37
- feishu_alert.send(traceback.format_exc())
37
+ print(traceback.format_exc())
38
38
  return False
39
39
 
40
40
  def get(self, key, default_value=""):
@@ -53,7 +53,7 @@ class RedisUtils:
53
53
  return default_value
54
54
  return value.decode()
55
55
  except Exception as e:
56
- feishu_alert.send(traceback.format_exc())
56
+ print(traceback.format_exc())
57
57
  return default_value
58
58
 
59
59
  def delete(self, key):
@@ -69,7 +69,7 @@ class RedisUtils:
69
69
  self.redis_client.delete(key)
70
70
  return True
71
71
  except Exception as e:
72
- feishu_alert.send(traceback.format_exc())
72
+ print(traceback.format_exc())
73
73
  return False
74
74
 
75
75
  def delete_many(self, keys: List[str]) -> bool:
@@ -85,7 +85,7 @@ class RedisUtils:
85
85
  self.redis_client.delete(*keys)
86
86
  return True
87
87
  except Exception as e:
88
- feishu_alert.send(traceback.format_exc())
88
+ print(traceback.format_exc())
89
89
  return False
90
90
 
91
91
  def set_hash(self, key, field, value, expire_seconds=None):
@@ -106,7 +106,7 @@ class RedisUtils:
106
106
  self.redis_client.expire(key, expire_seconds)
107
107
  return True
108
108
  except Exception as e:
109
- feishu_alert.send(traceback.format_exc())
109
+ print(traceback.format_exc())
110
110
  return False
111
111
 
112
112
  def get_hash(self, key, field):
@@ -125,7 +125,7 @@ class RedisUtils:
125
125
  return ""
126
126
  return value.decode()
127
127
  except Exception as e:
128
- feishu_alert.send(traceback.format_exc())
128
+ print(traceback.format_exc())
129
129
  return ""
130
130
 
131
131
  def delete_hash(self, key, field):
@@ -142,7 +142,7 @@ class RedisUtils:
142
142
  self.redis_client.hdel(key, field)
143
143
  return True
144
144
  except Exception as e:
145
- feishu_alert.send(traceback.format_exc())
145
+ print(traceback.format_exc())
146
146
  return False
147
147
 
148
148
  def list_hash_keys(self, key):
@@ -157,7 +157,7 @@ class RedisUtils:
157
157
  try:
158
158
  return [key.decode() for key in self.redis_client.hkeys(key)]
159
159
  except Exception as e:
160
- feishu_alert.send(traceback.format_exc())
160
+ print(traceback.format_exc())
161
161
  return []
162
162
 
163
163
  def list_keys(self, prefix=""):
@@ -183,7 +183,7 @@ class RedisUtils:
183
183
  break
184
184
  return [key.decode() for key in keys]
185
185
  except Exception as e:
186
- feishu_alert.send(traceback.format_exc())
186
+ print(traceback.format_exc())
187
187
  return []
188
188
 
189
189
  def __del__(self):
@@ -214,7 +214,7 @@ class RedisUtilsAsync:
214
214
  await self.async_redis_client.set(key, value, ex=expire_seconds)
215
215
  return True
216
216
  except Exception as e:
217
- feishu_alert.send(traceback.format_exc())
217
+ print(traceback.format_exc())
218
218
  return False
219
219
 
220
220
  async def get(self, key, default_value=""):
@@ -233,7 +233,7 @@ class RedisUtilsAsync:
233
233
  return default_value
234
234
  return value.decode()
235
235
  except Exception as e:
236
- feishu_alert.send(traceback.format_exc())
236
+ print(traceback.format_exc())
237
237
  return default_value
238
238
 
239
239
  async def delete(self, key):
@@ -249,7 +249,7 @@ class RedisUtilsAsync:
249
249
  await self.async_redis_client.delete(key)
250
250
  return True
251
251
  except Exception as e:
252
- feishu_alert.send(traceback.format_exc())
252
+ print(traceback.format_exc())
253
253
  return False
254
254
 
255
255
  async def delete_many(self, keys: List[str]) -> bool:
@@ -265,7 +265,7 @@ class RedisUtilsAsync:
265
265
  await self.async_redis_client.delete(*keys)
266
266
  return True
267
267
  except Exception as e:
268
- feishu_alert.send(traceback.format_exc())
268
+ print(traceback.format_exc())
269
269
  return False
270
270
 
271
271
  async def set_hash(self, key, field, value, expire_seconds=None):
@@ -286,7 +286,7 @@ class RedisUtilsAsync:
286
286
  await self.async_redis_client.expire(key, expire_seconds)
287
287
  return True
288
288
  except Exception as e:
289
- feishu_alert.send(traceback.format_exc())
289
+ print(traceback.format_exc())
290
290
  return False
291
291
 
292
292
  async def get_hash(self, key, field):
@@ -305,7 +305,7 @@ class RedisUtilsAsync:
305
305
  return ""
306
306
  return value.decode()
307
307
  except Exception as e:
308
- feishu_alert.send(traceback.format_exc())
308
+ print(traceback.format_exc())
309
309
  return ""
310
310
 
311
311
  async def delete_hash(self, key, field):
@@ -322,7 +322,7 @@ class RedisUtilsAsync:
322
322
  await self.async_redis_client.hdel(key, field)
323
323
  return True
324
324
  except Exception as e:
325
- feishu_alert.send(traceback.format_exc())
325
+ print(traceback.format_exc())
326
326
  return False
327
327
 
328
328
  async def list_hash_keys(self, key):
@@ -338,7 +338,7 @@ class RedisUtilsAsync:
338
338
  keys = await self.async_redis_client.hkeys(key)
339
339
  return [key.decode() for key in keys]
340
340
  except Exception as e:
341
- feishu_alert.send(traceback.format_exc())
341
+ print(traceback.format_exc())
342
342
  return []
343
343
 
344
344
  async def list_keys(self, prefix=""):
@@ -364,7 +364,7 @@ class RedisUtilsAsync:
364
364
  break
365
365
  return [key.decode() for key in keys]
366
366
  except Exception as e:
367
- feishu_alert.send(traceback.format_exc())
367
+ print(traceback.format_exc())
368
368
  return []
369
369
 
370
370
  async def close(self):
@@ -38,7 +38,7 @@ def catch_exception(
38
38
  alert_message = f"文件{os.path.relpath(inspect.getfile(func))}中的函数{get_caller_function_name()}执行失败,{alert_params_str},错误信息如下:\n {traceback.format_exc()}"
39
39
  if addtional_alert:
40
40
  alert_message += f"\n{addtional_alert}"
41
- feishu_alert.send(alert_message)
41
+ print(alert_message)
42
42
  return exception_return
43
43
 
44
44
  @wraps(func)
@@ -50,7 +50,7 @@ def catch_exception(
50
50
  alert_message = f"文件{os.path.relpath(inspect.getfile(func))}中的函数{get_caller_function_name()}执行失败,{alert_params_str},错误信息如下:\n {traceback.format_exc()}"
51
51
  if addtional_alert:
52
52
  alert_message += f"\n{addtional_alert}"
53
- feishu_alert.send(alert_message)
53
+ print(alert_message)
54
54
  return exception_return
55
55
 
56
56
  if asyncio.iscoroutinefunction(func):
@@ -3,7 +3,7 @@ ArrayLib 脚本工具包
3
3
  包含各种实用的命令行工具和脚本
4
4
  """
5
5
 
6
- __version__ = "1.0.6"
6
+ __version__ = "1.0.8"
7
7
  __author__ = "Lu qi"
8
8
 
9
9
  # 导出主要的脚本函数
@@ -0,0 +1,163 @@
1
+ import argparse
2
+ import base64
3
+ from pixelarraylib.system.common import execute_command_through_ssh, execute_command
4
+ from pixelarraylib.aliyun.domain import DomainUtils
5
+
6
+
7
+ def nginx_proxy_file_template(
8
+ domain_name: str, port_of_service: str, ssl_cert_path: str, ssl_key_path: str
9
+ ) -> str:
10
+ return f"""
11
+ server {{
12
+ listen 80;
13
+ server_name {domain_name}.pixelarrayai.com;
14
+
15
+ # 将所有HTTP请求重定向到HTTPS
16
+ return 301 https://$host$request_uri;
17
+ }}
18
+
19
+ server {{
20
+ listen 443 ssl;
21
+ server_name {domain_name}.pixelarrayai.com;
22
+
23
+ ssl_certificate {ssl_cert_path};
24
+ ssl_certificate_key {ssl_key_path};
25
+
26
+ location / {{
27
+ proxy_pass http://localhost:{port_of_service};
28
+ proxy_http_version 1.1;
29
+ proxy_set_header Host $host;
30
+ proxy_set_header X-Real-IP $remote_addr;
31
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32
+ proxy_set_header X-Forwarded-Proto $scheme;
33
+ }}
34
+ }}
35
+ """
36
+
37
+
38
+ def add_a_record_to_dns(
39
+ domain_name: str, ecs_ip: str, access_key_id: str, access_key_secret: str
40
+ ) -> None:
41
+ domain_utils = DomainUtils(
42
+ access_key_id, access_key_secret, domain_name="pixelarrayai.com"
43
+ )
44
+
45
+ # 先检查是否存在相同的主机记录
46
+ existing_record = domain_utils.find_record_by_rr_and_type(rr=domain_name, type="A")
47
+ if existing_record:
48
+ print(f"发现已存在的主机记录 {domain_name},正在删除...")
49
+ success = domain_utils.delete_record_by_rr_and_type(rr=domain_name, type="A")
50
+ if success:
51
+ print(f"已删除旧的主机记录 {domain_name}")
52
+ else:
53
+ print(f"删除旧记录失败,但继续添加新记录")
54
+
55
+ # 添加新的解析记录
56
+ success, record_id = domain_utils.add_domain_record(
57
+ rr=domain_name,
58
+ type="A",
59
+ value=ecs_ip,
60
+ )
61
+
62
+ if success:
63
+ print(f"域名解析记录添加成功,记录ID: {record_id}")
64
+ else:
65
+ print("域名解析记录添加失败")
66
+
67
+
68
+ def deploy(
69
+ domain_name: str,
70
+ port_of_service: str,
71
+ ssl_cert_path: str,
72
+ ssl_key_path: str,
73
+ access_key_id: str,
74
+ access_key_secret: str,
75
+ mode: str,
76
+ ecs_ip: str,
77
+ ) -> None:
78
+ if mode == "remote":
79
+ execute_command_through_ssh(
80
+ ecs_ip,
81
+ f"sudo rm -f /etc/nginx/sites-available/{domain_name} && sudo rm -f /etc/nginx/sites-enabled/{domain_name}",
82
+ )
83
+ print("删除原有配置成功")
84
+ execute_command_through_ssh(
85
+ ecs_ip,
86
+ f"sudo touch /etc/nginx/sites-available/{domain_name}",
87
+ )
88
+ print("文件创建成功")
89
+ nginx_proxy_file_content = nginx_proxy_file_template(
90
+ domain_name, port_of_service, ssl_cert_path, ssl_key_path
91
+ )
92
+ # 使用 base64 编码来避免特殊字符问题
93
+ encoded_content = base64.b64encode(nginx_proxy_file_content.encode('utf-8')).decode('utf-8')
94
+ execute_command_through_ssh(
95
+ ecs_ip,
96
+ f"echo '{encoded_content}' | base64 -d | sudo tee /etc/nginx/sites-available/{domain_name} > /dev/null",
97
+ )
98
+ print("内容写入成功")
99
+ execute_command_through_ssh(
100
+ ecs_ip,
101
+ f"sudo ln -s /etc/nginx/sites-available/{domain_name} /etc/nginx/sites-enabled/{domain_name}",
102
+ )
103
+ print("nginx配置添加成功,准备重启")
104
+ execute_command_through_ssh(
105
+ ecs_ip, f"sudo nginx -t && sudo systemctl restart nginx"
106
+ )
107
+ print("重启成功,请检查配置是否生效")
108
+ else:
109
+ execute_command(
110
+ f"sudo rm -f /etc/nginx/sites-available/{domain_name} && sudo rm -f /etc/nginx/sites-enabled/{domain_name}"
111
+ )
112
+ print("删除原有配置成功")
113
+ execute_command(
114
+ f"sudo touch /etc/nginx/sites-available/{domain_name}"
115
+ )
116
+ print("文件创建成功")
117
+ nginx_proxy_file_content = nginx_proxy_file_template(
118
+ domain_name, port_of_service, ssl_cert_path, ssl_key_path
119
+ )
120
+ execute_command(
121
+ f"sudo echo {nginx_proxy_file_content} | base64 -d | sudo tee /etc/nginx/sites-available/{domain_name} > /dev/null"
122
+ )
123
+ print("内容写入成功")
124
+ execute_command(
125
+ f"sudo ln -s /etc/nginx/sites-available/{domain_name} /etc/nginx/sites-enabled/{domain_name}"
126
+ )
127
+ print("nginx配置添加成功,准备重启")
128
+ execute_command(
129
+ "sudo nginx -t && sudo systemctl restart nginx"
130
+ )
131
+ print("重启成功,请检查配置是否生效")
132
+ add_a_record_to_dns(domain_name, ecs_ip, access_key_id, access_key_secret)
133
+
134
+
135
+ def main():
136
+ parser = argparse.ArgumentParser(
137
+ description="Nginx反向代理配置到ECS",
138
+ formatter_class=argparse.RawDescriptionHelpFormatter,
139
+ epilog=__doc__,
140
+ )
141
+ parser.add_argument("--domain_name", "-d", help="需要代理的域名")
142
+ parser.add_argument("--port_of_service", "-p", help="端口或服务")
143
+ parser.add_argument("--access_key_id", "-a", help="阿里云AccessKeyID")
144
+ parser.add_argument("--access_key_secret", "-s", help="阿里云AccessKeySecret")
145
+ parser.add_argument("--mode", "-m", help="本地执行还是远程执行,local或remote,默认是remote")
146
+ parser.add_argument("--ecs_ip", "-e", help="服务器的IP地址")
147
+
148
+ args = parser.parse_args()
149
+
150
+ deploy(
151
+ args.domain_name,
152
+ args.port_of_service,
153
+ "/var/pixelarray/ssl_auth/pixelarrayai.com.pem",
154
+ "/var/pixelarray/ssl_auth/pixelarrayai.com.key",
155
+ args.access_key_id,
156
+ args.access_key_secret,
157
+ args.mode,
158
+ args.ecs_ip,
159
+ )
160
+
161
+
162
+ if __name__ == "__main__":
163
+ main()
@@ -216,7 +216,7 @@ def split_content_into_sentences(
216
216
  sentences = [re.sub(r"[^\w\s]", "", s) for s in sentences]
217
217
  return sentences, True
218
218
  except Exception as e:
219
- feishu_alert.send(f"分割内容时发生错误: {traceback.format_exc()}")
219
+ print(f"分割内容时发生错误: {traceback.format_exc()}")
220
220
  return [], False
221
221
 
222
222
 
@@ -234,7 +234,7 @@ def remove_all_punctuation(text: str) -> tuple[str, bool]:
234
234
  # 使用正则表达式去除所有标点符号
235
235
  return re.sub(r"[^\w\s]", "", text), True
236
236
  except Exception as e:
237
- feishu_alert.send(f"去除标点符号时发生错误: {traceback.format_exc()}")
237
+ print(f"去除标点符号时发生错误: {traceback.format_exc()}")
238
238
  return text, False
239
239
 
240
240
 
@@ -263,16 +263,15 @@ def execute_command(command: Union[str, List[str]]) -> str:
263
263
  try:
264
264
  if isinstance(command, str):
265
265
  command = command.split()
266
- print(command)
267
266
  result = subprocess.run(
268
267
  command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
269
268
  )
270
269
  return result.stdout.decode(), True
271
270
  except subprocess.CalledProcessError as e:
272
- feishu_alert.send(
271
+ print(
273
272
  f"执行命令失败,命令: {command},错误信息: {e.stderr.decode() if e.stderr else str(e)}"
274
273
  )
275
- return None, False
274
+ return e.stderr.decode() if e.stderr else "", False
276
275
 
277
276
 
278
277
  async def execute_command_async(command: Union[str, List[str]]) -> str:
@@ -287,17 +286,16 @@ async def execute_command_async(command: Union[str, List[str]]) -> str:
287
286
  try:
288
287
  if isinstance(command, str):
289
288
  command = command.split()
290
- print(command)
291
289
  result = await asyncio.create_subprocess_exec(
292
290
  *command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
293
291
  )
294
292
  stdout, stderr = await result.communicate()
295
293
  return stdout.decode(), True
296
294
  except subprocess.CalledProcessError as e:
297
- feishu_alert.send(
295
+ print(
298
296
  f"异步执行命令失败,命令: {command},错误信息: {e.stderr.decode() if e.stderr else str(e)}"
299
297
  )
300
- return None, False
298
+ return e.stderr.decode() if e.stderr else "", False
301
299
 
302
300
 
303
301
  def get_variable_type(variable: object) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pixelarraylib
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: PixelArray Python开发工具库 - 包含阿里云服务、数据库工具、装饰器、监控等功能
5
5
  Author-email: Lu qi <qi.lu@pixelarrayai.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pixelarraylib"
7
- version = "1.0.6"
7
+ version = "1.0.8"
8
8
  authors = [
9
9
  {name = "Lu qi", email = "qi.lu@pixelarrayai.com"},
10
10
  ]
@@ -1,119 +0,0 @@
1
- import argparse
2
- import base64
3
- from pixelarraylib.system.common import execute_command_through_ssh
4
- from pixelarraylib.aliyun.domain import DomainUtils
5
-
6
-
7
- def nginx_proxy_file_template(
8
- domain_name: str, port_of_service: str, ssl_cert_path: str, ssl_key_path: str
9
- ) -> str:
10
- return f"""
11
- server {{
12
- listen 80;
13
- server_name {domain_name}.pixelarrayai.com;
14
-
15
- # 将所有HTTP请求重定向到HTTPS
16
- return 301 https://$host$request_uri;
17
- }}
18
-
19
- server {{
20
- listen 443 ssl;
21
- server_name {domain_name}.pixelarrayai.com;
22
-
23
- ssl_certificate {ssl_cert_path};
24
- ssl_certificate_key {ssl_key_path};
25
-
26
- location / {{
27
- proxy_pass http://localhost:{port_of_service};
28
- proxy_http_version 1.1;
29
- proxy_set_header Host $host;
30
- proxy_set_header X-Real-IP $remote_addr;
31
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32
- proxy_set_header X-Forwarded-Proto $scheme;
33
- }}
34
- }}
35
- """
36
-
37
-
38
- def add_a_record_to_dns(
39
- domain_name: str, ecs_ip: str, access_key_id: str, access_key_secret: str
40
- ) -> None:
41
- domain_utils = DomainUtils(
42
- access_key_id, access_key_secret, domain_name="pixelarrayai.com"
43
- )
44
- domain_utils.add_domain_record(
45
- rr=domain_name,
46
- type="A",
47
- value=ecs_ip,
48
- )
49
- print("域名解析记录添加成功")
50
-
51
-
52
- def deploy(
53
- ecs_ip: str,
54
- domain_name: str,
55
- port_of_service: str,
56
- ssl_cert_path: str,
57
- ssl_key_path: str,
58
- access_key_id: str,
59
- access_key_secret: str,
60
- ) -> None:
61
- execute_command_through_ssh(
62
- ecs_ip,
63
- f"sudo rm -f /etc/nginx/sites-available/{domain_name} && sudo rm -f /etc/nginx/sites-enabled/{domain_name}",
64
- )
65
- print("删除原有配置成功")
66
- execute_command_through_ssh(
67
- ecs_ip,
68
- f"sudo touch /etc/nginx/sites-available/{domain_name}",
69
- )
70
- print("文件创建成功")
71
- nginx_proxy_file_content = nginx_proxy_file_template(
72
- domain_name, port_of_service, ssl_cert_path, ssl_key_path
73
- )
74
- # 使用 base64 编码来避免特殊字符问题
75
- encoded_content = base64.b64encode(nginx_proxy_file_content.encode('utf-8')).decode('utf-8')
76
- execute_command_through_ssh(
77
- ecs_ip,
78
- f"echo '{encoded_content}' | base64 -d | sudo tee /etc/nginx/sites-available/{domain_name} > /dev/null",
79
- )
80
- print("内容写入成功")
81
- execute_command_through_ssh(
82
- ecs_ip,
83
- f"sudo ln -s /etc/nginx/sites-available/{domain_name} /etc/nginx/sites-enabled/{domain_name}",
84
- )
85
- print("nginx配置添加成功,准备重启")
86
- execute_command_through_ssh(
87
- ecs_ip, f"sudo nginx -t && sudo systemctl restart nginx"
88
- )
89
- print("重启成功,请检查配置是否生效")
90
- add_a_record_to_dns(domain_name, ecs_ip, access_key_id, access_key_secret)
91
-
92
-
93
- def main():
94
- parser = argparse.ArgumentParser(
95
- description="Nginx反向代理配置到ECS",
96
- formatter_class=argparse.RawDescriptionHelpFormatter,
97
- epilog=__doc__,
98
- )
99
- parser.add_argument("--ecs_ip", "-e", help="服务IP地址")
100
- parser.add_argument("--domain_name", "-d", help="需要代理的域名")
101
- parser.add_argument("--port_of_service", "-p", help="端口或服务")
102
- parser.add_argument("--access_key_id", "-a", help="阿里云AccessKeyID")
103
- parser.add_argument("--access_key_secret", "-s", help="阿里云AccessKeySecret")
104
-
105
- args = parser.parse_args()
106
-
107
- deploy(
108
- args.ecs_ip,
109
- args.domain_name,
110
- args.port_of_service,
111
- "/var/pixelarray/ssl_auth/pixelarrayai.com.pem",
112
- "/var/pixelarray/ssl_auth/pixelarrayai.com.key",
113
- args.access_key_id,
114
- args.access_key_secret,
115
- )
116
-
117
-
118
- if __name__ == "__main__":
119
- main()
File without changes
File without changes
File without changes
File without changes