Add detector modules
This commit is contained in:
58
confsync/detectors/git.py
Normal file
58
confsync/detectors/git.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Git configuration file detectors."""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
from confsync.detectors.base import BaseDetector, detector
|
||||
from confsync.models.config_models import ConfigCategory
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from confsync.models.config_models import ConfigFile
|
||||
|
||||
|
||||
@detector
|
||||
class GitConfigDetector(BaseDetector):
|
||||
"""Detector for Git configurations."""
|
||||
|
||||
category = ConfigCategory.GIT
|
||||
tool_name = "git"
|
||||
|
||||
def get_default_locations(self) -> List[str]:
|
||||
"""Get Git config locations."""
|
||||
return [
|
||||
str(Path.home() / ".gitconfig"),
|
||||
str(Path.home() / ".gitattributes"),
|
||||
str(Path.home() / ".gitignore"),
|
||||
str(Path.home() / ".config" / "git"),
|
||||
]
|
||||
|
||||
def get_file_patterns(self) -> List[str]:
|
||||
"""Get Git file patterns."""
|
||||
return [".gitconfig", ".gitattributes", ".gitignore"]
|
||||
|
||||
def detect(self) -> List["ConfigFile"]:
|
||||
"""Detect Git configuration files."""
|
||||
configs = []
|
||||
home = Path.home()
|
||||
|
||||
git_files = [
|
||||
home / ".gitconfig",
|
||||
home / ".gitattributes",
|
||||
home / ".gitignore",
|
||||
]
|
||||
|
||||
for git_file in git_files:
|
||||
if git_file.exists():
|
||||
config = self._create_config_file(str(git_file))
|
||||
config.metadata = {"version_control": "git"}
|
||||
configs.append(config)
|
||||
|
||||
git_config_dir = home / ".config" / "git"
|
||||
if git_config_dir.exists() and git_config_dir.is_dir():
|
||||
for file_path in git_config_dir.iterdir():
|
||||
if file_path.is_file():
|
||||
config = self._create_config_file(str(file_path))
|
||||
config.metadata = {"version_control": "git", "xdg": True}
|
||||
configs.append(config)
|
||||
|
||||
return configs
|
||||
Reference in New Issue
Block a user