Rev 61: Merge trunk in file:///home/jelmer/bzr-submit/nowrap/

Jelmer Vernooij jelmer at samba.org
Mon Apr 9 16:32:06 BST 2007


At file:///home/jelmer/bzr-submit/nowrap/

------------------------------------------------------------
revno: 61
revision-id: jelmer at samba.org-20070409153200-g8d83fg53tnbbfbr
parent: jelmer at samba.org-20070407222819-v7bt7jt65djqqgzm
parent: jelmer at samba.org-20070407224628-xk7amkuat6y08vgk
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: nowrap
timestamp: Mon 2007-04-09 17:32:00 +0200
message:
  Merge trunk
modified:
  __init__.py                    __init__.py-20060624164558-9aabyghnw7kxeuwg-1
  submit_helpers.py              submit_helpers.py-20060624164558-9aabyghnw7kxeuwg-2
  test_submit_bundle.py          test_submit_bundle.p-20070128205938-j61ty7zc1fxv9dba-1
    ------------------------------------------------------------
    revno: 59.1.3
    merged: jelmer at samba.org-20070407224628-xk7amkuat6y08vgk
    parent: jelmer at samba.org-20070407213035-t8bhc7o6upbvg4jq
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sun 2007-04-08 00:46:28 +0200
    message:
      Refactor get_subject(), add test.
    ------------------------------------------------------------
    revno: 59.1.2
    merged: jelmer at samba.org-20070407213035-t8bhc7o6upbvg4jq
    parent: jelmer at samba.org-20070407204219-j7xvun90ui91wvnz
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sat 2007-04-07 23:30:35 +0200
    message:
      Add tests for BranchConfigSubmitBundle.
    ------------------------------------------------------------
    revno: 59.1.1
    merged: jelmer at samba.org-20070407204219-j7xvun90ui91wvnz
    parent: jelmer at samba.org-20070407024347-mbwdcaml32dyv3kg
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: trunk
    timestamp: Sat 2007-04-07 22:42:19 +0200
    message:
      Add some tests for the .submit-options parser.
=== modified file '__init__.py'
--- a/__init__.py	2007-04-07 22:28:19 +0000
+++ b/__init__.py	2007-04-09 15:32:00 +0000
@@ -84,6 +84,80 @@
 
 submit_options = ['submit-address', 'submit-maintainer', 'submit-mailinglist']
 
+def parse_submit_options(text):
+    """Parse a .submit-options file."""
+    import re
+    option_re = re.compile(r'^([^#]\S+)\s*=\s*(\S+)$')
+    for line in text.splitlines():
+        result = option_re.match(line)
+        if result is None:
+            # Skip all lines that don't have the format
+            # name = value
+            # or that start with #
+            continue 
+            
+        yield result.groups()
+
+def read_options(branch):
+    _copy_options(branch, branch, False)
+
+def _copy_options(branch_from, branch_to, overwrite = False):
+    """Copy options from one branch to another"""
+    
+    from bzrlib import config
+    
+    from submit_helpers import store_config_in_branch
+    
+    config_from = config.BranchConfig(branch_from)
+    config_to   = config.BranchConfig(branch_to)
+    
+    conflict_list = []
+    
+    # First check if there is an versioned file '.submit-options'
+    try:
+        revision_id = branch_from.last_revision()
+        rep = branch_from.repository
+        tree = rep.revision_tree(revision_id)
+        file_id = tree.inventory.path2id('.submit-options')
+        if file_id:
+            for option, option_from in parse_submit_options(tree.get_file_text(file_id)):
+                option_to = config_to.get_user_option(option)
+                if option_to is None:
+                    store_config_in_branch(config_to, option, option_from)
+                elif option_to != option_from:
+                    conflict_list.append((option, option_from, option_to))
+                    if overwrite:
+                        store_config_in_branch(config_to, option, option_from)
+    except Exception, e:
+        print "Could not read file '.submit-options':", str(e) 
+        # No matter which error occurs here the command should not fail
+
+    for option in submit_options:
+        option_from = config_from.get_user_option(option)
+        option_to   = config_to.get_user_option(option)
+        if option_from is None:
+            continue
+        
+        if option_to is None:
+            store_config_in_branch(config_to, option, option_from)
+        elif option_to != option_from:
+            conflict_list.append((option, option_from, option_to))
+            if overwrite:
+                store_config_in_branch(config_to, option, option_from)
+                
+    if len(conflict_list)>0:
+        if overwrite:
+            trace.warning("There were conflicts in the submit "+
+                "options. Old values were overwriten.")
+        else:
+            trace.warning("There were conflicts in the submit "+
+                "options. Old values were kept.")
+        format_str = "%25s|%35s|%35s"
+        trace.warning(format_str % ("Name", "Old value", "New value"))
+        for conflict in conflict_list:
+            trace.warning(format_str % conflict)
+
+            
 class cmd_info(builtins.cmd_info):
 
     __doc__ = builtins.cmd_info.__doc__
@@ -122,5 +196,7 @@
     from bzrlib.tests import TestSuite, TestLoader
     import test_submit_bundle
 
+    suite = TestSuite()
     loader = TestLoader()
-    return loader.loadTestsFromModule(loader)
+    suite.addTests(loader.loadTestsFromModule(test_submit_bundle))
+    return suite

=== modified file 'submit_helpers.py'
--- a/submit_helpers.py	2007-04-07 22:28:19 +0000
+++ b/submit_helpers.py	2007-04-09 15:32:00 +0000
@@ -119,11 +119,11 @@
         
         multipart = True
         pqm = False
-        if mail_to[:8] == "mailbot:":
+        if mail_to.startswith("mailbot:"):
             pqm = True
             multipart = False
             mail_to = mail_to[8:]
-        elif mail_to[:7] == "mailto:":
+        elif mail_to.startswith("mailto:"):
             mail_to = mail_to[7:]
         return (mail_to, multipart, pqm)
 
@@ -178,14 +178,10 @@
     except (smtplib.SMTPException, socket.gaierror), e:
         raise BzrCommandError("SMTP-Error: " + str(e))
         
-def get_subject(branch, subject):
+def get_subject(branch):
     """ Format a nice subject. """
-    if subject is None:
-        rev = branch.repository.get_revision(branch.last_revision())
-        subject = '[PATCH] ' + rev.message.replace('\n', ' ') 
-    if subject[-1:] == "\n": 
-        subject = subject[:-1]
-    return subject
+    rev = branch.repository.get_revision(branch.last_revision())
+    return '[PATCH] ' + rev.message.replace('\n', ' ') 
     
 def get_bundle_text(base, revision, remember):
     """Handle tempfile etc. during bundle creation"""
@@ -332,8 +328,11 @@
             warning("WARNING: Could not sign the message. " + \
                 "This means your identity can't be verified by the " + \
                 "recipient. Error message: " + str(e))
-   
-    msg = create_mime_message(get_subject(branch, subject), mail_from,
+    
+    if subject is None:
+        subject = get_subject(branch)
+    
+    msg = create_mime_message(subject.strip("\n"), mail_from,
         mail_to, message_text, bundle_text, multipart)
     
     if dry_run: 

=== modified file 'test_submit_bundle.py'
--- a/test_submit_bundle.py	2007-01-28 21:00:03 +0000
+++ b/test_submit_bundle.py	2007-04-07 22:46:28 +0000
@@ -15,4 +15,118 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Test cases for pqm submit."""
 
-from bzrlib.tests import TestCase
+from bzrlib.bzrdir import BzrDir
+from bzrlib.errors import BzrCommandError
+from bzrlib.tests import TestCase, TestCaseInTempDir
+from bzrlib.tests.test_config import FakeBranch
+from bzrlib.workingtree import WorkingTree
+
+from bzrlib.plugins.submit import parse_submit_options
+from bzrlib.plugins.submit.submit_helpers import (BranchConfigSubmitBundle, 
+                                                  get_subject)
+
+class TestParseSubmitOptions(TestCase):
+    def test_simple(self):
+        """Make sure a single option can be parsed correctly."""
+        self.assertEquals([("bla", "bloe")], 
+                list(parse_submit_options("bla=bloe\n")))
+
+    def test_with_comment(self):
+        """Make sure comments are ignored."""
+        self.assertEquals([("bla", "bloe")], 
+                list(parse_submit_options("#comment\nbla=bloe\n")))
+
+    def test_multiple(self):
+        """Test that multiple options can be parsed."""
+        self.assertEquals([("bla", "bloe"), ("var1", "val1"), ("var2", "val2")], 
+            list(parse_submit_options("bla=bloe\nvar1=val1\nvar2=val2\n")))
+
+ 
+class TestConfig(TestCase):
+    def setUp(self):
+        self.config = BranchConfigSubmitBundle(FakeBranch())
+
+    def test_get_submit_address(self):
+        """Check whether the default submit address can be obtained."""
+        self.config.set_user_option('submit-address', 'foo at bar.nl')
+        self.assertEquals("foo at bar.nl", self.config.get_submit_address())
+
+    def test_get_submit_address_default(self):
+        """Check whether None is returned if no address is set."""
+        self.assertIs(None, self.config.get_submit_address())
+
+    def test_set_submit_address(self):
+        """Check whether the default submit address can be obtained."""
+        self.config.set_submit_address('some-address at example.com')
+        self.assertEquals("some-address at example.com", self.config.get_user_option("submit-address"))
+
+    def test_get_smtp_server(self):
+        """Check whether the SMTP server can be obtained from the config file."""
+        self.config.set_user_option("smtp_server", "smtp.example.com")
+        self.assertEquals("smtp.example.com", self.config.get_smtp_server())
+
+    def test_get_smtp_server_default(self):
+        """Make sure that get_smtp_server() defaults to localhost."""
+        self.assertEquals("localhost", self.config.get_smtp_server())
+
+    def test_get_smtp_user(self):
+        """Make sure that the SMTP user can be obtain from the config."""
+        self.config.set_user_option("smtp_user", "somebody")
+        self.assertEquals("somebody", self.config.get_smtp_user())
+
+    def test_get_smtp_user_default(self):
+        """Make sure that get_smtp_user() defaults to None."""
+        self.assertIs(None, self.config.get_smtp_user())
+
+    def test_get_smtp_password(self):
+        """Make sure the smtp password can be obtained correctly."""
+        self.config.set_user_option("smtp_password", "geheim")
+        self.assertEquals("geheim", self.config.get_smtp_password())
+
+    def test_get_smtp_password_default(self):
+        """Make sure the default smtp password is None."""
+        self.assertIs(None, self.config.get_smtp_password())
+
+    def test_get_mailto_no_address(self):
+        """Make sure a BzrCommandError is raised if there is no address set."""
+        self.assertRaises(BzrCommandError, 
+                lambda: self.config.get_mailto(None, None, False, False))
+
+    def test_get_mailto_remember(self):
+        """Make sure remember works."""
+        self.assertEquals(("foo at example.com", True, False),
+            self.config.get_mailto("foo at example.com", "default", True, False))
+        self.assertEquals("foo at example.com", self.config.get_submit_address("default"))
+
+    def test_get_mailto_noremember(self):
+        """Make sure remember=False doesn't store anything."""
+        self.assertEquals(("foo at example.com", True, False),
+            self.config.get_mailto("foo at example.com", "default", False, False))
+        self.assertIs(None, self.config.get_submit_address("default"))
+
+    def test_get_mailto_nopredefined(self):
+        """Make sure get_mailto() without predefined address uses 
+        get_submit_address."""
+        self.config.set_user_option("submit-address", "bar at example.com")
+        self.assertEquals(("bar at example.com", True, False),
+            self.config.get_mailto(None, "default", False, False))
+
+    def test_get_mailto_nopredefined(self):
+        """Make sure get_mailto() strips mailto: prefixes."""
+        self.assertEquals(("bar at example.com", True, False),
+            self.config.get_mailto("mailto:bar at example.com", "default", False, 
+                False))
+
+    def test_get_mailto_mailbot(self):
+        """Make sure get_mailto() strips mailbot: prefixes and 
+        returns the pqm setting correctly. """
+        self.assertEquals(("bar at example.com", False, True),
+            self.config.get_mailto("mailbot:bar at example.com", "default", False, 
+                False))
+
+class TestGetSubject(TestCaseInTempDir):
+    def test_get_subject(self):
+        branch = BzrDir.create_branch_convenience(self.test_dir)
+        wt = WorkingTree.open(branch.base)
+        wt.commit("The message")
+        self.assertEquals("[PATCH] The message", get_subject(branch))




More information about the bazaar-commits mailing list