diff --git a/sso/sso_script.py b/sso/sso_script.py index 2209e6b..b1d0e2b 100644 --- a/sso/sso_script.py +++ b/sso/sso_script.py @@ -20,6 +20,7 @@ from django.utils.timezone import get_current_timezone, localtime, now import datetime import utils.const import django.conf +import utils.dataintel # --- 功能函数定义 --- @@ -175,6 +176,58 @@ def update_product(new_product_id, batch_id, start, stop): return sns.last().serialize() +def filter_xdp_device_info(keyword): + engine = get_engine('device_info') + try: + if len(keyword) == 4: + result = engine.filter(passcode=keyword)[0] + else: + result = engine.filter(psn=keyword)[0] + except IndexError: + result = None + print("未找到设备信息") + return + + # 定义 RSA 相关的字段 + rsa_keys = ['rsa_public_key', 'rsa_private_key'] + # 定义不需要在表格中展示的字段 + exclude_fields = ['_read_perm', '_write_perm', 'created_by', 'mcu_uid'] + + # 分离 RSA 字段和其他字段 + rsa_data = {} + table_data = {} + for key, value in result.items(): + if key in rsa_keys: + rsa_data[key] = value + elif key in ['created_at', 'updated_at']: + table_data[key] = utils.dataintel.strf_time(utils.timestamp_to_local_datetime(value)) + elif key not in exclude_fields: + table_data[key] = value + + # 计算表格宽度 + max_key_len = max(len(str(k)) for k in table_data.keys()) + max_val_len = min(80, max(len(str(v)[:80]) for v in table_data.values())) + + # 打印表格 + print("\n" + "=" * (max_key_len + max_val_len + 7)) + print(f"| {'field'.ljust(max_key_len)} | {'value'.ljust(max_val_len)} |") + print("|" + "-" * (max_key_len + 2) + "|" + "-" * (max_val_len + 2) + "|") + + for key, value in table_data.items(): + val_str = str(value) + if len(val_str) > 80: + val_str = val_str[:77] + "..." + print(f"| {str(key).ljust(max_key_len)} | {val_str.ljust(max_val_len)} |") + + print("=" * (max_key_len + max_val_len + 7)) + + # 打印 RSA keys + for key, value in rsa_data.items(): + print(f"\n--- {key} ---") + print(value) + + + # --- 交互式菜单功能 --- def create_xdp_ultra_redeem_code(): """创建 xdp ultra redeem code""" @@ -238,6 +291,16 @@ def batch_update_product(): print(f"执行出错: {e}") +def query_xdp_device_info(): + """查询 XDP 设备信息""" + print("\n=== 查询 XDP 设备信息 ===") + keyword = input("请输入 PSN 或 Passcode (4位): ").strip() + if not keyword: + print("错误: 请输入有效的关键字") + return + filter_xdp_device_info(keyword) + + def show_menu(): """显示功能菜单""" print("\n" + "="*50) @@ -247,6 +310,7 @@ def show_menu(): print("1. 创建 XDP Ultra Redeem Code") print("2. 批次绑定商品") print("3. 批次更新商品") + print("4. 查询 XDP 设备信息") print("0. 退出") print("="*50) @@ -265,6 +329,8 @@ def main(): batch_bind_product() elif choice == '3': batch_update_product() + elif choice == '4': + query_xdp_device_info() elif choice == '0': print("\n退出脚本...") break