|
1 | 1 | import abc
|
| 2 | +import enum |
2 | 3 | import itertools
|
3 | 4 | import json
|
| 5 | +import sys |
4 | 6 | from collections.abc import Iterable
|
5 | 7 | from enum import Enum
|
| 8 | +from functools import lru_cache |
6 | 9 | from pathlib import Path
|
7 | 10 | from typing import Generic, Optional, TypeVar, Union
|
8 | 11 |
|
|
30 | 33 | #
|
31 | 34 |
|
32 | 35 |
|
| 36 | +class Platform(enum.Enum): |
| 37 | + LINUX = "linux" |
| 38 | + MACOS = "darwin" |
| 39 | + |
| 40 | + |
| 41 | +@lru_cache |
| 42 | +def current_platform() -> Platform: |
| 43 | + try: |
| 44 | + return Platform(sys.platform) |
| 45 | + except KeyError: |
| 46 | + raise ValueError(f"Unsupported platform: {sys.platform}") from None |
| 47 | + |
| 48 | + |
33 | 49 | @attrs.define(frozen=True)
|
34 | 50 | class Task:
|
35 | 51 | path: Path
|
@@ -417,13 +433,20 @@ class DirectoryHandler(abc.ABC):
|
417 | 433 |
|
418 | 434 | PATTERN: DirectoryPattern
|
419 | 435 |
|
| 436 | + SUPPORTED_PLATFORMS: set[Platform] = {Platform.LINUX, Platform.MACOS} |
| 437 | + |
420 | 438 | @classmethod
|
421 | 439 | def get_dependencies(cls):
|
422 | 440 | """Return external command dependencies needed for this handler to work."""
|
423 | 441 | if cls.EXTRACTOR:
|
424 | 442 | return cls.EXTRACTOR.get_dependencies()
|
425 | 443 | return []
|
426 | 444 |
|
| 445 | + @classmethod |
| 446 | + def is_supported_here(cls) -> bool: |
| 447 | + """Check if the current platform is supported by this handler.""" |
| 448 | + return current_platform() in cls.SUPPORTED_PLATFORMS |
| 449 | + |
427 | 450 | @abc.abstractmethod
|
428 | 451 | def calculate_multifile(self, file: Path) -> Optional[MultiFile]:
|
429 | 452 | """Calculate the MultiFile in a directory, using a file matched by the pattern as a starting point."""
|
@@ -453,13 +476,20 @@ class Handler(abc.ABC, Generic[TExtractor]):
|
453 | 476 |
|
454 | 477 | EXTRACTOR: TExtractor
|
455 | 478 |
|
| 479 | + SUPPORTED_PLATFORMS: set[Platform] = {Platform.LINUX, Platform.MACOS} |
| 480 | + |
456 | 481 | @classmethod
|
457 | 482 | def get_dependencies(cls):
|
458 | 483 | """Return external command dependencies needed for this handler to work."""
|
459 | 484 | if cls.EXTRACTOR is not None:
|
460 | 485 | return cls.EXTRACTOR.get_dependencies()
|
461 | 486 | return []
|
462 | 487 |
|
| 488 | + @classmethod |
| 489 | + def is_supported_here(cls) -> bool: |
| 490 | + """Check if the current platform is supported by this handler.""" |
| 491 | + return current_platform() in cls.SUPPORTED_PLATFORMS |
| 492 | + |
463 | 493 | @abc.abstractmethod
|
464 | 494 | def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]:
|
465 | 495 | """Calculate the Chunk offsets from the File and the file type headers."""
|
|
0 commit comments