Example #1
0
    def MakeCcFile(self, process_tags, cover_fname):
        """Make a cc file for us to use for per-commit Cc automation

        Also stores in self._generated_cc to make ShowActions() faster.

        Args:
            process_tags: Process tags as if they were aliases
            cover_fname: If non-None the name of the cover letter.
        Return:
            Filename of temp file created
        """
        # Look for commit tags (of the form 'xxx:' at the start of the subject)
        fname = '/tmp/patman.%d' % os.getpid()
        fd = open(fname, 'w')
        all_ccs = []
        for commit in self.commits:
            list = []
            if process_tags:
                list += gitutil.BuildEmailList(commit.tags)
            list += gitutil.BuildEmailList(commit.cc_list)
            list += get_maintainer.GetMaintainer(commit.patch)
            all_ccs += list
            print >> fd, commit.patch, ', '.join(list)
            self._generated_cc[commit.patch] = list

        if cover_fname:
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            print >> fd, cover_fname, ', '.join(set(cover_cc + all_ccs))

        fd.close()
        return fname
Example #2
0
    def MakeCcFile(self, process_tags, cover_fname, raise_on_error,
                   add_maintainers, limit):
        """Make a cc file for us to use for per-commit Cc automation

        Also stores in self._generated_cc to make ShowActions() faster.

        Args:
            process_tags: Process tags as if they were aliases
            cover_fname: If non-None the name of the cover letter.
            raise_on_error: True to raise an error when an alias fails to match,
                False to just print a message.
            add_maintainers: Either:
                True/False to call the get_maintainers to CC maintainers
                List of maintainers to include (for testing)
            limit: Limit the length of the Cc list
        Return:
            Filename of temp file created
        """
        col = terminal.Color()
        # Look for commit tags (of the form 'xxx:' at the start of the subject)
        fname = '/tmp/patman.%d' % os.getpid()
        fd = open(fname, 'w', encoding='utf-8')
        all_ccs = []
        for commit in self.commits:
            cc = []
            if process_tags:
                cc += gitutil.BuildEmailList(commit.tags,
                                             raise_on_error=raise_on_error)
            cc += gitutil.BuildEmailList(commit.cc_list,
                                         raise_on_error=raise_on_error)
            if type(add_maintainers) == type(cc):
                cc += add_maintainers
            elif add_maintainers:
                cc += get_maintainer.GetMaintainer(commit.patch)
            for x in set(cc) & set(settings.bounces):
                print(col.Color(col.YELLOW, 'Skipping "%s"' % x))
            cc = set(cc) - set(settings.bounces)
            cc = [tools.FromUnicode(m) for m in cc]
            if limit is not None:
                cc = cc[:limit]
            all_ccs += cc
            print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
            self._generated_cc[commit.patch] = cc

        if cover_fname:
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            cover_cc = [tools.FromUnicode(m) for m in cover_cc]
            cover_cc = list(set(cover_cc + all_ccs))
            if limit is not None:
                cover_cc = cover_cc[:limit]
            cc_list = '\0'.join([tools.ToUnicode(x) for x in sorted(cover_cc)])
            print(cover_fname, cc_list, file=fd)

        fd.close()
        return fname
Example #3
0
    def ShowActions(self, args, cmd, process_tags):
        """Show what actions we will/would perform

        Args:
            args: List of patch files we created
            cmd: The git command we would have run
            process_tags: Process tags as if they were aliases
        """
        col = terminal.Color()
        print 'Dry run, so not doing much. But I would do this:'
        print
        print 'Send a total of %d patch%s with %scover letter.' % (
            len(args), '' if len(args) == 1 else 'es',
            self.get('cover') and 'a ' or 'no ')

        # TODO: Colour the patches according to whether they passed checks
        for upto in range(len(args)):
            commit = self.commits[upto]
            print col.Color(col.GREEN, '   %s' % args[upto])
            cc_list = list(self._generated_cc[commit.patch])

            # Skip items in To list
            if 'to' in self:
                try:
                    map(cc_list.remove, gitutil.BuildEmailList(self.to))
                except ValueError:
                    pass

            for email in cc_list:
                if email == None:
                    email = col.Color(col.YELLOW,
                                      "<alias '%s' not found>" % tag)
                if email:
                    print '      Cc: ', email
        print
        for item in gitutil.BuildEmailList(self.get('to', '<none>')):
            print 'To:\t ', item
        for item in gitutil.BuildEmailList(self.cc):
            print 'Cc:\t ', item
        print 'Version: ', self.get('version')
        print 'Prefix:\t ', self.get('prefix')
        if self.cover:
            print 'Cover: %d lines' % len(self.cover)
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            all_ccs = itertools.chain(cover_cc, *self._generated_cc.values())
            for email in set(all_ccs):
                print '      Cc: ', email
        if cmd:
            print 'Git command: %s' % cmd
