monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone: 8682990661a2e7bb60fb7082f1


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone: 8682990661a2e7bb60fb7082f1e48e6a86a5a111
Date: Fri, 18 Feb 2011 20:54:36 +0100 (CET)

revision:            8682990661a2e7bb60fb7082f1e48e6a86a5a111
date:                2011-02-15T05:15:46
author:              Richard Levitte <address@hidden>
branch:              net.venge.monotone
changelog:
* contrib/monotone-mail-notify.lua: Moved ...
* extra/mtn-hooks/monotone-mail-notify.lua: ... here.  Make it possible
  for the user to specify a base different from the default
  (/var/spool/monotone).  Also, expect the script that does the work
  (monotone-mail-notify) to have execution bits and to take the base as
  parameter.
* contrib/monotone-mail-notify.sh: Moved ...
* extra/mtn-hooks/monotone-mail-notify: ... here.  Expect a base
  directory as first parameter, and expect mtn, source-highlight and
  mime-construct to be on $PATH.

* test/extra/mail-notify/__driver__.lua: New test script for
  monotone-mail-notify.lua et al.  It uses a number of other files as
  well, see the rest of this log.
* test/extra/mail-notify/scripts/mime-construct: New script.  This is a
  hack that makes sure mime-construct outputs the final result to file
  instead of trying to send an actual email.
* test/extra/mail-notify/scripts/mime-construct-extract: New script.
  Extracts the important bits from the output of mime-construct.  Used to
  get comparable results.
* test/extra/mail-notify/scripts/run-mail-notify: New script that will be
  called from monotone-mail-notify.lua in the test configuration.  What
  it does is set up the path to the mime-construct hack and the needed
  environment variables, then call monotone-mail-notify.
* test/extra/mail-notify/hooks.d/authorize_mail_notify_commands.lua: New
  monotone hook for this test.  It's a very short version of
  get_remote_automate_permitted that permits the exact automate remote
  commands that monotone-mail-notify uses.
* test/extra/mail-notify/mime-construct.expected: New file.  These is
  what we expect when mime-construct-extract has processed the result
  from monotona-mail-notify.


manifest:
format_version "1"

new_manifest [c13317ad5d28b67f087a60eb9a215db2a355e9ec]

old_revision [a2b70fe6724237422aa5308a3056529e8ae12fbd]

rename "contrib/monotone-mail-notify.lua"
    to "extra/mtn-hooks/monotone-mail-notify.lua"

rename "contrib/monotone-mail-notify.sh"
    to "extra/mtn-hooks/monotone-mail-notify"

add_dir "extra/mtn-hooks"

add_dir "test/extra/mail-notify"

add_dir "test/extra/mail-notify/hooks.d"

add_dir "test/extra/mail-notify/scripts"

add_file "test/extra/mail-notify/__driver__.lua"
 content [dd5179702c826ae1b6a205f63a8ea39c7e3fb590]

add_file "test/extra/mail-notify/hooks.d/authorize_mail_notify_commands.lua"
 content [948a7bfa96c89da0265c8b5eda4a99263c74491f]

add_file "test/extra/mail-notify/mime-construct.expected"
 content [56c894acf95b527b9a05de2147e21b1aa1f2b3ce]

add_file "test/extra/mail-notify/scripts/mime-construct"
 content [e8b34e4c59812c2e706f913bf8f7a694588af12c]

add_file "test/extra/mail-notify/scripts/mime-construct-extract"
 content [96cfd2769fa0ea941d9db5d3273d68122c44b12e]

add_file "test/extra/mail-notify/scripts/run-mail-notify"
 content [b90ab9abd71ff563f2492839cff878b947092bd6]

patch "extra/mtn-hooks/monotone-mail-notify"
 from [1e447c16f2f9962374d0ab26fd0d4c2d0f69d7f6]
   to [805853cf58465efb4b65e17c1d0cd8b6593ea955]

patch "extra/mtn-hooks/monotone-mail-notify.lua"
 from [71329cf83f1a56aafea35a6b9f9190a25df258de]
   to [f498fdf33ee9e4a453665f66fb72f0a17a0ee624]

  set "extra/mtn-hooks/monotone-mail-notify"
 attr "mtn:execute"
value "true"

  set "test/extra/mail-notify/scripts/mime-construct"
 attr "mtn:execute"
value "true"

  set "test/extra/mail-notify/scripts/mime-construct-extract"
 attr "mtn:execute"
value "true"

  set "test/extra/mail-notify/scripts/run-mail-notify"
 attr "mtn:execute"
value "true"
============================================================
--- contrib/monotone-mail-notify.lua	71329cf83f1a56aafea35a6b9f9190a25df258de
+++ extra/mtn-hooks/monotone-mail-notify.lua	f498fdf33ee9e4a453665f66fb72f0a17a0ee624
@@ -34,7 +34,7 @@ do
 do
    _from = "address@hidden"
    _server = "localhost"
-   _base = "/var/spool/monotone/"
+   _base = "/var/spool/monotone"
    _keydir = get_confdir() .. "/keys"
    _key = ""
    _shellscript = ""
@@ -91,6 +91,7 @@ do
       data["keydir"] = _keydir
       data["key"] = _key
       data["shellscript"] = _shellscript
+      data["base"] = _base
 
       for i, item in pairs(notifydata)
       do
@@ -115,6 +116,10 @@ do
 	    for j, val in pairs(item.values) do
 	       data[item.name] = val
 	    end
+	 elseif item.name == "base" then
+	    for j, val in pairs(item.values) do
+	       data[item.name] = val
+	    end
 	    -- Skip past other accepted words
 	 elseif item.name == "pattern" then
 	 elseif item.name == "allow" then
@@ -142,6 +147,7 @@ do
 	 elseif item.name == "keydir" then
 	 elseif item.name == "key" then
 	 elseif item.name == "shellscript" then
+	 elseif item.name == "base" then
 	    -- legal names: pattern, allow, deny, continue, comment
 	 elseif item.name == "pattern" then
 	    if matches and not cont then
@@ -267,6 +273,7 @@ do
 	       local keydir = _configuration_data["keydir"]
 	       local key = _configuration_data["key"]
 	       local shellscript = _configuration_data["shellscript"]
+	       local base = _configuration_data["base"]
 
 	       --print("monotone-mail-notify: About to write data")
 	       for rev_id,rev_data in pairs(_emails_to_send[session_id]) do
@@ -282,12 +289,13 @@ do
 
 		     local now = os.time()
 
-		     --print("monotone-mail-notify: Writing data for revision ",
-		     --	rev_data["revision"])
+		     -- print("monotone-mail-notify: Writing data for revision",
+		     --       rev_data["revision"], "to files with base",
+		     --       base .. "/" .. now .. "." .. rev_data["revision"])
 
-		     local outputFileRev = io.open(_base .. now .. "." .. rev_data["revision"] .. ".rev.txt", "w+")
-		     local outputFileHdr = io.open(_base .. now .. "." .. rev_data["revision"] .. ".hdr.txt", "w+")
-		     local outputFileDat = io.open(_base .. now .. "." .. rev_data["revision"] .. ".dat.txt", "w+")
+		     local outputFileRev = io.open(base .. "/" .. now .. "." .. rev_data["revision"] .. ".rev.txt", "w+")
+		     local outputFileHdr = io.open(base .. "/" .. now .. "." .. rev_data["revision"] .. ".hdr.txt", "w+")
+		     local outputFileDat = io.open(base .. "/" .. now .. "." .. rev_data["revision"] .. ".dat.txt", "w+")
 
 		     local to = ""
 		     for j,addr in pairs(rev_data["recipients"]) do
@@ -314,12 +322,12 @@ do
 	       end
 
 	       if shellscript and shellscript ~= "" then
-		  print("monotone-mail-notify.lua: Running script ",
-			shellscript)
+		  print("monotone-mail-notify.lua: Running script:",
+			shellscript, base)
 		  spawn_redirected("/dev/null",
 				   _shellscript_log,
 				   _shellscript_errlog,
-				   "bash", shellscript)
+				   shellscript, base)
 	       end
 	       _emails_to_send[session_id] = nil
 	       return "continue",nil
============================================================
--- contrib/monotone-mail-notify.sh	1e447c16f2f9962374d0ab26fd0d4c2d0f69d7f6
+++ extra/mtn-hooks/monotone-mail-notify	805853cf58465efb4b65e17c1d0cd8b6593ea955
@@ -1,4 +1,4 @@
-#! /usr/local/bin/bash
+#! /usr/bin/env bash
 
 # Install the corresponding .lua file in monotone.  Its
 # comments holds instructions on how to configure this
@@ -12,11 +12,13 @@
 # Copyright (c) 2010, Richard Levitte <address@hidden)
 # License: GPLv2 or later
 
-MTN="/usr/local/bin/mtn"
-HIGHLIGHT="/usr/local/bin/source-highlight"
-MIMECONSTRUCT="/usr/local/bin/mime-construct"
+MTN="mtn"
+HIGHLIGHT="source-highlight"
+MIMECONSTRUCT="mime-construct"
 BASE="/var/spool/monotone"
 
+if [ -n "$1" ]; then BASE="$1"; fi
+
 function processFile() {
     local fileBase=$1
 
@@ -158,6 +160,7 @@ then
 
 if [ "x" = "x$(ls $BASE)" ]
 then
+    echo >&2 "monotone-mail-notify: no files in $BASE, exiting"
     exit 0
 fi
 
============================================================
--- /dev/null	
+++ test/extra/mail-notify/__driver__.lua	dd5179702c826ae1b6a205f63a8ea39c7e3fb590
@@ -0,0 +1,72 @@
+skip_if(not existsonpath("mime-construct"))
+skip_if(not existsonpath("source-highlight"))
+
+includecommon("netsync.lua")
+
+mtn_setup()
+netsync.setup()
+append("netsync.lua", "\n\
+\n\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.conf\")\n\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.lua\")\n\
+")
+
+-- To make sure we get things into a file and not sent to some unknown
+-- email address (or /dev/null, which doesn't help us much), we do a
+-- little bit of a hack to modify the behaviour of mime-construct.  It
+-- works as follows:
+-- monotone server, on receiving a revision, will call the functions in
+-- monotone-mail-notify.lua, as normal.  The functions there will not
+-- call the shell script monotone-mail-notify directly, though.  Instead,
+-- it will call run-mail-notify (present in this test directory), which
+-- will alter $PATH locally to call a local version of mime-construct
+-- (basically, a shell script that calls mime-construct with an extra
+-- parameter to make sure it outputs to file instead of sending an email).
+mkdir("hooks.d")
+mkdir("scripts")
+check(copy(srcdir.."/../extra/mtn-hooks/monotone-mail-notify.lua",
+	   "hooks.d/monotone-mail-notify.lua"))
+check(copy(srcdir.."/../extra/mtn-hooks/monotone-mail-notify",
+	   "scripts/monotone-mail-notify"))
+check(get("scripts/run-mail-notify"))
+check(get("scripts/mime-construct"))
+check(get("hooks.d/authorize_mail_notify_commands.lua"))
+
+-- A file with expected result and the script that generates it
+check(get("mime-construct.expected"))
+check(get("scripts/mime-construct-extract"))
+
+-- Serve test2.db
+srv = netsync.start(2)
+
+-- Write the notification configuration
+mkdir(test.root .. "/spool")
+check(writefile("notify", "server \"mtn://" .. srv.address .. "?testbranch\"\
+from \"address@hidden"\
+keydir \"" .. test.root .. "/keys\"\
+key \"\"\
+shellscript \"" .. test.root .. "/scripts/run-mail-notify\"\
+base \"" .. test.root .."/spool\"\
+\
+pattern \"*\"\
+allow \"address@hidden"\
+"))
+
+-- Add some revisions to push
+addfile("test1", "foo")
+addfile("test2", "bar")
+commit()
+writefile("test2", "foobar")
+commit()
+
+-- Do the transfer
+srv:push("testbranch",1)
+
+check(exists("mime-construct.out"))
+wait(spawn_redirected("mime-construct.out",
+		      "mime-construct.extract",
+		      "mime-extract.err",
+		      "scripts/mime-construct-extract"))
+check(samefile("mime-construct.extract",
+	       "mime-construct.expected"))
+srv:stop()
============================================================
--- /dev/null	
+++ test/extra/mail-notify/hooks.d/authorize_mail_notify_commands.lua	948a7bfa96c89da0265c8b5eda4a99263c74491f
@@ -0,0 +1,15 @@
+do
+   local _save_get_remote_automate_permitted = get_remote_automate_permitted
+   function get_remote_automate_permitted(key_identity, command, options)
+      local mail_notify_commands = {
+	 "parents", "get_revision", "get_file", "content_diff"
+      }
+      for _,v in ipairs(mail_notify_commands) do
+	 if (v == command[1]) then
+	    return true
+	 end
+      end
+
+      return false
+   end
+end
============================================================
--- /dev/null	
+++ test/extra/mail-notify/mime-construct.expected	56c894acf95b527b9a05de2147e21b1aa1f2b3ce
@@ -0,0 +1,53 @@
+To: address@hidden
+From: address@hidden
+Subject: testbranch: 425f7d00baffb1f43a12b60f106b2293d5dddd7c
+--1
+revision:            425f7d00baffb1f43a12b60f106b2293d5dddd7c
+author:              address@hidden
+branch:              testbranch
+new_manifest [7d7201b5790d5f03cb148fe419c146329d509c3f]
+old_revision [dea7b0e6d7db3450398fa32af3938861b4e6dc60]
+patch "test2"
+ from [62cdb7020ff920e5aa642c3d4066950dd1f01f4d]
+   to [8843d7f92416211de9ebb963ff4ce28125932878]
+--1
+--2
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
+--- test2	62cdb7020ff920e5aa642c3d4066950dd1f01f4d
++++ test2	8843d7f92416211de9ebb963ff4ce28125932878
+@@ -1 +1 @@
+-bar
+\ No newline at end of file
++foobar
+\ No newline at end of file
+
+--2
+--2--
+--1--
+To: address@hidden
+From: address@hidden
+Subject: testbranch: dea7b0e6d7db3450398fa32af3938861b4e6dc60
+--3
+revision:            dea7b0e6d7db3450398fa32af3938861b4e6dc60
+author:              address@hidden
+branch:              testbranch
+new_manifest [b41ab7e3662a901fd8e2b6687804b8dcb2718264]
+old_revision []
+add_file "test1"
+ content [0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33]
+add_file "test2"
+ content [62cdb7020ff920e5aa642c3d4066950dd1f01f4d]
+--3
+--4
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
+--- /dev/null=09
++++ test2	62cdb7020ff920e5aa642c3d4066950dd1f01f4d
++bar=
+
+--4
+--4--
+--3--
============================================================
--- /dev/null	
+++ test/extra/mail-notify/scripts/mime-construct	e8b34e4c59812c2e706f913bf8f7a694588af12c
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+set -x
+if [ "$1" = "--subpart" ]; then
+    # The calling script is already redirecting to a file,
+    # let's not disturb that
+    $_MIME_CONSTRUCT "$@"
+else
+    $_MIME_CONSTRUCT --output "$@" \
+	>> $_MIME_CONSTRUCT_OUTPUT \
+	2>> $_MIME_CONSTRUCT_ERROR
+fi
============================================================
--- /dev/null	
+++ test/extra/mail-notify/scripts/mime-construct-extract	96cfd2769fa0ea941d9db5d3273d68122c44b12e
@@ -0,0 +1,88 @@
+#! /usr/bin/env perl
+
+# Takes a mail file generated with mime-construct and extracts the headers
+# To:, From: and Subject:, reformats the boundary lines to use numbers
+# (counting from 1) and any line containing one of the following regexps:
+# /^revision:\s/
+# /^author:\s/
+# /^branch:\s/
+# /^new_manifest\s\[/
+# /^old_revision\s\[/
+# /^patch\s"/
+# /^\sfrom\s\[/
+# /^\s\s\sto\s\[/
+# Also, any attachment with the content type text/plain that starts with
+# a line of = signs (QUOTED-PRINTABLE =3D) is extracted as is.
+
+use strict;
+use warnings;
+
+my @boundary_stack = ();
+my %boundary_index = ();
+my $next_index = 0;
+
+while(1) {
+    # Start with headers, those are seen all the way until the first empty line
+
+    my $current_content_type;
+    while(<STDIN>) {
+	chomp;
+	last if /^$/;
+
+	if (m|^content-type:\s*([-a-z]+/[-a-z]+)\s*(?:;\s*([a-z]+)=(.+))?$|i) {
+	    $current_content_type = $1;
+	    my $parameter_name = $2;
+	    my $parameter_value = $3;
+	    if ($current_content_type =~ m|^multipart/.*$|) {
+		# $parameter_name should be "boundary"
+		push @boundary_stack, $parameter_value;
+		$boundary_index{$parameter_value} = ++$next_index;
+	    }
+	}
+
+	next unless /^(to|from|subject):\s/i;
+	print $_,"\n";
+    }
+
+    ### Now is the time for the main body, before the attachments
+
+    # The following is to detect a text/plain file that starts with a series
+    # of quoted-printable equal signs (=3D).
+    my $first_line = 1;
+    my $print_all = 0;
+
+    while(<STDIN>) {
+	chomp;
+
+	my $current_boundary = $boundary_stack[$#boundary_stack];
+	my $current_index = $boundary_index{$current_boundary};
+
+	if ($first_line && $current_content_type eq "text/plain" &&
+	    m|^(=3D)+=$|) {
+	    $print_all = 1;
+	}
+	$first_line = 0;
+	if ($_ eq "--$current_boundary") {
+	    print "--$current_index\n";
+	    last;
+	}
+	if ($_ eq "--$current_boundary--") {
+	    print "--$current_index--\n";
+	    pop @boundary_stack;
+	    last if $#boundary_stack < 0;
+	    next;
+	}
+
+	next unless $print_all ||
+	    /^(?:
+	       (?:revision|author|branch):\s
+	       |
+	       (?:new_manifest|old_revision|\s+from|\s+to|\s+content)\s\[
+	       |
+	       (?:patch|add_file)\s\"
+	       )/sx;
+	print $_,"\n";
+    }
+
+    last if eof(STDIN);
+}
============================================================
--- /dev/null	
+++ test/extra/mail-notify/scripts/run-mail-notify	b90ab9abd71ff563f2492839cff878b947092bd6
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+# Current work directory should be
+# {builddir}/test/work/extra/mail-notify
+
+_MIME_CONSTRUCT="`type -p mime-construct || which mime-construct`"
+_MIME_CONSTRUCT_OUTPUT="`pwd`/mime-construct.out"
+_MIME_CONSTRUCT_ERROR="`pwd`/mime-construct.err"
+_HERE="`dirname ${0}`"
+ls -a "$1"
+ls -aR "`dirname $1`"
+export _MIME_CONSTRUCT _MIME_CONSTRUCT_OUTPUT _MIME_CONSTRUCT_ERROR
+PATH=${_HERE}:$PATH ${_HERE}/monotone-mail-notify "$@"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]