Skip to content
Snippets Groups Projects
Select Git revision
  • 77d44c7e146543af795b870fc23dc96ce0d14107
  • master default protected
  • L2SS-1914-fix_job_dispatch
  • TMSS-3170
  • TMSS-3167
  • TMSS-3161
  • TMSS-3158-Front-End-Only-Allow-Changing-Again
  • TMSS-3133
  • TMSS-3319-Fix-Templates
  • test-fix-deploy
  • TMSS-3134
  • TMSS-2872
  • defer-state
  • add-custom-monitoring-points
  • TMSS-3101-Front-End-Only
  • TMSS-984-choices
  • SDC-1400-Front-End-Only
  • TMSS-3079-PII
  • TMSS-2936
  • check-for-max-244-subbands
  • TMSS-2927---Front-End-Only-PXII
  • Before-Remove-TMSS
  • LOFAR-Release-4_4_318 protected
  • LOFAR-Release-4_4_317 protected
  • LOFAR-Release-4_4_316 protected
  • LOFAR-Release-4_4_315 protected
  • LOFAR-Release-4_4_314 protected
  • LOFAR-Release-4_4_313 protected
  • LOFAR-Release-4_4_312 protected
  • LOFAR-Release-4_4_311 protected
  • LOFAR-Release-4_4_310 protected
  • LOFAR-Release-4_4_309 protected
  • LOFAR-Release-4_4_308 protected
  • LOFAR-Release-4_4_307 protected
  • LOFAR-Release-4_4_306 protected
  • LOFAR-Release-4_4_304 protected
  • LOFAR-Release-4_4_303 protected
  • LOFAR-Release-4_4_302 protected
  • LOFAR-Release-4_4_301 protected
  • LOFAR-Release-4_4_300 protected
  • LOFAR-Release-4_4_299 protected
41 results

gridcontroller.js

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    cwl_parsing.py 1.75 KiB
    from pathlib import Path
    import ruamel.yaml
    import chardet
    
    def get_cwl_from_repo(repo_path: str) -> list[dict]:
        """
        Processes all CWL (Common Workflow Language) files in a given repository.
    
        Parameters:
            repo_path (str): The path to the local repository containing CWL files.
    
        Returns:
            list[dict]: 
                list of dictionaries representing parsed CWL files.
        """
        cwl_entities = []
        # Recursively find all CWL files in the repository
        pathlist = list(Path(repo_path).rglob("*.cwl"))
    
        for path in pathlist:
            processed_cwl = process_cwl_file(str(path))
            cwl_entities.append(processed_cwl)
        return cwl_entities
    
    def process_cwl_file(path: str) -> dict:
        """
        Processes a Common Workflow Language (CWL) file by detecting its encoding 
        and parsing it as YAML.
    
        Parameters:
            path (str): The file path to the CWL file.
    
        Returns:
            dict: A dictionary representation of the YAML content, with an additional 
                  'path' key containing the file path.
        
        Notes:
            - Uses `chardet` to detect file encoding, ensuring compatibility with 
              non-UTF-8 encoded files.
            - Uses `ruamel.yaml` for YAML parsing to preserve formatting and ordering.
        """
        # Detect file encoding to handle non-UTF-8 encoded files
        with open(path, 'rb') as file:
            raw_data = file.read()
            result = chardet.detect(raw_data)
            encoding = result['encoding']
    
        # Open the file using the detected encoding and parse it as YAML
        with open(path, "r", encoding=encoding) as file:
            yaml = ruamel.yaml.YAML()
            yaml_dict = yaml.load(file)
    
            # Add the file path to the dictionary for reference
            yaml_dict['path'] = path
    
        return yaml_dict