DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (dcc6d7a0dc00)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import json
import os
import site

# SelfServeMixin {{{1
class SelfServeMixin(object):
    def _get_session(self):
        site_packages_path = self.query_python_site_packages_path()
        site.addsitedir(site_packages_path)
        import requests
        session = requests.Session()
        adapter = requests.adapters.HTTPAdapter(max_retries=5)
        session.mount("http://", adapter)
        session.mount("https://", adapter)
        return session

    def _get_base_url(self):
        return self.config["selfserve_url"].rstrip("/")

    def trigger_nightly_builds(self, branch, revision, auth):
        session = self._get_session()

        selfserve_base = self._get_base_url()
        url = "%s/%s/rev/%s/nightly" % (selfserve_base, branch, revision)

        data = {
            "revision": revision,
        }
        self.info("Triggering nightly builds via %s" % url)
        return session.post(url, data=data, auth=auth).raise_for_status()

    def trigger_arbitrary_job(self, builder, branch, revision, auth, files=None):
        session = self._get_session()

        selfserve_base = self._get_base_url()
        url = "%s/%s/builders/%s/%s" % (selfserve_base, branch, builder, revision)

        data = {
            "properties": json.dumps({
                "branch": branch,
                "revision": revision
            }),
        }
        if files:
            data["files"] = json.dumps(files)

        self.info("Triggering arbritrary job at %s" % url)
        return session.post(url, data=data, auth=auth).raise_for_status()