"""Create a git repo for the project and push it to the Gitea remote.""" import os import sys import time from dulwich import porcelain from dulwich.repo import Repo ROOT = r"C:\Users\GuoAn\Documents\rob-for-qq-vx" REMOTE = "http://xiaoan:guoan123@git.xiaoan.xyz/xiaoan/Rob-for-qq-VX.git" BRANCH = "refs/heads/main" SKIP_DIRS = {".git", "__pycache__", "tmp"} SKIP_FILES = {"config.json"} SKIP_EXT = {".log", ".pyc", ".wav", ".mp3", ".png"} def walk(): for dirpath, dirnames, filenames in os.walk(ROOT): dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS] for name in filenames: if name in SKIP_FILES: continue if os.path.splitext(name)[1].lower() in SKIP_EXT: continue full = os.path.join(dirpath, name) yield os.path.relpath(full, ROOT).replace("\\", "/") def main(): if not os.path.isdir(os.path.join(ROOT, ".git")): Repo.init(ROOT, mkdir=False) repo = Repo(ROOT) files = sorted(walk()) print(f"files: {len(files)}") porcelain.add(repo, files) msg = "docs: restructure markdown docs and publish the bridge" try: porcelain.commit(repo, message=msg, author=b"xiaoan ", committer=b"xiaoan ") except Exception as exc: # noqa: BLE001 print("commit skipped:", exc) porcelain.branch_create(repo, "main", force=True) print("pushing ...") porcelain.push(repo, REMOTE, f"refs/heads/main:{BRANCH}") print("pushed ok") if __name__ == "__main__": main()