Add update repo script
parent
6f4999cb54
commit
926414b136
|
@ -0,0 +1,89 @@
|
|||
#! /usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
class Repo:
|
||||
_repo:str
|
||||
|
||||
def __init__(self, repo:str):
|
||||
assert isinstance(repo, str)
|
||||
self._repo = repo
|
||||
|
||||
@property
|
||||
def flatpaks(self):
|
||||
tmp = subprocess.run(["ostree", "refs", "--repo", self._repo], capture_output=True, check=True)
|
||||
return list(filter(lambda x: x.startswith(("runtime/", "app/")), tmp.stdout.decode().splitlines()))
|
||||
|
||||
def move_commit(self, repo, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None):
|
||||
assert isinstance(repo, Repo)
|
||||
assert isinstance(commit, str)
|
||||
assert isinstance(no_fsync, bool)
|
||||
assert gpg_key is None or isinstance(gpg_key, str)
|
||||
assert collection is None or isinstance(collection, str)
|
||||
|
||||
run_args = []
|
||||
if no_fsync:
|
||||
run_args.append("--disable-fsync")
|
||||
if gpg_key:
|
||||
run_args.append("--gpg-sign=" + gpg_key)
|
||||
if collection:
|
||||
run_args.append("--extra-collection-id=" + collection)
|
||||
subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--src-repo=" + repo._repo, "--src-ref=" + commit, "--no-update-summary", self._repo, commit], check=True)
|
||||
|
||||
def make_eol(self, commit:str, no_fsync:bool=False, gpg_key:str=None, collection:str=None):
|
||||
assert isinstance(commit, str)
|
||||
assert isinstance(no_fsync, bool)
|
||||
assert gpg_key is None or isinstance(gpg_key, str)
|
||||
assert collection is None or isinstance(collection, str)
|
||||
|
||||
run_args = []
|
||||
if no_fsync:
|
||||
run_args.append("--disable-fsync")
|
||||
if gpg_key:
|
||||
run_args.append("--gpg-sign=" + gpg_key)
|
||||
if collection:
|
||||
run_args.append("--extra-collection-id=" + collection)
|
||||
subprocess.run(["flatpak", "build-commit-from"] + run_args + ["--end-of-life=Base commit doesn't exists any more.", "--no-update-summary", "--src-ref=empty", self._repo, commit], check=True)
|
||||
|
||||
def gen_empty(self):
|
||||
subprocess.run(["tar", "-cf", "empty.tar", "-T", "/dev/null"], check=True)
|
||||
subprocess.run(["ostree", "commit", "--repo", self._repo, "--tar-autocreate-parents", "--tree=tar=empty.tar", "-b", "empty"], check=True)
|
||||
os.remove("empty.tar")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
# Argument parser
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("repo", nargs=1, help="Repo to manage")
|
||||
parser.add_argument("sources", nargs="+", help="Path with repos")
|
||||
parser.add_argument("--collection", "-c", type=str, default=None, nargs="?", help="Set collection")
|
||||
parser.add_argument("--gpg", "-g", type=str, default=None, nargs="?", help="GPG-Key")
|
||||
parser.add_argument("--no-fsync", dest="no_fsync", action="store_const", const=True, default=False, help="Not fsync")
|
||||
args = parser.parse_args()
|
||||
|
||||
# Gen sources
|
||||
source_repos = []
|
||||
for i in args.sources:
|
||||
for j in map(lambda x: os.path.join(i, x), os.listdir(i)):
|
||||
source_repos.append(Repo(j))
|
||||
target_repo = Repo(args.repo[0])
|
||||
|
||||
# Move commit
|
||||
commits_added = []
|
||||
for i in source_repos:
|
||||
tmp = i.flatpaks
|
||||
commits_added += tmp
|
||||
for j in tmp:
|
||||
target_repo.move_commit(i, j, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection)
|
||||
|
||||
# Create empty
|
||||
if "empty" not in target_repo.flatpaks:
|
||||
target_repo.gen_empty()
|
||||
|
||||
# Remove old
|
||||
commits_added = set(commits_added)
|
||||
for i in filter(lambda x: x not in commits_added, target_repo.flatpaks):
|
||||
target_repo.make_eol(i, no_fsync=args.no_fsync, gpg_key=args.gpg, collection=args.collection)
|
Loading…
Reference in New Issue