Пример #1
0
    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
Пример #2
0
    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))]
Пример #3
0
    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))]
Пример #4
0
    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
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
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]
Пример #8
0
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]
Пример #9
0
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]))
Пример #10
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)]
Пример #11
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)]
Пример #12
0
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()
Пример #13
0
 def loadParametersFrom(self, xml):
     self.formattingCode = XML.shallowText(xml).strip()
Пример #14
0
 def param_wrapWidth(self, tag):
     self.wrapWidth = int(XML.shallowText(tag))
Пример #15
0
 def param_filesWidthLimit(self, tag):
     self.filesWidthLimit = int(XML.shallowText(tag))
Пример #16
0
 def param_wrapWidth(self, tag):
     self.wrapWidth = int(XML.shallowText(tag))
Пример #17
0
 def param_widthLimit(self, tag):
     self.widthLimit = int(XML.shallowText(tag))
     if self.wrapWidth > self.widthLimit:
         self.wrapWidth = self.widthLimit
Пример #18
0
 def param_lineLimit(self, tag):
     self.lineLimit = int(XML.shallowText(tag))
Пример #19
0
 def param_widthLimit(self, tag):
     self.widthLimit = int(XML.shallowText(tag))
     if self.wrapWidth > self.widthLimit:
         self.wrapWidth = self.widthLimit
Пример #20
0
 def getValue(self, message):
     project = XML.dig(message.xml, "message", "source", "project")
     if project:
         return XML.shallowText(project)
Пример #21
0
 def loadParametersFrom(self, xml):
     self.formattingCode = XML.shallowText(xml).strip()
Пример #22
0
 def format_timestamp(self, stamp):
     return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
Пример #23
0
 def param_filesWidthLimit(self, tag):
     self.filesWidthLimit = int(XML.shallowText(tag))
Пример #24
0
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()
Пример #25
0
 def getValue(self, message):
     project = XML.dig(message.xml, "message", "source", "project")
     if project:
         return XML.shallowText(project)
Пример #26
0
 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()]
Пример #27
0
 def param_lineLimit(self, tag):
     self.lineLimit = int(XML.shallowText(tag))
Пример #28
0
 def format_timestamp(self, stamp):
     return ["Received ", Template.value[TimeUtil.formatRelativeDate(int(XML.shallowText(stamp)))]]
Пример #29
0
 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()]