From 7591c0f54fa3272df0f6b7057f6096bb513e9328 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 12 Apr 2021 12:12:16 -0600 Subject: give sections a separate thing --- repos/base.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'repos/base.py') diff --git a/repos/base.py b/repos/base.py index 1b4c42b..de0e5dc 100644 --- a/repos/base.py +++ b/repos/base.py @@ -58,24 +58,38 @@ class JSONDecoder(json.JSONDecoder): super().__init__(object_hook=self.object_hook) -@dataclass() +@dataclass(frozen=True) class Repository: family: Optional[str] repo: str + section: Optional[str] index_url: str parse: Callable[[Path], Mapping[str, Version]] def full_name(self): - if self.family is None: - return self.repo - else: - return f'{self.family} {self.repo}' + prefix = '' + if self.family is not None: + prefix = self.family + ' ' + suffix = '' + if self.section is not None: + suffix = ' ' + self.section + return f'{prefix}{self.repo}{suffix}' + + @property + def full_repo_name(self): + prefix = '' + if self.family is not None: + prefix = self.family + ' ' + return f'{prefix}{self.repo}' def _cache_dir(self) -> Path: - if self.family is None: - return Path('data') / slug(self.repo) - else: - return Path('data') / slug(self.family) / slug(self.repo) + result = Path('data') + if self.family is not None: + result = result / slug(self.family) + result = result / slug(self.repo) + if self.section is not None: + result = result / slug(self.section) + return result def _cache_file(self, name: str) -> Path: return self._cache_dir() / name -- cgit v1.2.3