Example #4
0
    def MakeCcFile(self, process_tags, cover_fname, raise_on_error,
                   add_maintainers):
        """Make a cc file for us to use for per-commit Cc automation

        Also stores in self._generated_cc to make ShowActions() faster.

        Args:
            process_tags: Process tags as if they were aliases
            cover_fname: If non-None the name of the cover letter.
            raise_on_error: True to raise an error when an alias fails to match,
                False to just print a message.
            add_maintainers: Either:
                True/False to call the get_maintainers to CC maintainers
                List of maintainers to include (for testing)
        Return:
            Filename of temp file created
        """
        # Look for commit tags (of the form 'xxx:' at the start of the subject)
        fname = '/tmp/patman.%d' % os.getpid()
        fd = open(fname, 'w')
        all_ccs = []
        for commit in self.commits:
            cc = []
            if process_tags:
                cc += gitutil.BuildEmailList(commit.tags,
                                             raise_on_error=raise_on_error)
            cc += gitutil.BuildEmailList(commit.cc_list,
                                         raise_on_error=raise_on_error)
            if type(add_maintainers) == type(cc):
                cc += add_maintainers
            elif add_maintainers:
                cc += get_maintainer.GetMaintainer(commit.patch)
            cc = [m.encode('utf-8') if type(m) != str else m for m in cc]
            all_ccs += cc
            print(commit.patch, ', '.join(set(cc)), file=fd)
            self._generated_cc[commit.patch] = cc

        if cover_fname:
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            cover_cc = [
                m.encode('utf-8') if type(m) != str else m for m in cover_cc
            ]
            cc_list = ', '.join(
                [x.decode('utf-8') for x in set(cover_cc + all_ccs)])
            print(cover_fname, cc_list.encode('utf-8'), file=fd)

        fd.close()
        return fname
Example #5
0
 def FormatTags(self, tags):
     out_list = []
     for tag in sorted(tags):
         if tag.startswith('Cc:'):
             tag_list = tag[4:].split(',')
             out_list += gitutil.BuildEmailList(tag_list, 'Cc:')
         else:
             out_list.append(tag)
     return out_list
Example #6
0
    def ShowActions(self, args, cmd, process_tags):
        """Show what actions we will/would perform

        Args:
            args: List of patch files we created
            cmd: The git command we would have run
            process_tags: Process tags as if they were aliases
        """
        to_set = set(gitutil.BuildEmailList(self.to))
        cc_set = set(gitutil.BuildEmailList(self.cc))

        col = terminal.Color()
        print('Dry run, so not doing much. But I would do this:')
        print()
        print('Send a total of %d patch%s with %scover letter.' %
              (len(args), '' if len(args) == 1 else 'es',
               self.get('cover') and 'a ' or 'no '))

        # TODO: Colour the patches according to whether they passed checks
        for upto in range(len(args)):
            commit = self.commits[upto]
            print(col.Color(col.GREEN, '   %s' % args[upto]))
            cc_list = list(self._generated_cc[commit.patch])
            for email in sorted(set(cc_list) - to_set - cc_set):
                if email == None:
                    email = col.Color(col.YELLOW,
                                      "<alias '%s' not found>" % tag)
                if email:
                    print('      Cc: ', email)
        print
        for item in sorted(to_set):
            print('To:\t ', item)
        for item in sorted(cc_set - to_set):
            print('Cc:\t ', item)
        print('Version: ', self.get('version'))
        print('Prefix:\t ', self.get('prefix'))
        if self.cover:
            print('Cover: %d lines' % len(self.cover))
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            all_ccs = itertools.chain(cover_cc, *self._generated_cc.values())
            for email in sorted(set(all_ccs) - to_set - cc_set):
                print('      Cc: ', email)
        if cmd:
            print('Git command: %s' % cmd)
