Esempio n. 1
0
class DocBuilder(object):

    def __init__(self, project, builder_name):
        self.project = project
        self.option = get_project_doc_option(project, builder_name)
        self.builder = ArminBuilder(self.option)
        self.builder_name = builder_name

    @property
    def queue_member(self):
        return "%s:%s" % (self.project.id, self.builder_name)

    @property
    def can_build(self):
        # Has the code_config.yaml
        conf = CodeConf(self.project)
        if conf.exists:
            return True

    @property
    def up_to_date(self):
        # Already builds the source
        last_commit_hash = mc.get(PROJECT_BUILD_HASH_MC_KEY % (
            self.project.id, self.builder_name))
        if not last_commit_hash:
            return False
        repo = self.project.repo
        commit_len = len(repo.get_commits(
            self.builder.commit_hex, last_commit_hash))
        if not commit_len:
            return True
        last_tree_hash = mc.get(PROJECT_BUILD_TREE_HASH_MC_KEY % (
            self.project.id, self.builder_name))
        if not last_tree_hash:
            return False
        if last_tree_hash == self.builder.tree_hex:
            return True
        return False

    @property
    def in_queue(self):
        # Already waits for building
        if rds.sismember(PROJECT_BUILD_QUEUE_RDS_KEY,
                         self.queue_member):
            return True

    def enqueue(self):
        rds.sadd(PROJECT_BUILD_QUEUE_RDS_KEY, self.queue_member)

    def dequeue(self):
        rds.srem(PROJECT_BUILD_QUEUE_RDS_KEY, self.queue_member)

    def build(self):
        project = self.project
        builder_name = self.builder_name
        self.builder.option = get_doc_builder_option(project, builder_name)
        self.option = self.builder.option
        self.builder.build()
Esempio n. 2
0
 def __init__(self, project, builder_name):
     self.project = project
     self.option = get_project_doc_option(project, builder_name)
     self.builder = ArminBuilder(self.option)
     self.builder_name = builder_name