fix: Address high-severity bandit issues
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
DSS Figma Sync CLI
|
||||
DSS Figma Sync CLI.
|
||||
|
||||
This script is a lightweight CLI wrapper around the FigmaTokenSource from the
|
||||
dss.ingest module. It fetches tokens and components from Figma and saves them
|
||||
@@ -10,22 +10,21 @@ The core extraction and processing logic resides in:
|
||||
dss.ingest.sources.figma.FigmaTokenSource
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from dataclasses import asdict
|
||||
import argparse
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from dss.ingest.base import TokenCollection
|
||||
from dss.ingest.sources.figma import FigmaTokenSource
|
||||
|
||||
# Ensure the project root is in the Python path
|
||||
DSS_ROOT = Path(__file__).parent.parent
|
||||
if str(DSS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(DSS_ROOT))
|
||||
|
||||
from dss.ingest.sources.figma import FigmaTokenSource
|
||||
from dss.ingest.base import TokenCollection
|
||||
|
||||
# =============================================================================
|
||||
# CONFIGURATION
|
||||
@@ -39,6 +38,7 @@ COMPONENTS_DIR = DSS_ROOT / ".dss/components"
|
||||
# OUTPUT WRITER
|
||||
# =============================================================================
|
||||
|
||||
|
||||
class OutputWriter:
|
||||
"""Writes extraction results to the DSS file structure."""
|
||||
|
||||
@@ -49,10 +49,10 @@ class OutputWriter:
|
||||
"""Write TokenCollection to a structured JSON file."""
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
tokens_file = output_dir / "figma-tokens.json"
|
||||
|
||||
|
||||
if self.verbose:
|
||||
print(f" [OUT] Writing {len(collection)} tokens to {tokens_file}")
|
||||
|
||||
|
||||
with open(tokens_file, "w") as f:
|
||||
json.dump(json.loads(collection.to_json()), f, indent=2)
|
||||
print(f" [OUT] Tokens: {tokens_file}")
|
||||
@@ -61,18 +61,22 @@ class OutputWriter:
|
||||
"""Write component registry."""
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
comp_file = output_dir / "figma-registry.json"
|
||||
|
||||
|
||||
if self.verbose:
|
||||
print(f" [OUT] Writing {components.get('component_count', 0)} components to {comp_file}")
|
||||
print(
|
||||
f" [OUT] Writing {components.get('component_count', 0)} components to {comp_file}"
|
||||
)
|
||||
|
||||
with open(comp_file, "w") as f:
|
||||
json.dump(components, f, indent=2)
|
||||
print(f" [OUT] Components: {comp_file}")
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# MAIN ORCHESTRATOR
|
||||
# =============================================================================
|
||||
|
||||
|
||||
async def main():
|
||||
"""Main CLI orchestration function."""
|
||||
parser = argparse.ArgumentParser(description="DSS Intelligent Figma Sync")
|
||||
@@ -95,7 +99,7 @@ async def main():
|
||||
print("[ERROR] No Figma token found.", file=sys.stderr)
|
||||
print(" Set FIGMA_TOKEN env var or add 'token' to .dss/config/figma.json", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
print_header(file_key, token, args.force)
|
||||
|
||||
# --- Extraction ---
|
||||
@@ -107,6 +111,7 @@ async def main():
|
||||
# In verbose mode, print more details
|
||||
if args.verbose:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
@@ -120,13 +125,14 @@ async def main():
|
||||
print_summary(
|
||||
file_name=component_registry.get("file_name", "Unknown"),
|
||||
token_count=len(token_collection),
|
||||
component_count=component_registry.get("component_count", 0)
|
||||
component_count=component_registry.get("component_count", 0),
|
||||
)
|
||||
|
||||
|
||||
print("\n[OK] Sync successful!")
|
||||
print(" Next: Run the translation and theming pipeline.")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def load_config() -> Dict:
|
||||
"""Load Figma config from .dss/config/figma.json."""
|
||||
config_path = DSS_ROOT / ".dss/config/figma.json"
|
||||
@@ -135,9 +141,12 @@ def load_config() -> Dict:
|
||||
with open(config_path) as f:
|
||||
return json.load(f)
|
||||
except (json.JSONDecodeError, IOError) as e:
|
||||
print(f"[WARN] Could not read or parse config file: {config_path}\n{e}", file=sys.stderr)
|
||||
print(
|
||||
f"[WARN] Could not read or parse config file: {config_path}\n{e}", file=sys.stderr
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
def print_header(file_key: str, token: str, force: bool):
|
||||
"""Prints the CLI header."""
|
||||
print("╔══════════════════════════════════════════════════════════════╗")
|
||||
@@ -148,6 +157,7 @@ def print_header(file_key: str, token: str, force: bool):
|
||||
print(f" Force: {force}")
|
||||
print("\n[1/3] Initializing Figma Ingestion Source...")
|
||||
|
||||
|
||||
def print_summary(file_name: str, token_count: int, component_count: int):
|
||||
"""Prints the final summary."""
|
||||
print("\n" + "=" * 60)
|
||||
|
||||
Reference in New Issue
Block a user