system.cpython-310.pyc•6.6 kB
o
&EhB! � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl Z d dl
mZ d dlm
Z
e �d�ZejdkrLejjdd� ejjdd� dd � Zd
e
fdd�ZdS )
� N)�Path)�FastMCPZsystem_tools�win32�utf-8��encodingc C s t �� d S )u! 获取当前用户的桌面路径ZDesktop)r �home� r r �E:\xiaozhi-mcp\tools\system.py�get_desktop_path s r �mcpc C s� | � � dtfdd��}| � � ddtdtdtfdd��}| � � d tdtfd
d��}| � � d tdtfdd
��}| � � dtfdd��}| � � dtfdd��}| � � dtdtfdd��}d S )N�returnc
S s� zUt jdd�} t �� }t �� }|jd }|jd }|j}t �d�}|jd }|jd }|j} t �� }
d| |d�t |d�t |d�|d�t |d�t |d�| d�d |
id
�d�W S t
yx } zt�dt
|�� �� d
t
|�d�W Y d}~S d}~ww )u�
获取服务器状态监控信息。
返回:
- 包含CPU、内存、磁盘等使用情况的字典
� )�intervali @�/T)�
usage_percentZ
core_count� )Ztotal_gbZused_gbr � boot_time)Zcpu�memory�disk�system)�success�resultu 获取服务器状态失败: F�r �errorN)�psutil�cpu_percent� cpu_countZvirtual_memory�total�used�percent�
disk_usager �round� Exception�loggerr �str)r r r Zmemory_totalZmemory_usedZmemory_percentr Z
disk_totalZ disk_usedZdisk_percentr �er r r
�get_server_status sF
���������z0register_system_tools.<locals>.get_server_status� �text�filenamec
S s2 zu|r?t � }|| }t|ddd��
}|�| � W d � n1 s!w Y t�dt|�g� t�d|� �� dt|�d�W S tj ddd d
dd��}|�| � |j
}W d � n1 s\w Y t�d|g� t�d
|� �� d|d�W S ty� } zt�dt|�� �� d
t|�d�W Y d}~S d}~ww )aM
Open Notepad with text and optionally save to a specific file.
Args:
text: The text to display in Notepad
filename: If provided, save to this file on desktop (e.g., "poem.txt")
Returns:
dict: {"success": bool, "filepath": str (if saved), "error": str (if failed)}
�wr r N�notepad.exezOpened Notepad with file: T)r �filepathz.txtFZnotepad_)�moder �suffix�delete�prefixz$Opened Notepad with temporary file: z"Failed to open Notepad with text: r )
r �open�write�
subprocess�Popenr% r$ �info�tempfile�NamedTemporaryFile�namer# r )r) r* Zdesktopr- �fZ temp_pathr&