def chain(self, length=-1, reverse=False, stop_ds=None): if stop_ds: # resolve all formats to the same format stop_ds = Dataset(stop_ds) chain = [] current = self while length != len(chain) and current != stop_ds: chain.append(current) if not current.previous: break current = Dataset(current.previous) if not reverse: chain.reverse() return chain
def chain(self, length=-1, reverse=False, stop_jobid=None): if stop_jobid: # resolve whatever format to the bare jobid stop_jobid = Dataset(stop_jobid) if stop_jobid: stop_jobid = stop_jobid.jobid chain = [] current = self while length != len(chain) and current.jobid != stop_jobid: chain.append(current) if not current.previous: break current = Dataset(current.previous) if not reverse: chain.reverse() return chain
def table(self): col1 = [] col2 = [] if DEPENDENCY in self and self[DEPENDENCY]: col1.append('Package') col2.append(self[DEPENDENCY]) else: col1.append('Package') col2.append(self[PACKAGE]) if INSTANTIATED in self and self[INSTANTIATED]: col1.append('Already Instantiated') col2.append("") if SUPER_CHAIN in self and self[SUPER_CHAIN]: col1.append('Inheritance chain') chain = [':api:`gma.%s`' % s[NAME] for s in self[SUPER_CHAIN]] chain.reverse() col2.append(' >> '.join(chain)) if CHILDREN in self and self[CHILDREN]: col1.append('Descendants') col2.append(self.getDescendants()) if col1 and col2: length1 = max(len(n)+2 for n in col1) length2 = max(len(t)+2 for t in col2) enclosing = '%s %s' % ('=' * length1, '=' * length2) table = [enclosing] for n, t in zip(col1, col2): eachLine = '%s%s %s' firstSpace = ' ' * (length1 - len(n)) table.append(eachLine % (n, firstSpace, t)) table.append(enclosing) return '\n'.join(table) return ""
def table(self): col1 = [] col2 = [] if DEPENDENCY in self and self[DEPENDENCY]: col1.append('Package') col2.append(self[DEPENDENCY]) else: col1.append('Package') col2.append(self[PACKAGE]) if INSTANTIATED in self and self[INSTANTIATED]: col1.append('Already Instantiated') col2.append("") if SUPER_CHAIN in self and self[SUPER_CHAIN]: col1.append('Inheritance chain') chain = [':api:`gma.%s`' % s[NAME] for s in self[SUPER_CHAIN]] chain.reverse() col2.append(' >> '.join(chain)) if CHILDREN in self and self[CHILDREN]: col1.append('Descendants') col2.append(self.getDescendants()) if col1 and col2: length1 = max(len(n) + 2 for n in col1) length2 = max(len(t) + 2 for t in col2) enclosing = '%s %s' % ('=' * length1, '=' * length2) table = [enclosing] for n, t in zip(col1, col2): eachLine = '%s%s %s' firstSpace = ' ' * (length1 - len(n)) table.append(eachLine % (n, firstSpace, t)) table.append(enclosing) return '\n'.join(table) return ""
def get_path_from_parent(self, parent): """ Return a list of PathInfos containing the path from the parent model to the current model, or an empty list if parent is not a parent of the current model. """ if self.model is parent: return [] model = self.concrete_model # Get a reversed base chain including both the current and parent # models. chain = model._meta.get_base_chain(parent) chain.reverse() chain.append(model) # Construct a list of the PathInfos between models in chain. path = [] for i, ancestor in enumerate(chain[:-1]): child = chain[i + 1] link = child._meta.get_ancestor_link(ancestor) path.extend(link.get_reverse_path_info()) return path