šŸ” Code Extractor

function verify_cloud_empty

Maturity: 46

Verifies that a reMarkable cloud storage account is completely empty by authenticating, retrieving the root document schema, and analyzing its contents for any remaining documents or folders.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/verify_cloud_empty.py
Lines:
11 - 124
Complexity:
complex

Purpose

This function is designed to validate that a reMarkable cloud storage has been successfully cleared of all content. It authenticates with the reMarkable cloud API, retrieves the root document schema, parses the content to identify any remaining documents or folders, and provides detailed analysis including item names, types, and metadata. It's particularly useful for testing cleanup operations or verifying account state before/after bulk operations.

Source Code

def verify_cloud_empty():
    """Verify that the cloud storage is empty"""
    print("šŸ” Verifying Cloud Content Removal")
    print("=" * 50)
    
    # Authenticate
    auth = RemarkableAuth()
    session = auth.get_authenticated_session()
    
    if not session:
        print("āŒ Authentication failed")
        return False
    
    try:
        # Get current root info
        print("šŸ“‹ Getting current root.docSchema...")
        root_response = session.get("https://eu.tectonic.remarkable.com/sync/v4/root")
        root_response.raise_for_status()
        root_data = root_response.json()
        
        print(f"āœ… Current root hash: {root_data['hash']}")
        print(f"āœ… Current generation: {root_data.get('generation')}")
        
        # Get root content
        root_content_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{root_data['hash']}")
        root_content_response.raise_for_status()
        root_content = root_content_response.text
        
        print(f"āœ… Root.docSchema size: {len(root_content)} bytes")
        print(f"šŸ“„ Root.docSchema content:")
        print(f"   {repr(root_content)}")
        
        # Parse content
        lines = root_content.strip().split('\n')
        print(f"\nšŸ“Š Analysis:")
        print(f"   Total lines: {len(lines)}")
        
        if len(lines) <= 1:
            print("āœ… Cloud appears to be EMPTY (only version header or less)")
            return True
        
        print(f"   Version: {lines[0] if lines else 'None'}")
        
        document_count = 0
        folder_count = 0
        
        for i, line in enumerate(lines[1:], 1):
            if line.strip():  # Non-empty line
                print(f"   Line {i}: {line}")
                
                # Try to parse the line
                parts = line.split(':')
                if len(parts) >= 5:
                    doc_hash = parts[0]
                    doc_uuid = parts[2]
                    doc_type = parts[3]
                    doc_size = parts[4]
                    
                    print(f"      UUID: {doc_uuid}")
                    print(f"      Type: {doc_type}")
                    print(f"      Size: {doc_size}")
                    
                    # Try to get name from metadata
                    try:
                        doc_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{doc_hash}")
                        if doc_response.status_code == 200:
                            doc_content = doc_response.text
                            doc_lines = doc_content.strip().split('\n')
                            
                            # Find metadata
                            for doc_line in doc_lines[1:]:
                                if ':' in doc_line and '.metadata' in doc_line:
                                    metadata_parts = doc_line.split(':')
                                    if len(metadata_parts) >= 5:
                                        metadata_hash = metadata_parts[0]
                                        metadata_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{metadata_hash}")
                                        if metadata_response.status_code == 200:
                                            metadata = json.loads(metadata_response.text)
                                            name = metadata.get('visibleName', 'Unknown')
                                            item_type = metadata.get('type', 'Unknown')
                                            deleted = metadata.get('deleted', False)
                                            parent = metadata.get('parent', '')
                                            
                                            print(f"      Name: {name}")
                                            print(f"      Item Type: {item_type}")
                                            print(f"      Deleted: {deleted}")
                                            print(f"      Parent: {parent or '(root)'}")
                                            
                                            if item_type == 'CollectionType':
                                                folder_count += 1
                                            elif item_type == 'DocumentType':
                                                document_count += 1
                                        break
                                    break
                    except Exception as e:
                        print(f"      āš ļø Could not fetch details: {e}")
                
                print()
        
        print(f"šŸ“Š SUMMARY:")
        print(f"   Documents found: {document_count}")
        print(f"   Folders found: {folder_count}")
        print(f"   Total items: {document_count + folder_count}")
        
        if document_count == 0 and folder_count == 0:
            print("āœ… Cloud is COMPLETELY EMPTY")
            return True
        else:
            print("āŒ Cloud still contains content")
            return False
            
    except Exception as e:
        print(f"āŒ Error checking cloud content: {e}")
        return False

Return Value

Returns a boolean value: True if the cloud storage is completely empty (contains only version header or no content), False if any documents or folders are found or if an error occurs during verification. The function also prints detailed diagnostic information to stdout during execution.

Dependencies

  • json
  • requests

Required Imports

import json
from auth import RemarkableAuth

Usage Example

# Verify if reMarkable cloud storage is empty
is_empty = verify_cloud_empty()

if is_empty:
    print("Cloud storage verified as empty")
else:
    print("Cloud storage still contains items")

# Example output:
# šŸ” Verifying Cloud Content Removal
# ==================================================
# šŸ“‹ Getting current root.docSchema...
# āœ… Current root hash: abc123...
# āœ… Current generation: 42
# āœ… Root.docSchema size: 80 bytes
# šŸ“„ Root.docSchema content:
#    '80\n'
# šŸ“Š Analysis:
#    Total lines: 1
# āœ… Cloud appears to be EMPTY (only version header or less)

Best Practices

  • This function performs multiple API calls and may take time to complete, especially if many items exist in the cloud
  • The function prints extensive diagnostic output to stdout; consider redirecting or capturing output if used in automated systems
  • Authentication must be properly configured before calling this function
  • The function makes synchronous HTTP requests; ensure network connectivity is stable
  • Error handling is present but errors are printed rather than raised; check the return value for success/failure
  • The function is hardcoded to use the EU region endpoint (eu.tectonic.remarkable.com); may need modification for other regions
  • Metadata parsing assumes specific reMarkable API response formats; API changes may break functionality
  • The function attempts to fetch detailed metadata for each item found, which can be slow for large numbers of items

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class RootCleaner 75.0% similar

    A class that completely clears the reMarkable cloud's root.docSchema file, removing all document references while maintaining the proper file structure and version.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/clear_root_docschema.py
  • function test_remarkable_authentication 73.7% similar

    Asynchronous test function that validates reMarkable Cloud authentication and verifies access to the root folder by listing its contents.

    From: /tf/active/vicechatdev/e-ink-llm/test_remarkable.py
  • function main_v23 73.0% similar

    Clears all document references from the reMarkable Cloud root.docSchema, making the cloud interface appear completely empty while preserving the actual documents.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/clear_root_docschema.py
  • function verify_document_status 72.3% similar

    Verifies the current status and metadata of a specific test document in the reMarkable cloud sync system by querying the sync API endpoints and analyzing the document's location and properties.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/verify_document_status.py
  • function test_remarkable_auth 69.9% similar

    Asynchronous function that tests authentication and API connectivity with the reMarkable Cloud service, verifying credentials and basic API access.

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