function main_v29
Main entry point function that orchestrates a file synchronization process from a FileCloud source to a local directory, with progress reporting and error handling.
/tf/active/vicechatdev/UQchat/download_uq_files.py
170 - 195
moderate
Purpose
This function serves as the main execution entry point for the UQchat FileCloud Sync application. It handles the complete workflow of: (1) displaying sync configuration information, (2) creating necessary local directories, (3) authenticating with FileCloud service, (4) initiating the directory synchronization process from a remote FileCloud path to a local filesystem location, and (5) reporting completion status. The function is designed to sync files from a specific FileCloud shared directory structure to a local base directory.
Source Code
def main():
"""Main execution"""
print("=" * 80)
print("UQchat FileCloud Sync")
print("=" * 80)
print(f"Source: {SOURCE_PATH}")
print(f"Destination: {LOCAL_BASE_DIR}")
print("=" * 80)
# Create base directory if it doesn't exist
LOCAL_BASE_DIR.mkdir(parents=True, exist_ok=True)
# Login to FileCloud
session = login_filecloud()
if not session:
print("Failed to login. Exiting.")
return
# Start syncing from the source path
# Map FileCloud path to local directory structure
# Remove the prefix '/SHARED/vicebio_shares/03_Non_Clinical/' from paths
sync_directory(session, SOURCE_PATH, LOCAL_BASE_DIR / '01_Research_UQ')
print("\n" + "=" * 80)
print("✓ Sync complete!")
print("=" * 80)
Return Value
Returns None implicitly. The function performs side effects (file synchronization, console output) but does not return any value. Early return occurs if FileCloud login fails.
Dependencies
requestsxmltodictpathlibdatetimezoneinfo
Required Imports
import os
import requests
import xmltodict
from pathlib import Path
from datetime import datetime
from zoneinfo import ZoneInfo
Usage Example
# Define required global variables and functions first
from pathlib import Path
import requests
import xmltodict
SOURCE_PATH = '/SHARED/vicebio_shares/03_Non_Clinical/'
LOCAL_BASE_DIR = Path('./local_sync')
def login_filecloud():
# Implementation to authenticate with FileCloud
# Returns session object or None on failure
session = requests.Session()
# ... authentication logic ...
return session
def sync_directory(session, source, destination):
# Implementation to sync files from FileCloud to local
pass
# Execute the main function
if __name__ == '__main__':
main()
Best Practices
- Ensure SOURCE_PATH and LOCAL_BASE_DIR are properly defined as module-level constants before calling this function
- The login_filecloud() function should handle credential management securely (avoid hardcoding credentials)
- Ensure sufficient disk space is available at LOCAL_BASE_DIR before running synchronization
- The function creates directories with parents=True and exist_ok=True, which is safe for repeated executions
- Consider wrapping the main() call in a try-except block to handle unexpected errors gracefully
- The function performs early exit if login fails, which is good practice for dependency validation
- Monitor console output for sync progress and completion status
- The hardcoded path mapping ('01_Research_UQ') suggests this is specific to a particular organizational structure
Tags
Similar Components
AI-powered semantic similarity - components with related functionality: