def format(self, args): # Format each package inside each result set packages = [] for results in XML.getChildElements(XML.dig(args.message.xml, "message", "body", "builder")): if results.nodeName == 'results': for package in XML.getChildElements(results): if package.nodeName == 'package': packages.append(self.format_package(package)) return self.joinMessage(args.message, packages)
def component_files(self, element, args): """Format the contents of our <files> tag as a tree with nested lists""" from LibCIA.Web import Template files = XML.dig(args.message.xml, "message", "body", "commit", "files") if not (files and XML.hasChildElements(files)): return [] # First we organize the files into a tree of nested dictionaries. # The dictionary we ultimately have FileTree render maps each node # (file or directory) to a dictionary of its contents. The keys # in these dictionaries can be any Nouvelle-renderable object # produced by format_file. # # As a first step, we build a dictionary mapping path segment to # [fileTag, children] lists. We then create a visual representation # of each fileTag and generate the final dictionary. fileTree = {} for fileTag in XML.getChildElements(files): if fileTag.nodeName == 'file': # Separate the file into path segments and walk into our tree node = [None, fileTree] for segment in XML.shallowText(fileTag).split('/'): if segment: node = node[1].setdefault(segment, [None, {}]) # The leaf node owns this fileTag node[0] = fileTag return [Template.FileTree(self.format_file_tree(fileTree))]
def consolidateFiles(self, xmlFiles): """Given a <files> element, find the directory common to all files and return a 2-tuple with that directory followed by a list of files within that directory. """ files = [] if xmlFiles: for fileTag in XML.getChildElements(xmlFiles): if fileTag.nodeName == 'file': files.append(XML.shallowText(fileTag)) # If we only have one file, return it as the prefix. # This prevents the below regex from deleting the filename # itself, assuming it was a partial filename. if len(files) == 1: return files[0], [] # Start with the prefix found by commonprefix, # then actually make it end with a directory rather than # possibly ending with part of a filename. prefix = re.sub("[^/]*$", "", posixpath.commonprefix(files)) endings = [] for file in files: ending = file[len(prefix):].strip() if ending == '': ending = '.' endings.append(ending) return prefix, endings
def format_results(self, package): """Given a package, returns a formatted representation of all results for that package""" results = [] for element in XML.getChildElements(package): f = getattr(self, 'result_' + element.nodeName, None) if f: results.append(f(element))
def getSvnRevision(self): """Return the current Subversion repository revision, or None if we're not in an svn working copy or it can't be parsed. """ try: entries = XML.parseString(open(".svn/entries").read()).documentElement highestRev = 0 for tag in XML.getChildElements(entries): if tag.nodeName == 'entry': rev = tag.getAttributeNS(None, 'committed-rev') if rev and rev > highestRev: highestRev = rev return highestRev except: return None