style: auto-fix ruff lint and format
This commit is contained in:
@@ -17,8 +17,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def _manage_comment_dispatch(
|
async def _manage_comment_dispatch(
|
||||||
service, app_name: str, file_id: str, action: str,
|
service,
|
||||||
comment_content: Optional[str] = None, comment_id: Optional[str] = None,
|
app_name: str,
|
||||||
|
file_id: str,
|
||||||
|
action: str,
|
||||||
|
comment_content: Optional[str] = None,
|
||||||
|
comment_id: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Route comment management actions to the appropriate implementation."""
|
"""Route comment management actions to the appropriate implementation."""
|
||||||
action_lower = action.lower().strip()
|
action_lower = action.lower().strip()
|
||||||
@@ -28,14 +32,20 @@ async def _manage_comment_dispatch(
|
|||||||
return await _create_comment_impl(service, app_name, file_id, comment_content)
|
return await _create_comment_impl(service, app_name, file_id, comment_content)
|
||||||
elif action_lower == "reply":
|
elif action_lower == "reply":
|
||||||
if not comment_id or not comment_content:
|
if not comment_id or not comment_content:
|
||||||
raise ValueError("comment_id and comment_content are required for reply action")
|
raise ValueError(
|
||||||
return await _reply_to_comment_impl(service, app_name, file_id, comment_id, comment_content)
|
"comment_id and comment_content are required for reply action"
|
||||||
|
)
|
||||||
|
return await _reply_to_comment_impl(
|
||||||
|
service, app_name, file_id, comment_id, comment_content
|
||||||
|
)
|
||||||
elif action_lower == "resolve":
|
elif action_lower == "resolve":
|
||||||
if not comment_id:
|
if not comment_id:
|
||||||
raise ValueError("comment_id is required for resolve action")
|
raise ValueError("comment_id is required for resolve action")
|
||||||
return await _resolve_comment_impl(service, app_name, file_id, comment_id)
|
return await _resolve_comment_impl(service, app_name, file_id, comment_id)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid action '{action_lower}'. Must be 'create', 'reply', or 'resolve'.")
|
raise ValueError(
|
||||||
|
f"Invalid action '{action_lower}'. Must be 'create', 'reply', or 'resolve'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_comment_tools(app_name: str, file_id_param: str):
|
def create_comment_tools(app_name: str, file_id_param: str):
|
||||||
@@ -67,8 +77,12 @@ def create_comment_tools(app_name: str, file_id_param: str):
|
|||||||
@require_google_service("drive", "drive_file")
|
@require_google_service("drive", "drive_file")
|
||||||
@handle_http_errors(manage_func_name, service_type="drive")
|
@handle_http_errors(manage_func_name, service_type="drive")
|
||||||
async def manage_comment(
|
async def manage_comment(
|
||||||
service, user_google_email: str, document_id: str, action: str,
|
service,
|
||||||
comment_content: Optional[str] = None, comment_id: Optional[str] = None,
|
user_google_email: str,
|
||||||
|
document_id: str,
|
||||||
|
action: str,
|
||||||
|
comment_content: Optional[str] = None,
|
||||||
|
comment_id: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Manage comments on a Google Document.
|
"""Manage comments on a Google Document.
|
||||||
|
|
||||||
@@ -94,8 +108,12 @@ def create_comment_tools(app_name: str, file_id_param: str):
|
|||||||
@require_google_service("drive", "drive_file")
|
@require_google_service("drive", "drive_file")
|
||||||
@handle_http_errors(manage_func_name, service_type="drive")
|
@handle_http_errors(manage_func_name, service_type="drive")
|
||||||
async def manage_comment(
|
async def manage_comment(
|
||||||
service, user_google_email: str, spreadsheet_id: str, action: str,
|
service,
|
||||||
comment_content: Optional[str] = None, comment_id: Optional[str] = None,
|
user_google_email: str,
|
||||||
|
spreadsheet_id: str,
|
||||||
|
action: str,
|
||||||
|
comment_content: Optional[str] = None,
|
||||||
|
comment_id: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Manage comments on a Google Spreadsheet.
|
"""Manage comments on a Google Spreadsheet.
|
||||||
|
|
||||||
@@ -121,8 +139,12 @@ def create_comment_tools(app_name: str, file_id_param: str):
|
|||||||
@require_google_service("drive", "drive_file")
|
@require_google_service("drive", "drive_file")
|
||||||
@handle_http_errors(manage_func_name, service_type="drive")
|
@handle_http_errors(manage_func_name, service_type="drive")
|
||||||
async def manage_comment(
|
async def manage_comment(
|
||||||
service, user_google_email: str, presentation_id: str, action: str,
|
service,
|
||||||
comment_content: Optional[str] = None, comment_id: Optional[str] = None,
|
user_google_email: str,
|
||||||
|
presentation_id: str,
|
||||||
|
action: str,
|
||||||
|
comment_content: Optional[str] = None,
|
||||||
|
comment_id: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Manage comments on a Google Presentation.
|
"""Manage comments on a Google Presentation.
|
||||||
|
|
||||||
|
|||||||
@@ -510,9 +510,9 @@ async def manage_deployment(
|
|||||||
service, user_google_email, script_id, deployment_id
|
service, user_google_email, script_id, deployment_id
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid action '{action}'. Must be 'create', 'update', or 'delete'.")
|
raise ValueError(
|
||||||
|
f"Invalid action '{action}'. Must be 'create', 'update', or 'delete'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _list_deployments_impl(
|
async def _list_deployments_impl(
|
||||||
@@ -602,8 +602,6 @@ async def _update_deployment_impl(
|
|||||||
return "\n".join(output)
|
return "\n".join(output)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def _delete_deployment_impl(
|
async def _delete_deployment_impl(
|
||||||
service: Any,
|
service: Any,
|
||||||
user_google_email: str,
|
user_google_email: str,
|
||||||
@@ -628,8 +626,6 @@ async def _delete_deployment_impl(
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def _list_script_processes_impl(
|
async def _list_script_processes_impl(
|
||||||
service: Any,
|
service: Any,
|
||||||
user_google_email: str,
|
user_google_email: str,
|
||||||
|
|||||||
@@ -534,7 +534,6 @@ async def get_events(
|
|||||||
return text_output
|
return text_output
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Internal implementation functions for event create/modify/delete.
|
# Internal implementation functions for event create/modify/delete.
|
||||||
# These are called by both the consolidated ``manage_event`` tool and the
|
# These are called by both the consolidated ``manage_event`` tool and the
|
||||||
@@ -789,7 +788,6 @@ def _normalize_attendees(
|
|||||||
return normalized if normalized else None
|
return normalized if normalized else None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def _modify_event_impl(
|
async def _modify_event_impl(
|
||||||
service,
|
service,
|
||||||
user_google_email: str,
|
user_google_email: str,
|
||||||
@@ -1139,7 +1137,9 @@ async def manage_event(
|
|||||||
action_lower = action.lower().strip()
|
action_lower = action.lower().strip()
|
||||||
if action_lower == "create":
|
if action_lower == "create":
|
||||||
if not summary or not start_time or not end_time:
|
if not summary or not start_time or not end_time:
|
||||||
raise ValueError("summary, start_time, and end_time are required for create action")
|
raise ValueError(
|
||||||
|
"summary, start_time, and end_time are required for create action"
|
||||||
|
)
|
||||||
return await _create_event_impl(
|
return await _create_event_impl(
|
||||||
service=service,
|
service=service,
|
||||||
user_google_email=user_google_email,
|
user_google_email=user_google_email,
|
||||||
@@ -1154,7 +1154,9 @@ async def manage_event(
|
|||||||
attachments=attachments,
|
attachments=attachments,
|
||||||
add_google_meet=add_google_meet or False,
|
add_google_meet=add_google_meet or False,
|
||||||
reminders=reminders,
|
reminders=reminders,
|
||||||
use_default_reminders=use_default_reminders if use_default_reminders is not None else True,
|
use_default_reminders=use_default_reminders
|
||||||
|
if use_default_reminders is not None
|
||||||
|
else True,
|
||||||
transparency=transparency,
|
transparency=transparency,
|
||||||
visibility=visibility,
|
visibility=visibility,
|
||||||
guests_can_modify=guests_can_modify,
|
guests_can_modify=guests_can_modify,
|
||||||
@@ -1196,7 +1198,9 @@ async def manage_event(
|
|||||||
calendar_id=calendar_id,
|
calendar_id=calendar_id,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid action '{action_lower}'. Must be 'create', 'update', or 'delete'.")
|
raise ValueError(
|
||||||
|
f"Invalid action '{action_lower}'. Must be 'create', 'update', or 'delete'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -1204,12 +1208,6 @@ async def manage_event(
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@handle_http_errors("query_freebusy", is_read_only=True, service_type="calendar")
|
@handle_http_errors("query_freebusy", is_read_only=True, service_type="calendar")
|
||||||
@require_google_service("calendar", "calendar_read")
|
@require_google_service("calendar", "calendar_read")
|
||||||
|
|||||||
@@ -775,9 +775,7 @@ async def manage_contacts_batch(
|
|||||||
try:
|
try:
|
||||||
if action == "create":
|
if action == "create":
|
||||||
if not contacts:
|
if not contacts:
|
||||||
raise Exception(
|
raise Exception("contacts parameter is required for 'create' action.")
|
||||||
"contacts parameter is required for 'create' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(contacts) > 200:
|
if len(contacts) > 200:
|
||||||
raise Exception("Maximum 200 contacts can be created in a batch.")
|
raise Exception("Maximum 200 contacts can be created in a batch.")
|
||||||
@@ -823,9 +821,7 @@ async def manage_contacts_batch(
|
|||||||
|
|
||||||
if action == "update":
|
if action == "update":
|
||||||
if not updates:
|
if not updates:
|
||||||
raise Exception(
|
raise Exception("updates parameter is required for 'update' action.")
|
||||||
"updates parameter is required for 'update' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(updates) > 200:
|
if len(updates) > 200:
|
||||||
raise Exception("Maximum 200 contacts can be updated in a batch.")
|
raise Exception("Maximum 200 contacts can be updated in a batch.")
|
||||||
@@ -922,9 +918,7 @@ async def manage_contacts_batch(
|
|||||||
|
|
||||||
# action == "delete"
|
# action == "delete"
|
||||||
if not contact_ids:
|
if not contact_ids:
|
||||||
raise Exception(
|
raise Exception("contact_ids parameter is required for 'delete' action.")
|
||||||
"contact_ids parameter is required for 'delete' action."
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(contact_ids) > 500:
|
if len(contact_ids) > 500:
|
||||||
raise Exception("Maximum 500 contacts can be deleted in a batch.")
|
raise Exception("Maximum 500 contacts can be deleted in a batch.")
|
||||||
@@ -1063,7 +1057,9 @@ async def manage_contact_group(
|
|||||||
.execute
|
.execute
|
||||||
)
|
)
|
||||||
|
|
||||||
response = f"Contact group {group_id} has been deleted for {user_google_email}."
|
response = (
|
||||||
|
f"Contact group {group_id} has been deleted for {user_google_email}."
|
||||||
|
)
|
||||||
if delete_contacts:
|
if delete_contacts:
|
||||||
response += " Contacts in the group were also deleted."
|
response += " Contacts in the group were also deleted."
|
||||||
else:
|
else:
|
||||||
@@ -1140,5 +1136,3 @@ async def manage_contact_group(
|
|||||||
message = f"Unexpected error: {e}."
|
message = f"Unexpected error: {e}."
|
||||||
logger.exception(message)
|
logger.exception(message)
|
||||||
raise Exception(message)
|
raise Exception(message)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1854,9 +1854,7 @@ async def manage_drive_access(
|
|||||||
validate_share_type(share_type)
|
validate_share_type(share_type)
|
||||||
|
|
||||||
if share_type in ("user", "group") and not share_with:
|
if share_type in ("user", "group") and not share_with:
|
||||||
raise ValueError(
|
raise ValueError(f"share_with is required for share_type '{share_type}'")
|
||||||
f"share_with is required for share_type '{share_type}'"
|
|
||||||
)
|
|
||||||
if share_type == "domain" and not share_with:
|
if share_type == "domain" and not share_with:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"share_with (domain name) is required for share_type 'domain'"
|
"share_with (domain name) is required for share_type 'domain'"
|
||||||
@@ -1898,14 +1896,16 @@ async def manage_drive_access(
|
|||||||
service.permissions().create(**create_params).execute
|
service.permissions().create(**create_params).execute
|
||||||
)
|
)
|
||||||
|
|
||||||
return "\n".join([
|
return "\n".join(
|
||||||
|
[
|
||||||
f"Successfully shared '{file_metadata.get('name', 'Unknown')}'",
|
f"Successfully shared '{file_metadata.get('name', 'Unknown')}'",
|
||||||
"",
|
"",
|
||||||
"Permission created:",
|
"Permission created:",
|
||||||
f" - {format_permission_info(created_permission)}",
|
f" - {format_permission_info(created_permission)}",
|
||||||
"",
|
"",
|
||||||
f"View link: {file_metadata.get('webViewLink', 'N/A')}",
|
f"View link: {file_metadata.get('webViewLink', 'N/A')}",
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# --- grant_batch: share with multiple recipients ---
|
# --- grant_batch: share with multiple recipients ---
|
||||||
if action == "grant_batch":
|
if action == "grant_batch":
|
||||||
@@ -2001,10 +2001,12 @@ async def manage_drive_access(
|
|||||||
"Results:",
|
"Results:",
|
||||||
]
|
]
|
||||||
output_parts.extend(results)
|
output_parts.extend(results)
|
||||||
output_parts.extend([
|
output_parts.extend(
|
||||||
|
[
|
||||||
"",
|
"",
|
||||||
f"View link: {file_metadata.get('webViewLink', 'N/A')}",
|
f"View link: {file_metadata.get('webViewLink', 'N/A')}",
|
||||||
])
|
]
|
||||||
|
)
|
||||||
return "\n".join(output_parts)
|
return "\n".join(output_parts)
|
||||||
|
|
||||||
# --- update: modify an existing permission ---
|
# --- update: modify an existing permission ---
|
||||||
@@ -2056,12 +2058,14 @@ async def manage_drive_access(
|
|||||||
.execute
|
.execute
|
||||||
)
|
)
|
||||||
|
|
||||||
return "\n".join([
|
return "\n".join(
|
||||||
|
[
|
||||||
f"Successfully updated permission on '{file_metadata.get('name', 'Unknown')}'",
|
f"Successfully updated permission on '{file_metadata.get('name', 'Unknown')}'",
|
||||||
"",
|
"",
|
||||||
"Updated permission:",
|
"Updated permission:",
|
||||||
f" - {format_permission_info(updated_permission)}",
|
f" - {format_permission_info(updated_permission)}",
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# --- revoke: remove an existing permission ---
|
# --- revoke: remove an existing permission ---
|
||||||
if action == "revoke":
|
if action == "revoke":
|
||||||
@@ -2083,11 +2087,13 @@ async def manage_drive_access(
|
|||||||
.execute
|
.execute
|
||||||
)
|
)
|
||||||
|
|
||||||
return "\n".join([
|
return "\n".join(
|
||||||
|
[
|
||||||
f"Successfully removed permission from '{file_metadata.get('name', 'Unknown')}'",
|
f"Successfully removed permission from '{file_metadata.get('name', 'Unknown')}'",
|
||||||
"",
|
"",
|
||||||
f"Permission ID '{permission_id}' has been revoked.",
|
f"Permission ID '{permission_id}' has been revoked.",
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# --- transfer_owner: transfer file ownership ---
|
# --- transfer_owner: transfer file ownership ---
|
||||||
# action == "transfer_owner"
|
# action == "transfer_owner"
|
||||||
@@ -2134,14 +2140,6 @@ async def manage_drive_access(
|
|||||||
return "\n".join(output_parts)
|
return "\n".join(output_parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@handle_http_errors("copy_drive_file", is_read_only=False, service_type="drive")
|
@handle_http_errors("copy_drive_file", is_read_only=False, service_type="drive")
|
||||||
@require_google_service("drive", "drive_file")
|
@require_google_service("drive", "drive_file")
|
||||||
@@ -2214,8 +2212,6 @@ async def copy_drive_file(
|
|||||||
return "\n".join(output_parts)
|
return "\n".join(output_parts)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
@handle_http_errors(
|
@handle_http_errors(
|
||||||
"set_drive_file_permissions", is_read_only=False, service_type="drive"
|
"set_drive_file_permissions", is_read_only=False, service_type="drive"
|
||||||
|
|||||||
@@ -1951,7 +1951,9 @@ async def manage_gmail_filter(
|
|||||||
action_lower = action.lower().strip()
|
action_lower = action.lower().strip()
|
||||||
if action_lower == "create":
|
if action_lower == "create":
|
||||||
if not criteria or not filter_action:
|
if not criteria or not filter_action:
|
||||||
raise ValueError("criteria and filter_action are required for create action")
|
raise ValueError(
|
||||||
|
"criteria and filter_action are required for create action"
|
||||||
|
)
|
||||||
logger.info("[manage_gmail_filter] Creating filter")
|
logger.info("[manage_gmail_filter] Creating filter")
|
||||||
filter_body = {"criteria": criteria, "action": filter_action}
|
filter_body = {"criteria": criteria, "action": filter_action}
|
||||||
created_filter = await asyncio.to_thread(
|
created_filter = await asyncio.to_thread(
|
||||||
@@ -1971,7 +1973,11 @@ async def manage_gmail_filter(
|
|||||||
service.users().settings().filters().get(userId="me", id=filter_id).execute
|
service.users().settings().filters().get(userId="me", id=filter_id).execute
|
||||||
)
|
)
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
service.users().settings().filters().delete(userId="me", id=filter_id).execute
|
service.users()
|
||||||
|
.settings()
|
||||||
|
.filters()
|
||||||
|
.delete(userId="me", id=filter_id)
|
||||||
|
.execute
|
||||||
)
|
)
|
||||||
criteria_info = filter_details.get("criteria", {})
|
criteria_info = filter_details.get("criteria", {})
|
||||||
action_info = filter_details.get("action", {})
|
action_info = filter_details.get("action", {})
|
||||||
@@ -1982,11 +1988,9 @@ async def manage_gmail_filter(
|
|||||||
f"Action: {action_info or '(none)'}"
|
f"Action: {action_info or '(none)'}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid action '{action_lower}'. Must be 'create' or 'delete'.")
|
raise ValueError(
|
||||||
|
f"Invalid action '{action_lower}'. Must be 'create' or 'delete'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool()
|
@server.tool()
|
||||||
|
|||||||
@@ -232,5 +232,3 @@ async def get_search_engine_info(service, user_google_email: str) -> str:
|
|||||||
|
|
||||||
logger.info(f"Search engine info retrieved successfully for {user_google_email}")
|
logger.info(f"Search engine info retrieved successfully for {user_google_email}")
|
||||||
return confirmation_message
|
return confirmation_message
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -810,17 +810,12 @@ async def manage_conditional_formatting(
|
|||||||
condition_values_list = _parse_condition_values(condition_values)
|
condition_values_list = _parse_condition_values(condition_values)
|
||||||
gradient_points_list = _parse_gradient_points(gradient_points)
|
gradient_points_list = _parse_gradient_points(gradient_points)
|
||||||
|
|
||||||
sheets, sheet_titles = await _fetch_sheets_with_rules(
|
sheets, sheet_titles = await _fetch_sheets_with_rules(service, spreadsheet_id)
|
||||||
service, spreadsheet_id
|
|
||||||
)
|
|
||||||
grid_range = _parse_a1_range(range_name, sheets)
|
grid_range = _parse_a1_range(range_name, sheets)
|
||||||
|
|
||||||
target_sheet = None
|
target_sheet = None
|
||||||
for sheet in sheets:
|
for sheet in sheets:
|
||||||
if (
|
if sheet.get("properties", {}).get("sheetId") == grid_range.get("sheetId"):
|
||||||
sheet.get("properties", {}).get("sheetId")
|
|
||||||
== grid_range.get("sheetId")
|
|
||||||
):
|
|
||||||
target_sheet = sheet
|
target_sheet = sheet
|
||||||
break
|
break
|
||||||
if target_sheet is None:
|
if target_sheet is None:
|
||||||
@@ -869,9 +864,7 @@ async def manage_conditional_formatting(
|
|||||||
if rule_index is not None:
|
if rule_index is not None:
|
||||||
add_rule_request["index"] = rule_index
|
add_rule_request["index"] = rule_index
|
||||||
|
|
||||||
request_body = {
|
request_body = {"requests": [{"addConditionalFormatRule": add_rule_request}]}
|
||||||
"requests": [{"addConditionalFormatRule": add_rule_request}]
|
|
||||||
}
|
|
||||||
|
|
||||||
await asyncio.to_thread(
|
await asyncio.to_thread(
|
||||||
service.spreadsheets()
|
service.spreadsheets()
|
||||||
@@ -879,9 +872,7 @@ async def manage_conditional_formatting(
|
|||||||
.execute
|
.execute
|
||||||
)
|
)
|
||||||
|
|
||||||
format_desc = (
|
format_desc = ", ".join(applied_parts) if applied_parts else "format applied"
|
||||||
", ".join(applied_parts) if applied_parts else "format applied"
|
|
||||||
)
|
|
||||||
|
|
||||||
sheet_title = target_sheet.get("properties", {}).get("title", "Unknown")
|
sheet_title = target_sheet.get("properties", {}).get("title", "Unknown")
|
||||||
state_text = _format_conditional_rules_section(
|
state_text = _format_conditional_rules_section(
|
||||||
@@ -906,18 +897,15 @@ async def manage_conditional_formatting(
|
|||||||
condition_values_list = _parse_condition_values(condition_values)
|
condition_values_list = _parse_condition_values(condition_values)
|
||||||
gradient_points_list = _parse_gradient_points(gradient_points)
|
gradient_points_list = _parse_gradient_points(gradient_points)
|
||||||
|
|
||||||
sheets, sheet_titles = await _fetch_sheets_with_rules(
|
sheets, sheet_titles = await _fetch_sheets_with_rules(service, spreadsheet_id)
|
||||||
service, spreadsheet_id
|
|
||||||
)
|
|
||||||
|
|
||||||
target_sheet = None
|
target_sheet = None
|
||||||
grid_range = None
|
grid_range = None
|
||||||
if range_name:
|
if range_name:
|
||||||
grid_range = _parse_a1_range(range_name, sheets)
|
grid_range = _parse_a1_range(range_name, sheets)
|
||||||
for sheet in sheets:
|
for sheet in sheets:
|
||||||
if (
|
if sheet.get("properties", {}).get("sheetId") == grid_range.get(
|
||||||
sheet.get("properties", {}).get("sheetId")
|
"sheetId"
|
||||||
== grid_range.get("sheetId")
|
|
||||||
):
|
):
|
||||||
target_sheet = sheet
|
target_sheet = sheet
|
||||||
break
|
break
|
||||||
@@ -979,17 +967,11 @@ async def manage_conditional_formatting(
|
|||||||
else:
|
else:
|
||||||
existing_boolean = existing_rule.get("booleanRule", {})
|
existing_boolean = existing_rule.get("booleanRule", {})
|
||||||
existing_condition = existing_boolean.get("condition", {})
|
existing_condition = existing_boolean.get("condition", {})
|
||||||
existing_format = copy.deepcopy(
|
existing_format = copy.deepcopy(existing_boolean.get("format", {}))
|
||||||
existing_boolean.get("format", {})
|
|
||||||
)
|
|
||||||
|
|
||||||
cond_type = (
|
cond_type = (condition_type or existing_condition.get("type", "")).upper()
|
||||||
condition_type or existing_condition.get("type", "")
|
|
||||||
).upper()
|
|
||||||
if not cond_type:
|
if not cond_type:
|
||||||
raise UserInputError(
|
raise UserInputError("condition_type is required for boolean rules.")
|
||||||
"condition_type is required for boolean rules."
|
|
||||||
)
|
|
||||||
if cond_type not in CONDITION_TYPES:
|
if cond_type not in CONDITION_TYPES:
|
||||||
raise UserInputError(
|
raise UserInputError(
|
||||||
f"condition_type must be one of {sorted(CONDITION_TYPES)}."
|
f"condition_type must be one of {sorted(CONDITION_TYPES)}."
|
||||||
@@ -997,15 +979,12 @@ async def manage_conditional_formatting(
|
|||||||
|
|
||||||
if condition_values_list is not None:
|
if condition_values_list is not None:
|
||||||
cond_values = [
|
cond_values = [
|
||||||
{"userEnteredValue": str(val)}
|
{"userEnteredValue": str(val)} for val in condition_values_list
|
||||||
for val in condition_values_list
|
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
cond_values = existing_condition.get("values")
|
cond_values = existing_condition.get("values")
|
||||||
|
|
||||||
new_format = (
|
new_format = copy.deepcopy(existing_format) if existing_format else {}
|
||||||
copy.deepcopy(existing_format) if existing_format else {}
|
|
||||||
)
|
|
||||||
if background_color is not None:
|
if background_color is not None:
|
||||||
bg_color_parsed = _parse_hex_color(background_color)
|
bg_color_parsed = _parse_hex_color(background_color)
|
||||||
if bg_color_parsed:
|
if bg_color_parsed:
|
||||||
@@ -1014,9 +993,7 @@ async def manage_conditional_formatting(
|
|||||||
del new_format["backgroundColor"]
|
del new_format["backgroundColor"]
|
||||||
if text_color is not None:
|
if text_color is not None:
|
||||||
text_color_parsed = _parse_hex_color(text_color)
|
text_color_parsed = _parse_hex_color(text_color)
|
||||||
text_format = copy.deepcopy(
|
text_format = copy.deepcopy(new_format.get("textFormat", {}))
|
||||||
new_format.get("textFormat", {})
|
|
||||||
)
|
|
||||||
if text_color_parsed:
|
if text_color_parsed:
|
||||||
text_format["foregroundColor"] = text_color_parsed
|
text_format["foregroundColor"] = text_color_parsed
|
||||||
elif "foregroundColor" in text_format:
|
elif "foregroundColor" in text_format:
|
||||||
@@ -1096,9 +1073,7 @@ async def manage_conditional_formatting(
|
|||||||
if not isinstance(rule_index, int) or rule_index < 0:
|
if not isinstance(rule_index, int) or rule_index < 0:
|
||||||
raise UserInputError("rule_index must be a non-negative integer.")
|
raise UserInputError("rule_index must be a non-negative integer.")
|
||||||
|
|
||||||
sheets, sheet_titles = await _fetch_sheets_with_rules(
|
sheets, sheet_titles = await _fetch_sheets_with_rules(service, spreadsheet_id)
|
||||||
service, spreadsheet_id
|
|
||||||
)
|
|
||||||
target_sheet = _select_sheet(sheets, sheet_name)
|
target_sheet = _select_sheet(sheets, sheet_name)
|
||||||
|
|
||||||
sheet_props = target_sheet.get("properties", {})
|
sheet_props = target_sheet.get("properties", {})
|
||||||
|
|||||||
@@ -377,21 +377,13 @@ async def manage_task_list(
|
|||||||
|
|
||||||
# action == "clear_completed"
|
# action == "clear_completed"
|
||||||
if not task_list_id:
|
if not task_list_id:
|
||||||
raise ValueError(
|
raise ValueError("'task_list_id' is required for the 'clear_completed' action.")
|
||||||
"'task_list_id' is required for the 'clear_completed' action."
|
|
||||||
)
|
|
||||||
return await _clear_completed_tasks_impl(service, user_google_email, task_list_id)
|
return await _clear_completed_tasks_impl(service, user_google_email, task_list_id)
|
||||||
|
|
||||||
|
|
||||||
# --- Legacy task list tools (wrappers around _impl functions) ---
|
# --- Legacy task list tools (wrappers around _impl functions) ---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@server.tool() # type: ignore
|
@server.tool() # type: ignore
|
||||||
@require_google_service("tasks", "tasks_read") # type: ignore
|
@require_google_service("tasks", "tasks_read") # type: ignore
|
||||||
@handle_http_errors("list_tasks", service_type="tasks") # type: ignore
|
@handle_http_errors("list_tasks", service_type="tasks") # type: ignore
|
||||||
@@ -1017,13 +1009,3 @@ async def manage_task(
|
|||||||
|
|
||||||
|
|
||||||
# --- Legacy task tools (wrappers around _impl functions) ---
|
# --- Legacy task tools (wrappers around _impl functions) ---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user