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 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 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(self, args): if not args.input: return project = XML.dig(args.message.xml, "message", "source", "project") if project: from LibCIA.IRC.Formatting import format prefix = format("%s:" % XML.shallowText(project), 'bold') + " " return "\n".join([prefix + line for line in args.input.split("\n")]) else: return args.input
def format(self, args): if not args.input: return project = XML.dig(args.message.xml, "message", "source", "project") if project: from LibCIA.IRC.Formatting import format prefix = format("%s:" % XML.shallowText(project), 'bold') + " " return "\n".join( [prefix + line for line in args.input.split("\n")]) else: return args.input
def getNormalizedLog(xml, tabWidth=8): """Given the DOM node for a <log> tag, return a list of text lines with whitespace normalized appropriately. This strips all whitespace from the right side, and homogeneously strips whitespace from the left side as much as possible. Leading and trailing blank lines are removed, but internal blank lines are not. """ if not xml: return [] lines = [] maxLeftStrip = None for line in XML.shallowText(xml).split("\n"): # Expand tabs and strip righthand whitespace line = line.replace("\t", " "*tabWidth).rstrip() strippedLine = line.lstrip() # Blank lines don't count in determining the left strip amount if strippedLine: # Determine how much we can strip from the left side leftStrip = len(line) - len(strippedLine) # Determine the maximum amount of space we can strip # from the left side homogeneously across the whole text if maxLeftStrip is None or leftStrip < maxLeftStrip: maxLeftStrip = leftStrip # Skip leading blank lines if lines or strippedLine: lines.append(line) # Remove trailing blank lines while lines and not lines[-1].strip(): del lines[-1] # Homogeneous left strip if maxLeftStrip is None: return lines else: return [line[maxLeftStrip:] for line in lines]
def getNormalizedLog(xml, tabWidth=8): """Given the DOM node for a <log> tag, return a list of text lines with whitespace normalized appropriately. This strips all whitespace from the right side, and homogeneously strips whitespace from the left side as much as possible. Leading and trailing blank lines are removed, but internal blank lines are not. """ if not xml: return [] lines = [] maxLeftStrip = None for line in XML.shallowText(xml).split("\n"): # Expand tabs and strip righthand whitespace line = line.replace("\t", " " * tabWidth).rstrip() strippedLine = line.lstrip() # Blank lines don't count in determining the left strip amount if strippedLine: # Determine how much we can strip from the left side leftStrip = len(line) - len(strippedLine) # Determine the maximum amount of space we can strip # from the left side homogeneously across the whole text if maxLeftStrip is None or leftStrip < maxLeftStrip: maxLeftStrip = leftStrip # Skip leading blank lines if lines or strippedLine: lines.append(line) # Remove trailing blank lines while lines and not lines[-1].strip(): del lines[-1] # Homogeneous left strip if maxLeftStrip is None: return lines else: return [line[maxLeftStrip:] for line in lines]
class Message: serializer = Serializer() formatter_factory = OldFormatters.getFactory() def __init__(self, (id, xml)): self.id = id self.hex_id = "%x" % id self.oldmsg = OldMessage(xml) self.timestamp = datetime.datetime.fromtimestamp( XML.digValue(self.oldmsg.xml, float, "message", "timestamp")) self.formatter = self.formatter_factory.findMedium( 'xhtml', self.oldmsg) self.is_commit = isinstance(self.formatter, CommitFormatter) if self.is_commit: for shortcut, path in XML.pathShortcuts.items(): doc = XML.XPath(path).queryObject(self.oldmsg) if doc: setattr(self, shortcut, XML.shallowText(doc[0]))
def component_headers(self, element, args): """Format all relevant commit metadata in an email-style header box""" from LibCIA.Web import Template message = args.message commit = XML.dig(message.xml, "message", "body", "commit") source = XML.dig(message.xml, "message", "source") author = XML.dig(commit, "author") version = XML.dig(commit, "version") revision = XML.dig(commit, "revision") diffLines = XML.dig(commit, "diffLines") url = XML.dig(commit, "url") log = XML.dig(commit, "log") project = XML.dig(source, "project") module = XML.dig(source, "module") branch = XML.dig(source, "branch") headers = OrderedDict() if author: headers['Author'] = XML.shallowText(author) if project: headers['Project'] = XML.shallowText(project) if module: headers['Module'] = XML.shallowText(module) if branch: headers['Branch'] = XML.shallowText(branch) if version: headers['Version'] = XML.shallowText(version) if revision: headers['Revision'] = XML.shallowText(revision) if diffLines: headers['Changed Lines'] = XML.shallowText(diffLines) if url: headers['URL'] = tag( 'a', href=XML.shallowText(url))[Util.extractSummary(url)] return [Template.MessageHeaders(headers)]
def component_headers(self, element, args): """Format all relevant commit metadata in an email-style header box""" from LibCIA.Web import Template message = args.message commit = XML.dig(message.xml, "message", "body", "commit") source = XML.dig(message.xml, "message", "source") author = XML.dig(commit, "author") version = XML.dig(commit, "version") revision = XML.dig(commit, "revision") diffLines = XML.dig(commit, "diffLines") url = XML.dig(commit, "url") log = XML.dig(commit, "log") project = XML.dig(source, "project") module = XML.dig(source, "module") branch = XML.dig(source, "branch") headers = OrderedDict() if author: headers['Author'] = XML.shallowText(author) if project: headers['Project'] = XML.shallowText(project) if module: headers['Module'] = XML.shallowText(module) if branch: headers['Branch'] = XML.shallowText(branch) if version: headers['Version'] = XML.shallowText(version) if revision: headers['Revision'] = XML.shallowText(revision) if diffLines: headers['Changed Lines'] = XML.shallowText(diffLines) if url: headers['URL'] = tag('a', href=XML.shallowText(url))[ Util.extractSummary(url) ] return [Template.MessageHeaders(headers)]
def getCrunchedLog(xml): """Given the DOM node for a <log> tag, return the log as a string with all groups of one or more whitespace characters replaced with a single space. """ return re.sub("\s+", " ", XML.shallowText(xml)).strip()
def loadParametersFrom(self, xml): self.formattingCode = XML.shallowText(xml).strip()
def param_wrapWidth(self, tag): self.wrapWidth = int(XML.shallowText(tag))
def param_filesWidthLimit(self, tag): self.filesWidthLimit = int(XML.shallowText(tag))
def param_wrapWidth(self, tag): self.wrapWidth = int(XML.shallowText(tag))
def param_widthLimit(self, tag): self.widthLimit = int(XML.shallowText(tag)) if self.wrapWidth > self.widthLimit: self.wrapWidth = self.widthLimit
def param_lineLimit(self, tag): self.lineLimit = int(XML.shallowText(tag))
def param_widthLimit(self, tag): self.widthLimit = int(XML.shallowText(tag)) if self.wrapWidth > self.widthLimit: self.wrapWidth = self.widthLimit
def getValue(self, message): project = XML.dig(message.xml, "message", "source", "project") if project: return XML.shallowText(project)
def loadParametersFrom(self, xml): self.formattingCode = XML.shallowText(xml).strip()
def format_timestamp(self, stamp): return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
def param_filesWidthLimit(self, tag): self.filesWidthLimit = int(XML.shallowText(tag))
def getCrunchedLog(xml): """Given the DOM node for a <log> tag, return the log as a string with all groups of one or more whitespace characters replaced with a single space. """ return re.sub("\s+", " ", XML.shallowText(xml)).strip()
def getValue(self, message): project = XML.dig(message.xml, "message", "source", "project") if project: return XML.shallowText(project)
def component_url(self, element, args): element = XML.dig(args.message.xml, "message", "body", "commit", "url") if element: return [tag('a', href=XML.shallowText(element))[ 'link' ]] else: return [Message.MarkAsHidden()]
def param_lineLimit(self, tag): self.lineLimit = int(XML.shallowText(tag))
def format_timestamp(self, stamp): return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
def component_url(self, element, args): element = XML.dig(args.message.xml, "message", "body", "commit", "url") if element: return [tag('a', href=XML.shallowText(element))['link']] else: return [Message.MarkAsHidden()]