File size: 2,081 Bytes
ac46d48
bd98803
 
 
 
 
 
 
ac46d48
bd98803
 
 
ac46d48
bd98803
 
 
ac46d48
bd98803
ac46d48
bd98803
 
 
ac46d48
bd98803
ac46d48
 
 
 
 
 
 
 
 
 
 
 
 
5a002e9
bd98803
ac46d48
 
 
 
 
037c74d
 
ac46d48
 
 
 
037c74d
5a002e9
037c74d
 
ac46d48
 
 
 
 
 
bd98803
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65

#!/usr/bin/env python3
"""
Export complete system state for backup and analysis.
"""

import sys
import json
import logging
from datetime import datetime
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from core.nuclear_intelligence import NuclearIntelligenceCore
from blockchain.virtual_ledger import VirtualLedger

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

def main():
    """Export system state."""
    logging.info("Exporting system state...")
    
    try:
        # Initialize components
        ni_core = NuclearIntelligenceCore()
        ledger = VirtualLedger()
        
        # Prepare export
        export_data = {
            "timestamp": datetime.now().isoformat(),
            "blockchain_state": {
                "chain": [block.to_dict() for block in ledger.chain],
                "pending_transactions": [tx.to_dict() for tx in ledger.pending_transactions],
                "nes_supply": ledger.nes_supply
            },
            "knowledge_graph_state": ni_core.kg.graph
        }
        
        # Save to file
        export_dir = Path(__file__).parent.parent / "exports"
        export_dir.mkdir(exist_ok=True)
        
        ts = datetime.now().strftime("%Y%m%d_%H%M%S")
        export_file = export_dir / f"system_state_{ts}.json"
        with open(export_file, "w", encoding="utf-8") as f:
            json.dump(export_data, f, indent=2, ensure_ascii=False)
        
        logging.info(f"System state exported to {export_file}")
        blocks_count = len(export_data["blockchain_state"]["chain"])
        kg_entities_count = len(export_data["knowledge_graph_state"].get("entities", {}))
        logging.info(f"Blockchain blocks: {blocks_count}")
        logging.info(f"Knowledge graph entities: {kg_entities_count}")
        
        return 0
        
    except Exception as e:
        logging.error(f"Critical error during state export: {e}", exc_info=True)
        return 1


if __name__ == "__main__":
    sys.exit(main())