def new(cls, lock, git_gecko, git_wpt, gecko_base, gecko_head, wpt_base="origin/master", wpt_head=None, bug=None, pr=None, status="open"): # TODO: this object creation is extremely non-atomic :/ import index if cls.obj_id == "bug": assert bug is not None obj_id = bug elif cls.obj_id == "pr": assert pr is not None obj_id = pr else: raise ValueError("Invalid cls.obj_id: %s" % cls.obj_id) if wpt_head is None: wpt_head = wpt_base data = { "gecko-base": gecko_base, "wpt-base": wpt_base, "pr": pr, "bug": bug, "status": status } # This is pretty ugly process_name = ProcessName.with_seq_id(git_gecko, cls.obj_type, cls.sync_type, obj_id) if not cls.multiple_syncs and process_name.seq_id != 0: raise ValueError( "Tried to create new %s sync for %s %s but one already exists" % (cls.obj_id, cls.sync_type, obj_id)) SyncData.create(lock, git_gecko, process_name, data) BranchRefObject.create(lock, git_gecko, process_name, gecko_head, sync_commit.GeckoCommit) BranchRefObject.create(lock, git_wpt, process_name, wpt_head, sync_commit.WptCommit) rv = cls(git_gecko, git_wpt, process_name) idx = index.SyncIndex(git_gecko) idx.insert(idx.make_key(rv), process_name).save() if cls.obj_id == "bug": bug_idx = index.BugIdIndex(git_gecko) bug_idx.insert(bug_idx.make_key(rv), process_name).save() elif cls.obj_id == "pr": pr_idx = index.PrIdIndex(git_gecko) pr_idx.insert(pr_idx.make_key(rv), process_name).save() return rv
def load_by_status(cls, git_gecko, git_wpt, status): import index idx = index.SyncIndex(git_gecko) key = (cls.obj_type, cls.sync_type, status) process_names = idx.get(key) rv = set() for process_name in process_names: rv.add(cls(git_gecko, git_wpt, process_name)) return rv
def load_by_status(cls, repo, subtype, status): import index process_names = index.SyncIndex(repo).get((cls.obj_type, subtype, status)) rv = set() for process_name in process_names: rv.add(cls(repo, process_name)) return rv
def status(self, value): if value not in self.statuses: raise ValueError("Unrecognised status %s" % value) current = self.status if current == value: return if (current, value) not in self.status_transitions: raise ValueError("Tried to change status from %s to %s" % (current, value)) import index index.SyncIndex(self.git_gecko).delete(index.SyncIndex.make_key(self), self.process_name) index.BugIdIndex(self.git_gecko).delete( index.BugIdIndex.make_key(self), self.process_name) self.data["status"] = value index.SyncIndex(self.git_gecko).insert(index.SyncIndex.make_key(self), self.process_name) index.BugIdIndex(self.git_gecko).insert( index.BugIdIndex.make_key(self), self.process_name)