From fba0e08fffafe0fe341bc09a3f7f256c6e94e66d Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Mon, 20 Aug 2012 11:34:32 +0100 Subject: [PATCH] Support for importing git from bitbucket --- fdroidserver/import.py | 112 +++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/fdroidserver/import.py b/fdroidserver/import.py index e0994e0b..60690fc5 100644 --- a/fdroidserver/import.py +++ b/fdroidserver/import.py @@ -25,6 +25,63 @@ import re import urllib from optparse import OptionParser + +# Get the repo type and address from the given web page. The page is scanned +# in a rather naive manner for 'git clone xxxx', 'hg clone xxxx', etc, and +# when one of these is found it's assumed that's the information we want. +# Returns repotype, address, or None, reason +def getrepofrompage(url): + + req = urllib.urlopen(url) + if req.getcode() != 200: + return (None, 'Unable to find source at ' + sourcecode + ' - return code ' + str(req.getcode())) + page = req.read() + + # Works for Google Code and BitBucket... + index = page.find('hg clone') + if index != -1: + repotype = 'hg' + repo = page[index + 9:] + index = repo.find('<') + if index == -1: + return (None, "Error while getting repo address") + repo = repo[:index] + return (repotype, repo) + + # Works for Google Code and BitBucket... + index=page.find('git clone') + if index != -1: + repotype = 'git' + repo = page[index + 10:] + index = repo.find('<') + if index == -1: + return (None, "Error while getting repo address") + repo = repo[:index] + return (repotype, repo) + + # Google Code only... + index=page.find('svn checkout') + if index != -1: + repotype = 'git-svn' + repo = page[index + 13:] + prefix = 'http' + if not repo.startswith(prefix): + return (None, "Unexpected checkout instructions format") + repo = 'http' + repo[len(prefix):] + index = repo.find('<') + if index == -1: + return (None, "Error while getting repo address - no end tag? '" + repo + "'") + sys.exit(1) + repo = repo[:index] + index = repo.find(' ') + if index == -1: + return (None, "Error while getting repo address - no space? '" + repo + "'") + repo = repo[:index] + return (repotype, repo) + + return (None, "No information found." + page) + + def main(): # Read configuration... @@ -84,8 +141,11 @@ def main(): projecttype = 'bitbucket' sourcecode = url + '/src' issuetracker = url + '/issues' - repotype = 'hg' - repo = url + # Figure out the repo type and adddress... + repotype, repo = getrepofrompage(sourcecode) + if not repotype: + print "Unable to determine vcs type. " + repo + sys.exit(1) elif url.startswith('http://code.google.com/p/'): if not url.endswith('/'): url += '/'; @@ -96,53 +156,9 @@ def main(): issuetracker = url + 'issues/list' # Figure out the repo type and adddress... - req = urllib.urlopen(sourcecode) - if req.getcode() != 200: - print 'Unable to find source at ' + sourcecode + ' - return code ' + str(req.getcode()) - sys.exit(1) - page = req.read() - repotype = None - index = page.find('hg clone') - if index != -1: - repotype = 'hg' - repo = page[index + 9:] - index = repo.find('<') - if index == -1: - print "Error while getting repo address" - sys.exit(1) - repo = repo[:index] + repotype, repo = getrepofrompage(sourcecode) if not repotype: - index=page.find('git clone') - if index != -1: - repotype = 'git' - repo = page[index + 10:] - index = repo.find('<') - if index == -1: - print "Error while getting repo address" - sys.exit(1) - repo = repo[:index] - if not repotype: - index=page.find('svn checkout') - if index != -1: - repotype = 'git-svn' - repo = page[index + 13:] - prefix = 'http' - if not repo.startswith(prefix): - print "Unexpected checkout instructions format" - sys.exit(1) - repo = 'http' + repo[len(prefix):] - index = repo.find('<') - if index == -1: - print "Error while getting repo address - no end tag? '" + repo + "'" - sys.exit(1) - repo = repo[:index] - index = repo.find(' ') - if index == -1: - print "Error while getting repo address - no space? '" + repo + "'" - sys.exit(1) - repo = repo[:index] - if not repotype: - print "Unable to determine vcs type" + print "Unable to determine vcs type. " + repo sys.exit(1) # Figure out the license...