Parse a CSV/Excel batch file and return tasks plus file base name.
(content: bytes, filename: str)
| 21 | |
| 22 | |
| 23 | def parse_batch_file(content: bytes, filename: str) -> Tuple[List[BatchTask], str]: |
| 24 | """Parse a CSV/Excel batch file and return tasks plus file base name.""" |
| 25 | suffix = Path(filename or "").suffix.lower() |
| 26 | if suffix not in {".csv", ".xlsx", ".xls"}: |
| 27 | raise ValidationError("Unsupported file type; must be .csv or .xlsx/.xls", field="file") |
| 28 | |
| 29 | if suffix == ".csv": |
| 30 | df = _read_csv(content) |
| 31 | else: |
| 32 | df = _read_excel(content) |
| 33 | |
| 34 | file_base = Path(filename).stem or "batch" |
| 35 | tasks = _parse_dataframe(df) |
| 36 | if not tasks: |
| 37 | raise ValidationError("Batch file contains no tasks", field="file") |
| 38 | return tasks, file_base |
| 39 | |
| 40 | |
| 41 | def _read_csv(content: bytes) -> pd.DataFrame: |
no test coverage detected