šŸ” Code Extractor

function print_sync_info

Maturity: 44

Reads and displays synchronization log information from a JSON file in a replica directory, including last sync time, root hash, and number of nodes synced.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
Lines:
239 - 257
Complexity:
simple

Purpose

This function provides a user-friendly display of synchronization status for a replica directory. It reads a 'sync_log.json' file and prints formatted information about the last synchronization operation, including timestamp, root hash (truncated for readability), and the count of synced nodes. It handles missing files and read errors gracefully with warning messages.

Source Code

def print_sync_info(replica_dir: Path):
    """Print sync log information"""
    sync_log_file = replica_dir / "sync_log.json"
    
    if not sync_log_file.exists():
        print(f"āš ļø No sync log found")
        return
    
    try:
        with open(sync_log_file, 'r', encoding='utf-8') as f:
            sync_log = json.load(f)
        
        print(f"\nšŸ“‹ SYNC INFORMATION:")
        print(f"   šŸ• Last sync: {sync_log.get('last_sync', 'unknown')}")
        print(f"   šŸ”‘ Root hash: {sync_log.get('root_hash', 'unknown')[:16]}...")
        print(f"   šŸ“Š Nodes synced: {sync_log.get('nodes_synced', 0)}")
        
    except Exception as e:
        print(f"āš ļø Error reading sync log: {e}")

Parameters

Name Type Default Kind
replica_dir Path - positional_or_keyword

Parameter Details

replica_dir: A Path object pointing to the replica directory that contains the 'sync_log.json' file. This directory should be the root of a replica structure where synchronization logs are stored. The function will look for a file named 'sync_log.json' directly within this directory.

Return Value

This function returns None. It performs side effects by printing formatted synchronization information to stdout using print() statements. Output includes emoji-prefixed status messages showing last sync time, root hash (first 16 characters), and number of nodes synced, or warning messages if the log file is missing or cannot be read.

Dependencies

  • json
  • pathlib

Required Imports

import json
from pathlib import Path

Usage Example

from pathlib import Path
import json

# Setup: Create a sample replica directory with sync log
replica_path = Path('./my_replica')
replica_path.mkdir(exist_ok=True)

# Create a sample sync_log.json file
sync_data = {
    'last_sync': '2024-01-15 14:30:00',
    'root_hash': 'abc123def456ghi789jkl012mno345pqr678',
    'nodes_synced': 42
}

with open(replica_path / 'sync_log.json', 'w', encoding='utf-8') as f:
    json.dump(sync_data, f)

# Use the function
print_sync_info(replica_path)

# Output:
# šŸ“‹ SYNC INFORMATION:
#    šŸ• Last sync: 2024-01-15 14:30:00
#    šŸ”‘ Root hash: abc123def456ghi7...
#    šŸ“Š Nodes synced: 42

Best Practices

  • Ensure the replica_dir Path object points to a valid directory before calling this function
  • The sync_log.json file should follow the expected schema with 'last_sync', 'root_hash', and 'nodes_synced' keys
  • This function is designed for console output and uses emoji characters - ensure your terminal supports UTF-8 encoding
  • The function gracefully handles missing files and JSON parsing errors, making it safe to call even if the sync log doesn't exist
  • The root hash is truncated to 16 characters for display purposes - if you need the full hash, consider modifying the function or reading the file directly
  • This is a display-only function with no return value - use it for logging/monitoring purposes, not for programmatic access to sync data

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function print_status 63.9% similar

    Prints a formatted status report for SharePoint to FileCloud synchronization operations, displaying sync statistics, timing information, and health indicators.

    From: /tf/active/vicechatdev/SPFCsync/monitor.py
  • function analyze_logs 56.1% similar

    Parses and analyzes log files to extract synchronization statistics, error counts, and performance metrics for a specified time period.

    From: /tf/active/vicechatdev/SPFCsync/monitor.py
  • function main_v28 53.8% similar

    Executes a diagnostic analysis for file synchronization issues, analyzes missing files, and saves the results to a JSON file.

    From: /tf/active/vicechatdev/SPFCsync/deep_diagnostics.py
  • function sync_directory 53.0% similar

    Recursively synchronizes a directory from a FileCloud remote server to a local filesystem, downloading new or modified files and creating directory structures as needed.

    From: /tf/active/vicechatdev/UQchat/download_uq_files.py
  • function print_database_analysis 52.5% similar

    Prints a comprehensive, formatted analysis of a reMarkable tablet replica database, including statistics, hierarchy information, file types, and a content tree visualization.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/analyze_replica.py
← Back to Browse