diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-09-17 19:41:21 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2012-09-17 19:41:21 +0200 |
commit | 7859445bf4c18f9182cff48b058786f971ca21d7 (patch) | |
tree | c077081cc4dcb7cd7a424e37d1eb43d98c3d9cb9 /sync-github.py | |
parent | Read description from git's config, not from flat file. (diff) | |
download | GitTools-7859445bf4c18f9182cff48b058786f971ca21d7.tar.xz GitTools-7859445bf4c18f9182cff48b058786f971ca21d7.zip |
Use control master in ssh and work around github deletion bugs.
Diffstat (limited to 'sync-github.py')
-rwxr-xr-x | sync-github.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/sync-github.py b/sync-github.py index 73499b7..687e01c 100755 --- a/sync-github.py +++ b/sync-github.py @@ -3,6 +3,8 @@ from pygithub3 import Github import sys import os import os.path +import stat +import uuid import subprocess class LocalRepo: @@ -65,12 +67,25 @@ def main(argv): for repo in remote_repos: if repo.name not in [local.name for local in local_repos]: print "[-] Deleting repository %s." % repo.name - github.repos.delete(repo=repo.name, user=user) - + try: + github.repos.delete(repo=repo.name, user=user) + except: + pass + + print "[#] Connecting to github ssh." + control_master = os.path.abspath(os.path.dirname(__file__) + "/.ssh-control-" + str(uuid.uuid4())) + ssh_cmd = control_master + ".cmd.sh" + cmd_file = open(ssh_cmd, "w") + cmd_file.write("#!/bin/sh\nexec ssh -o ControlMaster=no -o ControlPath=\"%s\" $@\n" % control_master) + cmd_file.close() + os.chmod(ssh_cmd, stat.S_IRWXU) + os.system("ssh -Nf -o ControlMaster=yes -o ControlPath=\"%s\" git@github.com" % control_master) for repo in local_repos: print "[^] Mirroring repository %s." % repo.name - os.system("cd \"%s\"; git push --mirror git@github.com:%s/%s.git" % (repo.path, user, repo.name)) - + os.system("cd \"%s\"; GIT_SSH=\"%s\" git push --mirror git@github.com:%s/%s.git" % (repo.path, ssh_cmd, user, repo.name)) + os.system("ssh -o ControlMaster=no -o ControlPath=\"%s\" -O exit -N git@github.com" % control_master) + os.unlink(ssh_cmd) + return 0 if __name__ == "__main__": |