Spaces:
Sleeping

File size: 2,163 Bytes
39e01c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import shutil
import sys
import argparse

def setup_data(scilab_base, workspace_base, target_data):
    """
    scilab_base: path to scilab root folder (e.g. scilab-2026.0.1/scilab-2026.0.1/scilab)
    workspace_base: path to the AI xcos module root
    target_data: target directory (./data)
    """
    
    # Define mapping (Source -> Target)
    mappings = {
        # Reference blocks
        os.path.join(workspace_base, "Reference blocks"): os.path.join(target_data, "reference_blocks"),
        # Block info (JSON)
        os.path.join(workspace_base, "xcosgen", "server", "blocks"): os.path.join(target_data, "blocks"),
        # Macros
        os.path.join(scilab_base, "modules", "scicos_blocks", "macros"): os.path.join(target_data, "macros"),
        # Help
        os.path.join(scilab_base, "modules", "xcos", "help", "en_US", "palettes"): os.path.join(target_data, "help"),
    }

    # Added: xcosai_poll_loop.sci copy for launch script
    poll_loop_src = os.path.join(workspace_base, "XcosAICompiler", "macros", "xcosai_poll_loop.sci")
    poll_loop_dest = os.path.join(target_data, "xcosai_poll_loop.sci")

    for src, dest in mappings.items():
        if os.path.exists(src):
            print(f"Staging {src} -> {dest}")
            if os.path.exists(dest):
                shutil.rmtree(dest)
            shutil.copytree(src, dest)
        else:
            print(f"WARNING: Source not found: {src}")

    if os.path.exists(poll_loop_src):
        print(f"Staging poll loop -> {poll_loop_dest}")
        shutil.copy2(poll_loop_src, poll_loop_dest)
    else:
        print(f"WARNING: Poll loop source not found: {poll_loop_src}")

    print("Data staging complete.")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Stage data for Scilab Xcos MCP Server")
    parser.add_argument("--scilab", required=True, help="Path to Scilab source root")
    parser.add_argument("--workspace", required=True, help="Path to workspace root")
    parser.add_argument("--target", default="data", help="Target data directory")
    
    args = parser.parse_args()
    setup_data(args.scilab, args.workspace, args.target)