def for_bug(cls, git_gecko, git_wpt, bug, statuses=None, flat=False): """Get the syncs for a specific bug. :param bug: The bug number for which to find syncs. :param statuses: An optional list of sync statuses to include. Defaults to all statuses. :param flat: Return a flat list of syncs instead of a dictionary. :returns: By default a dictionary of {status: [syncs]}, but if flat is true, just returns a list of matching syncs. """ import index bug = str(bug) statuses = set(statuses) if statuses is not None else set(cls.statuses) rv = defaultdict(set) idx_key = (bug, ) if len(statuses) == 1: idx_key == (bug, list(statuses)[0]) idx = index.BugIdIndex(git_gecko) process_names = idx.get(idx_key) for process_name in process_names: if process_name.subtype == cls.sync_type: sync = cls(git_gecko, git_wpt, process_name) if sync.status in statuses: rv[sync.status].add(sync) if flat: rv = list(itertools.chain.from_iterable(rv.itervalues())) return rv
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 bug(self, value): import index if self.obj_id == "bug": raise AttributeError("Can't set attribute") old_key = None if self.data.get("bug"): old_key = index.BugIdIndex.make_key(self) self.data["bug"] = value new_key = index.BugIdIndex.make_key(self) index.BugIdIndex(self.git_gecko).move(old_key, new_key, self.process_name)
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)