Example #7
0
    def MakeCcFile(self, process_tags):
        """Make a cc file for us to use for per-commit Cc automation

        Args:
            process_tags: Process tags as if they were aliases
        Return:
            Filename of temp file created
        """
        # Look for commit tags (of the form 'xxx:' at the start of the subject)
        fname = '/tmp/patman.%d' % os.getpid()
        fd = open(fname, 'w')
        for commit in self.commits:
            list = []
            if process_tags:
                list += gitutil.BuildEmailList(commit.tags)
            list += gitutil.BuildEmailList(commit.cc_list)
            print >> fd, commit.patch, ', '.join(list)

        fd.close()
        return fname
Example #8
0
    def ShowActions(self, args, cmd, process_tags):
        """Show what actions we will/would perform

        Args:
            args: List of patch files we created
            cmd: The git command we would have run
            process_tags: Process tags as if they were aliases
        """
        col = terminal.Color()
        print 'Dry run, so not doing much. But I would do this:'
        print
        print 'Send a total of %d patch%s with %scover letter.' % (
            len(args), '' if len(args) == 1 else 'es',
            self.get('cover') and 'a ' or 'no ')

        # TODO: Colour the patches according to whether they passed checks
        for upto in range(len(args)):
            commit = self.commits[upto]
            print col.Color(col.GREEN, '   %s' % args[upto])
            cc_list = []
            if process_tags:
                cc_list += gitutil.BuildEmailList(commit.tags)
            cc_list += gitutil.BuildEmailList(commit.cc_list)

            for email in cc_list:
                if email == None:
                    email = col.Color(col.YELLOW,
                                      "<alias '%s' not found>" % tag)
                if email:
                    print '      Cc: ', email
        print
        for item in gitutil.BuildEmailList(self.get('to', '<none>')):
            print 'To:\t ', item
        for item in gitutil.BuildEmailList(self.cc):
            print 'Cc:\t ', item
        print 'Version: ', self.get('version')
        print 'Prefix:\t ', self.get('prefix')
        if self.cover:
            print 'Cover: %d lines' % len(self.cover)
        if cmd:
            print 'Git command: %s' % cmd
Example #9
0
    def MakeCcFile(self, process_tags, cover_fname, raise_on_error,
                   add_maintainers):
        """Make a cc file for us to use for per-commit Cc automation

        Also stores in self._generated_cc to make ShowActions() faster.

        Args:
            process_tags: Process tags as if they were aliases
            cover_fname: If non-None the name of the cover letter.
            raise_on_error: True to raise an error when an alias fails to match,
                False to just print a message.
            add_maintainers: Call the get_maintainers to CC maintainers
        Return:
            Filename of temp file created
        """
        # Look for commit tags (of the form 'xxx:' at the start of the subject)
        fname = '/tmp/patman.%d' % os.getpid()
        fd = open(fname, 'w')
        all_ccs = []
        for commit in self.commits:
            list = []
            if process_tags:
                list += gitutil.BuildEmailList(commit.tags,
                                               raise_on_error=raise_on_error)
            list += gitutil.BuildEmailList(commit.cc_list,
                                           raise_on_error=raise_on_error)
            if add_maintainers:
                list += get_maintainer.GetMaintainer(commit.patch)
            all_ccs += list
            print(commit.patch, ', '.join(set(list)), file=fd)
            self._generated_cc[commit.patch] = list

        if cover_fname:
            cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
            print(cover_fname, ', '.join(set(cover_cc + all_ccs)), file=fd)

        fd.close()
        return fname