-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_drive_access.py
More file actions
157 lines (127 loc) · 5.88 KB
/
Copy pathdebug_drive_access.py
File metadata and controls
157 lines (127 loc) · 5.88 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
"""
Debug script to troubleshoot Google Drive access and file detection
"""
import os
from dotenv import load_dotenv
from utils import get_drive_service, list_files_in_folder
load_dotenv()
def debug_drive_access():
print("🔍 MCP Drive Access Diagnostics")
print("=" * 50)
# Check environment variables
print("1. Environment Variables:")
server_folder_id = os.getenv('MCP_SERVER_FOLDER_ID')
client_folder_id = os.getenv('MCP_CLIENT_FOLDER_ID')
key_path = os.getenv('GOOGLE_SERVICE_ACCOUNT_KEY_PATH')
print(f" 📁 Server Folder ID: {server_folder_id}")
print(f" 📁 Client Folder ID: {client_folder_id}")
print(f" 🔑 Service Account Key: {key_path}")
if not server_folder_id:
print(" ❌ MCP_SERVER_FOLDER_ID is missing!")
return
if not key_path or not os.path.exists(key_path):
print(f" ❌ Service account key file not found: {key_path}")
return
print(" ✅ Environment variables look good")
print()
# Test Google Drive connection
print("2. Google Drive Connection:")
try:
drive_service = get_drive_service()
print(" ✅ Successfully connected to Google Drive API")
except Exception as e:
print(f" ❌ Failed to connect to Google Drive: {e}")
return
print()
# Test folder access
print("3. Folder Access Test:")
try:
# Test server folder access
print(f" Testing server folder access ({server_folder_id})...")
folder_info = drive_service.files().get(fileId=server_folder_id).execute()
print(f" ✅ Server folder accessible: '{folder_info['name']}'")
# Test client folder access
print(f" Testing client folder access ({client_folder_id})...")
folder_info = drive_service.files().get(fileId=client_folder_id).execute()
print(f" ✅ Client folder accessible: '{folder_info['name']}'")
except Exception as e:
print(f" ❌ Folder access failed: {e}")
print(" 💡 Make sure the service account has access to both folders")
return
print()
# List files in server folder
print("4. Files in Server Folder:")
try:
files = list_files_in_folder(drive_service, server_folder_id)
if not files:
print(" 📭 No files found in server folder")
print(" 💡 Try uploading a CSV or Excel file to the folder")
else:
print(f" 📄 Found {len(files)} file(s):")
for i, file_info in enumerate(files, 1):
file_name = file_info['name']
file_id = file_info['id']
file_size = file_info.get('size', 'Unknown')
created_time = file_info.get('createdTime', 'Unknown')
# Check if supported format
is_supported = file_name.lower().endswith(('.csv', '.xlsx', '.xls'))
support_icon = "✅" if is_supported else "❌"
print(f" {i:2d}. {support_icon} {file_name}")
print(f" 📄 ID: {file_id}")
print(f" 📊 Size: {file_size} bytes")
print(f" 🕐 Created: {created_time}")
print()
except Exception as e:
print(f" ❌ Failed to list files: {e}")
return
print()
# Test file processing capability
print("5. Processing Test:")
if files:
# Find first supported file
supported_file = None
for file_info in files:
if file_info['name'].lower().endswith(('.csv', '.xlsx', '.xls')):
supported_file = file_info
break
if supported_file:
print(f" 🧪 Testing with file: {supported_file['name']}")
print(f" 📄 File ID: {supported_file['id']}")
# Test if we can download the file
try:
from utils import download_file_from_drive
file_content = download_file_from_drive(supported_file['id'], drive_service)
print(f" ✅ Successfully downloaded file ({len(file_content)} bytes)")
# Test if we can read the file
import pandas as pd
from io import BytesIO
filename = supported_file['name']
if filename.lower().endswith('.csv'):
df = pd.read_csv(BytesIO(file_content))
elif filename.lower().endswith(('.xlsx', '.xls')):
df = pd.read_excel(BytesIO(file_content))
print(f" ✅ Successfully parsed file: {len(df)} rows × {len(df.columns)} columns")
print(f" 📊 Columns: {list(df.columns)}")
except Exception as e:
print(f" ❌ Failed to process file: {e}")
else:
print(" ⚠️ No supported files found for testing")
else:
print(" ⚠️ No files available for testing")
print()
print("🎯 Diagnosis Complete!")
print("=" * 30)
if files:
supported_count = len([f for f in files if f['name'].lower().endswith(('.csv', '.xlsx', '.xls'))])
if supported_count > 0:
print(f"✅ Found {supported_count} supported file(s) ready for processing")
print("💡 The auto-processor should be able to detect and process these files")
else:
print("⚠️ Files found but none are in supported formats (CSV, Excel)")
print("💡 Upload CSV or Excel files to test the auto-processor")
else:
print("📭 No files found in the monitored folder")
print("💡 Upload a CSV or Excel file to your Google Drive folder and try again")
if __name__ == "__main__":
debug_drive_access()