Пример #1
0
    def default(self, reponame):
        if reponame not in self.repos.sections():
            raise cherrypy.HTTPError(404)

        self._checkAccess(reponame)
        lock = self.locks[reponame]
        msg = None
        sendMail = False

        lock.acquire()
        try:
            try:
                time_start = time.time()
                time_end = None
                repo = self._updateRepo(reponame)
                try:
                    if self._build(reponame):
                        msg = "#{} Build succeeded.".format(
                            repo.head.commit.hexsha[0:6])
                        msg_class = "green"
                        time_end = time.time()
                    else:
                        msg = "#{} Build failed.".format(
                            repo.head.commit.hexsha[0:6])
                        msg_class = "red"
                except:
                    msg = "#{} Build error.".format(
                        repo.head.commit.hexsha[0:6])
                    msg_class = "red"
                    raise
            except GitCommandError as e:
                msg = "Pull error. ({})".format(str(e))
                msg_class = "red"
                sendMail = True
                raise

            if time_end != None:
                msg += " ({:.2f} s)".format(time_end - time_start)

            template = Template("templates/build.html")
            template.assignData("reponame", reponame)
            template.assignData("message", msg)
            template.assignData("msg_class", msg_class)
            template.assignData("pagetitle", "Build")
            return template.render()
        finally:
            logger = BuildLogger(self.repodir)
            logger.log(reponame, msg, sendMail)
            lock.release()
Пример #2
0
    def default(self, reponame):
        if reponame not in self.repos.sections():
            raise cherrypy.HTTPError(404)

        self._checkAccess(reponame)
        lock = self.locks[reponame]
        msg = None
        sendMail = False

        lock.acquire()
        try:
            try:
                time_start = time.time()
                time_end = None
                repo = self._updateRepo(reponame)
                try:
                    if self._build(reponame):
                        msg = """#%s Build succeeded.""" % repo.head.commit.hexsha[0:6]
                        msg_class = "green"
                        time_end = time.time()
                    else:
                        msg = """#%s Build failed.""" % repo.head.commit.hexsha[0:6]
                        msg_class = "red"
                except:
                    msg = """#%s Build error.""" % repo.head.commit.hexsha[0:6]
                    msg_class = "red"
                    raise
            except GitCommandError as e:
                msg = "Pull error. (" + str(e) + ")"
                msg_class = "red"
                sendMail = True
                raise

            if time_end != None:
                msg += " ({:.2f} s)".format(time_end - time_start)

            template = Template("templates/build.html")
            template.assignData("reponame", reponame)
            template.assignData("message", msg)
            template.assignData("msg_class", msg_class)
            template.assignData("pagetitle", "Build")
            return template.render()
        finally:
            logger = BuildLogger(self.repodir)
            logger.log(reponame, msg, sendMail)
            lock.release()