<commit_before>import json
import urllib
import re


class TravisManager:
    """Get information from Travis-CI
    """
    def __init__(self):
        self.urlBase = 'http://travis-ci.org/'
        self.repos = self.urlBase + 'repositories.json'
        self.reposByOwner = self.urlBase + 'repositories.json?owner_name={owner}'
        self.reposIndexSearch = self.urlBase + 'repositories.json?search={query}'
        self.reposShow = self.urlBase + '{owner_name}/{name}.json'
        self.builds = self.urlBase + '{owner_name}/{name}/builds.json'
        self.buildsShow = self.urlBase + '{owner_name}/{name}/builds/{id}.json'
        self.workers = self.urlBase + 'workers.json'
        self.jobs = self.urlBase + 'jobs.json'
        self.jobsShow = self.urlBase + 'jobs/{id}.json'

    def getRepos(self, _owner):
        """Return a list with the owner's repositories
        """
        return json.loads(urllib.urlopen(self.reposByOwner.format(owner = _owner)).read())


    def getBuildsAndJobs(self, _owner):
        """
        Returns a list with all the owner's builds
        """
        repos = json.loads(urllib.urlopen(self.reposByOwner.format(owner=_owner)).read())
        buildsList = []
        runningList = []
        jobsList = []

        # Build the builds list
        for repo in repos:
            buildsPerRepo = json.loads(urllib.urlopen(self.builds.format(owner_name=_owner, name=repo['slug'].split('/')[-1])).read())
            for build in buildsPerRepo:
                build['repository'] = repo['slug'].split('/')[-1]
                if build['state'] == 'started':
                    runningList.append(build)
                buildsList.append(build)

        # Build running jobs list
        for r in runningList:
            jobID = json.loads(urllib.urlopen(self.buildsShow.format(owner_name=_owner, name=r['repository'], id=r['id'])).read())['matrix'][0]['id']
            job = json.loads(urllib.urlopen(self.jobsShow.format(id = jobID)).read())
            job['repository'] = r['repository']
            jobsList.append(job)

        return buildsList, jobsList

    def getRelatedJob(self, buildID, repo, owner):
        """
        Return the job releted to the build <buildID> of the owner's <owner> repo <repo>
        """
        jobID = json.loads(urllib.urlopen(self.buildsShow.format(owner_name=owner, name=repo, id=buildID)).read())['matrix'][0]['id']
        return json.loads(urllib.urlopen(self.jobsShow.format(id=jobID)).read())

    def getFormattedLog(self, log):
        """Return a log ready to be written to a file: Without control characters
        """
        return re.sub(r"(?m)^.*\r(?!$)", "", log).encode('utf8').replace('\r', '')<commit_msg>Added getBuildsList function<commit_after>import json
import urllib
import re


class TravisManager:
    """Get information from Travis-CI
    """
    def __init__(self):
        self.urlBase = 'http://travis-ci.org/'
        self.repos = self.urlBase + 'repositories.json'
        self.reposByOwner = self.urlBase + 'repositories.json?owner_name={owner}'
        self.reposIndexSearch = self.urlBase + 'repositories.json?search={query}'
        self.reposShow = self.urlBase + '{owner_name}/{name}.json'
        self.builds = self.urlBase + '{owner_name}/{name}/builds.json'
        self.buildsShow = self.urlBase + '{owner_name}/{name}/builds/{id}.json'
        self.workers = self.urlBase + 'workers.json'
        self.jobs = self.urlBase + 'jobs.json'
        self.jobsShow = self.urlBase + 'jobs/{id}.json'

    def getRepos(self, _owner):
        """Return a list with the owner's repositories
        """
        return json.loads(urllib.urlopen(self.reposByOwner.format(owner = _owner)).read())


    def getBuildList(self, _owner, _repo):
        """Returns a list with all the builds for the _owner's  _repo
        """
        return json.loads(urllib.urlopen(self.builds.format(owner_name=_owner, name=_repo)).read())


    def getBuildsAndJobs(self, _owner):
        """
        Returns a list with all the owner's builds
        """
        repos = json.loads(urllib.urlopen(self.reposByOwner.format(owner=_owner)).read())
        buildsList = []
        runningList = []
        jobsList = []

        # Build the builds list
        for repo in repos:
            buildsPerRepo = json.loads(urllib.urlopen(self.builds.format(owner_name=_owner, name=repo['slug'].split('/')[-1])).read())
            for build in buildsPerRepo:
                build['repository'] = repo['slug'].split('/')[-1]
                if build['state'] == 'started':
                    runningList.append(build)
                buildsList.append(build)

        # Build running jobs list
        for r in runningList:
            jobID = json.loads(urllib.urlopen(self.buildsShow.format(owner_name=_owner, name=r['repository'], id=r['id'])).read())['matrix'][0]['id']
            job = json.loads(urllib.urlopen(self.jobsShow.format(id = jobID)).read())
            job['repository'] = r['repository']
            jobsList.append(job)

        return buildsList, jobsList

    def getRelatedJob(self, owner, repo, buildID):
        """
        Return the job releted to the build <buildID> of the owner's <owner> repo <repo>
        """
        jobID = json.loads(urllib.urlopen(self.buildsShow.format(owner_name=owner, name=repo, id=buildID)).read())['matrix'][0]['id']
        return json.loads(urllib.urlopen(self.jobsShow.format(id=jobID)).read())

    def getFormattedLog(self, log):
        """Return a log ready to be written to a file: Without control characters
        """
        return re.sub(r"(?m)^.*\r(?!$)", "", log).encode('utf8').replace('\r', '')
{'fraction_non_alphanumeric': 0.1527336860670194, 'fraction_numerical': 0.001763668430335097, 'mean_word_length': 2.701697127937337, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6358932', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1741, 'n_words': 338}