diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/mozharness/external_tools/detect_repo.py | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozharness/external_tools/detect_repo.py')
-rw-r--r-- | testing/mozharness/external_tools/detect_repo.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/testing/mozharness/external_tools/detect_repo.py b/testing/mozharness/external_tools/detect_repo.py new file mode 100644 index 000000000..67466a03e --- /dev/null +++ b/testing/mozharness/external_tools/detect_repo.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# Stolen from taskcluster-vcs +# https://github.com/taskcluster/taskcluster-vcs/blob/master/src/vcs/detect_remote.js + +from urllib2 import Request, urlopen +from urlparse import urlsplit, urlunsplit +from os.path import exists, join + +def first(seq): + return next(iter(filter(lambda x: x, seq)), '') + +def all_first(*sequences): + return map(lambda x: first(x), sequences) + +# http://codereview.stackexchange.com/questions/13027/joining-url-path-components-intelligently +# I wonder why this is not a builtin feature in Python +def urljoin(*parts): + schemes, netlocs, paths, queries, fragments = zip(*(urlsplit(part) for part in parts)) + scheme, netloc, query, fragment = all_first(schemes, netlocs, queries, fragments) + path = '/'.join(p.strip('/') for p in paths if p) + return urlunsplit((scheme, netloc, path, query, fragment)) + +def _detect_remote(url, content): + try: + response = urlopen(url) + except Exception: + return False + + if response.getcode() != 200: + return False + + content_type = response.headers.get('content-type', '') + return True if content in content_type else False + +def detect_git(url): + location = urljoin(url, '/info/refs?service=git-upload-pack') + req = Request(location, headers={'User-Agent':'git/2.0.1'}) + return _detect_remote(req, 'x-git') + +def detect_hg(url): + location = urljoin(url, '?cmd=lookup&key=0') + return _detect_remote(location, 'mercurial') + +def detect_local(url): + if exists(join(url, '.git')): + return 'git' + + if exists(join(url, '.hg')): + return 'hg' + + return '' + |