channel: also update repos.json

This commit is contained in:
Jörg Thalheim 2018-08-13 17:41:59 +02:00
parent 65df4722c6
commit b132efe226
2 changed files with 34 additions and 4 deletions

View file

@ -85,6 +85,14 @@ def remove_repo(repo: Repo, path: Path) -> None:
commit_files([str(repo_path)], f"{repo.name}: remove")
def update_manifest(repos: List[Repo], path: Path) -> None:
d = {}
for repo in repos:
d[repo.name] = repo.as_json()
write_json_file(dict(repos=d), path)
def update_channel(path: Path) -> None:
manifest = load_manifest(MANIFEST_PATH, LOCK_PATH)
@ -112,6 +120,8 @@ def update_channel(path: Path) -> None:
for channel_repo in channel_repos.values():
remove_repo(channel_repo, path)
update_manifest(updated_repos, path.joinpath("repos.json"))
update_lock_file(updated_repos, path.joinpath("repos.json.lock"))

View file

@ -38,7 +38,7 @@ class RepoType(Enum):
GIT = auto()
@staticmethod
def from_repo(repo: "Repo", type_: str) -> "RepoType":
def from_repo(repo: "Repo", type_: Optional[str]) -> "RepoType":
if repo.submodules:
return RepoType.GIT
if repo.url.hostname == "github.com":
@ -55,7 +55,7 @@ class Repo:
name: str,
url: Url,
submodules: bool,
type_: str,
supplied_type: Optional[str],
file_: Optional[str],
locked_version: Optional[LockedVersion],
) -> None:
@ -75,11 +75,30 @@ class Repo:
):
self.locked_version = locked_version
self.type = RepoType.from_repo(self, type_)
self.supplied_type = supplied_type
self.computed_type = RepoType.from_repo(self, supplied_type)
@property
def type(self) -> RepoType:
return self.computed_type
def __repr__(self) -> str:
return f"<{self.__class__.__name__} {self.name}>"
def as_json(self) -> Dict[str, Any]:
d = dict(url=self.url.geturl()) # type: Dict[str, Any]
if self.submodules:
d["submodules"] = self.submodules
if self.supplied_type is not None:
d["type"] = self.supplied_type
if self.file is not None and self.file != "default.nix":
d["file"] = self.file
return d
class Manifest:
def __init__(self, repos: List[Repo]) -> None:
@ -99,7 +118,8 @@ def _load_locked_versions(path: PathType) -> Dict[str, LockedVersion]:
url = urlparse(repo["url"])
rev = repo["rev"]
sha256 = repo["sha256"]
locked_versions[name] = LockedVersion(url, rev, sha256)
submodules = repo.get("submodules", False)
locked_versions[name] = LockedVersion(url, rev, sha256, submodules)
return locked_versions