function check_site_vs_channels
Diagnostic function that analyzes and compares SharePoint site structure, specifically examining the main site document library versus Teams channel document libraries to identify the correct library for synchronization.
/tf/active/vicechatdev/SPFCsync/check_site_library.py
10 - 167
moderate
Purpose
This function performs a comprehensive analysis of a SharePoint site's drive structure to help identify and differentiate between the main site document library and Teams channel libraries. It's designed as a diagnostic tool to troubleshoot synchronization issues by listing all drives, examining their contents, and highlighting expected folder structures. The function prints detailed information about each drive including IDs, types, URLs, and contents, with special markers for expected folders like '01 UCJ Research', '02 Toxicology', '03 CMC', and '04 Quality'.
Source Code
def check_site_vs_channels():
"""Check main site library vs channels document libraries"""
config = Config()
try:
client = SharePointGraphClient(
site_url=config.SHAREPOINT_SITE_URL,
client_id=config.AZURE_CLIENT_ID,
client_secret=config.AZURE_CLIENT_SECRET
)
print("â
SharePoint Graph client initialized")
print(f"Site: {config.SHAREPOINT_SITE_URL}")
print()
except Exception as e:
print(f"â Failed to initialize client: {e}")
return
headers = {
'Authorization': f'Bearer {client.access_token}',
'Accept': 'application/json'
}
print("đ ANALYZING SITE STRUCTURE")
print("=" * 50)
# 1. Check main site drives
print("1. MAIN SITE DRIVES:")
print("-" * 30)
try:
drives_url = f"https://graph.microsoft.com/v1.0/sites/{client.site_id}/drives"
response = requests.get(drives_url, headers=headers)
if response.status_code == 200:
drives_data = response.json()
for drive in drives_data.get('value', []):
drive_name = drive.get('name', 'Unknown')
drive_id = drive.get('id', 'Unknown')
web_url = drive.get('webUrl', 'No URL')
drive_type = drive.get('driveType', 'unknown')
print(f"đ {drive_name}")
print(f" ID: {drive_id}")
print(f" Type: {drive_type}")
print(f" URL: {web_url}")
# Check if this looks like the main site library
if 'Shared%20Documents' in web_url and 'channel' not in web_url.lower():
print(" đ¯ This appears to be the MAIN SITE LIBRARY")
# Get contents
root_url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/root/children"
try:
root_response = requests.get(root_url, headers=headers)
if root_response.status_code == 200:
root_data = root_response.json()
if 'value' in root_data:
folders = [item for item in root_data['value'] if 'folder' in item]
files = [item for item in root_data['value'] if 'file' in item]
print(f" đ {len(folders)} folders, đ {len(files)} files")
# List folder names - look for the expected ones
if folders:
print(" Folders found:")
expected_folders = ['01 UCJ Research', '02 Toxicology', '03 CMC', '04 Quality']
for folder in folders:
folder_name = folder.get('name', 'Unknown')
is_expected = any(exp in folder_name for exp in expected_folders)
marker = "đ¯" if is_expected else "đ"
print(f" {marker} {folder_name}")
if is_expected:
print(f" â
This matches expected folder pattern!")
else:
print(f" â Failed to get contents: {root_response.status_code}")
except Exception as e:
print(f" â Error getting contents: {e}")
elif 'channel' in web_url.lower() or '00Strategy' in web_url:
print(" đĸ This appears to be a TEAMS CHANNEL library")
print()
except Exception as e:
print(f"â Error checking drives: {e}")
# 2. Try to find the default documents library specifically
print("\n2. TRYING TO ACCESS DEFAULT DOCUMENTS LIBRARY:")
print("-" * 50)
try:
# Try the standard site documents library endpoint
default_drive_url = f"https://graph.microsoft.com/v1.0/sites/{client.site_id}/drive"
response = requests.get(default_drive_url, headers=headers)
if response.status_code == 200:
default_drive = response.json()
drive_name = default_drive.get('name', 'Unknown')
drive_id = default_drive.get('id', 'Unknown')
web_url = default_drive.get('webUrl', 'No URL')
print(f"đ Default Drive: {drive_name}")
print(f" ID: {drive_id}")
print(f" URL: {web_url}")
# This should be the main site library
if drive_id != client.drive_id:
print(" đ¯ This is DIFFERENT from our current drive!")
print(" đ¯ This is likely the MAIN SITE LIBRARY we want to sync!")
# Get contents
root_url = f"https://graph.microsoft.com/v1.0/drives/{drive_id}/root/children"
try:
root_response = requests.get(root_url, headers=headers)
if root_response.status_code == 200:
root_data = root_response.json()
if 'value' in root_data:
folders = [item for item in root_data['value'] if 'folder' in item]
files = [item for item in root_data['value'] if 'file' in item]
print(f" đ {len(folders)} folders, đ {len(files)} files")
# List folder names - look for the expected ones
if folders:
print(" Folders found:")
expected_folders = ['01 UCJ Research', '02 Toxicology', '03 CMC', '04 Quality']
for folder in folders:
folder_name = folder.get('name', 'Unknown')
is_expected = any(exp in folder_name for exp in expected_folders)
marker = "đ¯" if is_expected else "đ"
print(f" {marker} {folder_name}")
if is_expected:
print(f" â
FOUND EXPECTED FOLDER!")
# Show some files too
if files:
print(" Some files:")
for file in files[:5]:
file_name = file.get('name', 'Unknown')
print(f" đ {file_name}")
else:
print(f" â Failed to get contents: {root_response.status_code}")
except Exception as e:
print(f" â Error getting contents: {e}")
else:
print(" âšī¸ This is the same drive we're already using")
else:
print(f"â Failed to get default drive: {response.status_code}")
except Exception as e:
print(f"â Error checking default drive: {e}")
Return Value
This function does not return any value (implicitly returns None). All output is printed to stdout, including drive information, folder structures, file listings, and diagnostic messages with emoji markers for visual clarity.
Dependencies
requestssharepoint_graph_clientconfig
Required Imports
import requests
from sharepoint_graph_client import SharePointGraphClient
from config import Config
Usage Example
# Ensure config.py has required settings:
# SHAREPOINT_SITE_URL = 'https://yourtenant.sharepoint.com/sites/yoursite'
# AZURE_CLIENT_ID = 'your-client-id'
# AZURE_CLIENT_SECRET = 'your-client-secret'
from your_module import check_site_vs_channels
# Run the diagnostic check
check_site_vs_channels()
# Output will be printed to console showing:
# - All drives in the SharePoint site
# - Main site library identification
# - Teams channel libraries
# - Folder and file listings
# - Comparison with expected folder structure
Best Practices
- This is a diagnostic/debugging function meant for development and troubleshooting, not production use
- Ensure proper Azure AD application permissions are configured before running
- The function expects specific folder naming conventions ('01 UCJ Research', '02 Toxicology', etc.) - modify the expected_folders list if your structure differs
- Review console output carefully to identify the correct drive_id for your main site library
- The function makes multiple API calls to Microsoft Graph - be mindful of rate limits
- Error handling is built-in but failures are printed rather than raised, so monitor console output
- The function uses emoji markers (â , â, đ¯, đ, etc.) for visual clarity - ensure your console supports Unicode
- Access tokens are obtained through SharePointGraphClient - ensure the client is properly authenticated
- The function distinguishes between main site libraries and Teams channel libraries by examining URLs for 'channel' keywords
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function access_main_site_library 71.3% similar
-
function check_all_libraries 69.0% similar
-
function explore_site_structure 68.7% similar
-
function quick_test 67.9% similar
-
function main_v24 66.8% similar