优化项目结构, 增加表格和文档插件

This commit is contained in:
jianxin committed 2025-04-01 16:51:54 +08:00
1 parent 057d267e9f
commit 7805931355
3 files changed
+20 -38

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ def invoke_wps_func(func, args):
xhr.send(JSON.stringify({{id: '{req_uui}', response: res}}));void(0" xhr.send(JSON.stringify({{id: '{req_uui}', response: res}}));void(0"
data = { data = {
"name": "xbotet", "name": "xbot-et",
"function": "var res = InvokeFromXbot", "function": "var res = InvokeFromXbot",
"info": info, "info": info,
"showToFront": True, "showToFront": True,
Binary file not shown.
+19 -37
View File
@@ -34,7 +34,7 @@ def create_authwebsite_xml(directory, node_name="xbotwps"):
try: try:
# Parse the XML file # Parse the XML file
dom = minidom.parse() dom = minidom.parse(file_path)
# Get the websites element # Get the websites element
websites_elements = dom.getElementsByTagName("websites") websites_elements = dom.getElementsByTagName("websites")
@@ -69,26 +69,14 @@ def create_authwebsite_xml(directory, node_name="xbotwps"):
print(f"Updated authwebsite.xml at {file_path}") print(f"Updated authwebsite.xml at {file_path}")
except Exception as e: except Exception as e:
print(f"Error working with authwebsite.xml: {e}") raise Exception(f"Error working with authwebsite.xml: {e}")
# Create a completely new file with the correct structure and node
content = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
"<websites>\n"
f' <website origin="null" status="enable" name="{node_name}"/>\n'
"</websites>\n"
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created new authwebsite.xml at {file_path}")
def create_publish_xml( def create_publish_xml(
directory, node_name="xbotwps", addon_path=None, verson="1.0.0", addon_type="wps" directory, node_name="xbotwps", verson="1.0.0", addon_type="wps"
): ):
"""Create the publish.xml file if it doesn't exist or update it if it exists.""" """Create the publish.xml file if it doesn't exist or update it if it exists."""
file_path = os.path.join(directory, "publish.xml") file_path = os.path.join(directory, "publish.xml")
if addon_path is None:
raise ValueError("addon_path must be provided")
# Create the basic XML structure if the file doesn't exist # Create the basic XML structure if the file doesn't exist
if not os.path.exists(file_path): if not os.path.exists(file_path):
@@ -124,7 +112,7 @@ def create_publish_xml(
# Create and append the new jsplugin node # Create and append the new jsplugin node
new_jsplugin = dom.createElement("jsplugin") new_jsplugin = dom.createElement("jsplugin")
new_jsplugin.setAttribute("enable", "enable_dev") new_jsplugin.setAttribute("enable", "enable_dev")
new_jsplugin.setAttribute("url", addon_path) new_jsplugin.setAttribute("url", "null")
new_jsplugin.setAttribute("install", "null") new_jsplugin.setAttribute("install", "null")
new_jsplugin.setAttribute("version", verson) new_jsplugin.setAttribute("version", verson)
new_jsplugin.setAttribute("type", addon_type) new_jsplugin.setAttribute("type", addon_type)
@@ -139,23 +127,13 @@ def create_publish_xml(
print(f"Updated publish.xml at {file_path}") print(f"Updated publish.xml at {file_path}")
except Exception as e: except Exception as e:
print(f"Error working with publish.xml: {e}") raise Exception(f"Error working with publish.xml: {e}")
# Create a completely new file with the correct structure and node
content = (
'<?xml version="1.0" encoding="UTF-8"?>\n'
"<jsplugins>\n"
f' <jsplugin enable="enable_dev" url="{addon_path}" install="null" version="1.0.0" type="wps" customDomain="" name="{node_name}"/>\n'
"</jsplugins>\n"
)
with open(file_path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Created new publish.xml at {file_path}")
def extract_addon(addon_path, install_dir): def extract_addon(addon_path, install_dir, addon_name, addon_version):
"""Extract the addon archive to the installation directory.""" """Extract the addon archive to the installation directory."""
addon_name = "xbotwps" addon_name_with_version = f"{addon_name}_{addon_version}"
extract_dir = os.path.join(install_dir, addon_name) extract_dir = os.path.join(install_dir, addon_name_with_version)
# Clean the existing directory if it exists # Clean the existing directory if it exists
if os.path.exists(extract_dir): if os.path.exists(extract_dir):
@@ -171,7 +149,7 @@ def extract_addon(addon_path, install_dir):
try: try:
print(f"Extracting ZIP archive to {extract_dir}") print(f"Extracting ZIP archive to {extract_dir}")
with zipfile.ZipFile(addon_path, "r") as zip_ref: with zipfile.ZipFile(addon_path, "r") as zip_ref:
zip_ref.extractall(install_dir) zip_ref.extractall(extract_dir)
print("Extraction completed successfully") print("Extraction completed successfully")
return True return True
@@ -185,9 +163,11 @@ def main():
# 2. 从插件目录下读取package.json文件,获取插件名称, 版本号, 插件类型 # 2. 从插件目录下读取package.json文件,获取插件名称, 版本号, 插件类型
# 3. 创建authwebsite.xml文件,添加插件名称节点 # 3. 创建authwebsite.xml文件,添加插件名称节点
# 4. 创建publish.xml文件,添加插件名称节点 # 4. 创建publish.xml文件,添加插件名称节点
addon_path = r"C:\\Users\\32075\\OneDrive\\文档\\Code\\RPA_Script\\wps-js-extension\\XbotWps\\wps-addon-build\\xbotwps.zip" addon_name = "XbotWps"
node_name = "xbotwps" addon_type = "et"
addon_version = "1.0.0"
addon_path = r"C:\Users\32075\OneDrive\文档\Code\RPA_Script\wps-js-extension\XbotWps\scripts\XbotWps_1.0.0.zip"
install_dir = get_install_directory() install_dir = get_install_directory()
print(f"Installation directory: {install_dir}") print(f"Installation directory: {install_dir}")
@@ -197,11 +177,13 @@ def main():
print(f"Created installation directory: {install_dir}") print(f"Created installation directory: {install_dir}")
# Create the required XML files # Create the required XML files
create_authwebsite_xml(install_dir, node_name) create_authwebsite_xml(install_dir, addon_name)
create_publish_xml(install_dir, node_name, addon_path) create_publish_xml(
install_dir, addon_name, verson=addon_version, addon_type=addon_type
)
# Extract the addon to the installation directory # Extract the addon to the installation directory
if extract_addon(addon_path, install_dir): if extract_addon(addon_path, install_dir, addon_name, addon_version):
print("Addon extracted successfully.") print("Addon extracted successfully.")
else: else:
print("Failed to extract addon.") print("Failed to extract addon.")