Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/python
import sys, os, os.path
GITHUB_SRC_ROOT='/is/github'
# git@github.com:is/conf.git
# https://github.com/is/conf.git
def ParseURL(url):
if url.startswith("git@github.com"):
user, k, project = url.partition(':')[2].partition('/')
elif url.startswith("https://github.com/"):
user, k, project = url[len("https://github.com/"):].partition('/')
else:
user = 'XXXX'
project = 'XXXX.git'
return [user, project[:-4]]
def GitFetch(user, project):
os.system("cd %s;git pull " % MainPath(user, project))
print "-- FETCH --"
print MainPath(user, project)
print Level1Path(user, project)
print Level2Path(user, project)
print Level3Path(user, project)
def GitClone(url, user, project):
lmain = MainPath(user, project)
try:
os.makedirs(os.path.dirname(lmain))
except OSError, e:
pass
print "git clone -o github %s %s" % (url, lmain)
os.system("git clone -o github %s %s" % (url, lmain))
l1 = Level1Path(user, project)
l2 = Level2Path(user, project)
l3 = Level3Path(user, project)
for l in [l1, l2, l3]:
try:
os.unlink(l)
except OSError, e:
pass
os.symlink(lmain, l)
print "-- CLONE --"
print lmain
print l1
print l2
print l3
def MainPath(user, project):
return os.path.join(GITHUB_SRC_ROOT, user, project)
def Level1Path(user, project):
return os.path.join(GITHUB_SRC_ROOT, '1', project)
def Level2Path(user, project):
return os.path.join(GITHUB_SRC_ROOT, '2', user + "__" + project)
def Level3Path(user, project):
return os.path.join(GITHUB_SRC_ROOT, '3', project + "__" + user)
def main():
url = sys.argv[1]
if url [-1] == '/':
url = url[:-1]
if not url.endswith(".git"):
url = url + ".git"
user, project = ParseURL(url)
lmain = MainPath(user, project)
print lmain
if os.path.exists(lmain):
GitFetch(user, project)
else:
GitClone(url, user, project)
if __name__ == '__main__':
main()
# vim: ts=2 sts=2 ai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.