From 97086e489db4e4b99a21fe3ad52f06917f39e482 Mon Sep 17 00:00:00 2001 From: git user Date: Thu, 6 Aug 2026 23:22:15 -0700 Subject: short names --- README.md | 7 +++++-- update_mirrors.py | 63 +++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a7e1b02..1b7467d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Bitbucket is where our private repositories are kept. For some reason python3-github was different enough that I had to install PyGithub with pip and --break-system-packages. -https://pygithub.readthedocs.io/en/stable/github_objects/Repository.html#github.Repository.Repository.ssh_url +https://pygithub.readthedocs.io/en/stable/github_objects/Repository.html So the idea is to check for all of the repos that I own/clon/participate in and mirror them. @@ -31,4 +31,7 @@ So the idea is to check for all of the repos that I own/clon/participate in and - if repo is not mirrored - create a mirror - else - - update the mirror \ No newline at end of file + - update the mirror + +## cgit + diff --git a/update_mirrors.py b/update_mirrors.py index c5a56e3..e5ce1d8 100755 --- a/update_mirrors.py +++ b/update_mirrors.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 + + + import os import subprocess from github import Github @@ -23,27 +26,47 @@ def myrepos() : g.close() return(repos) +#repo.url=wcm +#repo.owner=yctct +#repo.path=/home/git/repositories/wcm.git +#repo.desc= a script to count words in Markdown files +# +# Consider sorting by prefix and making group entries if __name__ == "__main__": local_prefix="/srv/git/mirrors/github/" - - for url in myrepos(): - #print(url) - local_copy=local_prefix+url.split(':')[1] - if os.path.isdir(local_copy): - print("updating local copy: " + local_copy) - result=subprocess.run(["git", "remote", "update"], - cwd=local_copy, capture_output=True) - print(result.stdout.decode(), end='') - print(result.stderr.decode(), end='') - else: - print("create new mirror at: "+local_copy) - result=subprocess.run(["git","clone","--mirror", url, - local_copy], capture_output=True) - print(result.stdout.decode(), end='') - print(result.stderr.decode(), end='') - - #print(local_copy) - #mypath="/srv/git/mirrors/github/"+repo.ssh_url.split(':')[1] - #print("git clone --mirror " +repo.ssh_url+" "+mypath) + g = mygithub() + with open("/srv/git/repolist", "w") as repolist: + + for repo in g.get_user().get_repos(): + url=repo.ssh_url + shortname = url.split(':')[1].split('.')[0] + local_copy=local_prefix+url.split(':')[1] + + repolist.write("repo.url="+shortname+"\n") + # repolist.write("repo.url="+url+"\n") + repolist.write("repo.owner=feurig\n") + repolist.write("repo.path="+local_copy+"\n") + description = repo.description + if repo.description is None: + description = "No Description Provided" + repolist.write("repo.desc="+description+"\n") + + if os.path.isdir(local_copy): + print("updating local copy: " + local_copy) + result=subprocess.run(["git", "remote", "update"], + cwd=local_copy, capture_output=True) + print(result.stdout.decode(), end='') + print(result.stderr.decode(), end='') + else: + print("create new mirror at: "+local_copy) + result=subprocess.run(["git","clone","--mirror", url, + local_copy], capture_output=True) + print(result.stdout.decode(), end='') + print(result.stderr.decode(), end='') + + #print(local_copy) + #mypath="/srv/git/mirrors/github/"+repo.ssh_url.split(':')[1] + #print("git clone --mirror " +repo.ssh_url+" "+mypath) + g.close() \ No newline at end of file -- cgit v1.2.3