Tim Landscheidt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/340276 )

Change subject: Package jmail
......................................................................

Package jmail

Bug: T158722
Change-Id: I2a2a86ecf1f0129374733f9222decf241d13e708
---
M configure.ac
M debian/changelog
M debian/control
M debian/copyright
M debian/jobutils.install
M debian/jobutils.manpages
M jobutils/bin/Makefile.am
A jobutils/bin/jmail
M jobutils/man/Makefile.am
A jobutils/man/jmail.1.in
M tox.ini
11 files changed, 124 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs 
refs/changes/76/340276/1

diff --git a/configure.ac b/configure.ac
index 5a3b7d5..bc7795b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@
                  jobutils/Makefile
                  jobutils/bin/Makefile
                  jobutils/man/Makefile
+                 jobutils/man/jmail.1
                  jobutils/man/job.1
                  jobutils/man/jstop.1
                  jobutils/man/jsub.1
diff --git a/debian/changelog b/debian/changelog
index cd131c6..bbb1283 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+toollabs (1.20~precise+1~dev) precise; urgency=medium
+
+  * Package jmail
+
+ -- Tim Landscheidt <t...@tim-landscheidt.de>  Tue, 28 Feb 2017 03:25:32 +0000
+
 toollabs (1.19~precise+1) precise; urgency=medium
 
   * Remove toolwatcher
diff --git a/debian/control b/debian/control
index fa8b889..a99e382 100644
--- a/debian/control
+++ b/debian/control
@@ -22,7 +22,8 @@
 Package: jobutils
 Architecture: all
 Depends: ${misc:Depends}, ${perl:Depends}, ${python:Depends},
- gridengine-client, libipc-run-perl, libstring-shellquote-perl, python
+ gridengine-client, libipc-run-perl, libstring-shellquote-perl,
+ python, python3
 Description: Set of utilities to use on wikimedia bots and tools cluster
  This package will install jstart (jsub) and jstop, the Tool Labs (more)
  user-friendly wrappers to submit jobs to the gridengine
diff --git a/debian/copyright b/debian/copyright
index f3d9372..f545288 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -5,6 +5,10 @@
 Copyright: 2013 Marc-André Pelletier <mpellet...@wikimedia.org>
 License: ISC
 
+Files: jobutils/bin/jmail jobutils/man/jmail.1.in
+Copyright: Copyright 2017 Tim Landscheidt <t...@tim-landscheidt.de>
+License: GPL-3.0+
+
 Files: debian/*
 Copyright: 2013 Carl Fürstenberg <azat...@gmail.com>
 License: GPL-3.0+
diff --git a/debian/jobutils.install b/debian/jobutils.install
index 3b8bf2f..956f91f 100644
--- a/debian/jobutils.install
+++ b/debian/jobutils.install
@@ -1,3 +1,4 @@
+usr/bin/jmail
 usr/bin/job
 usr/bin/jstart
 usr/bin/jstop
diff --git a/debian/jobutils.manpages b/debian/jobutils.manpages
index 92a5a84..c6a457c 100644
--- a/debian/jobutils.manpages
+++ b/debian/jobutils.manpages
@@ -1,3 +1,4 @@
+debian/tmp/usr/share/man/man1/jmail.1
 debian/tmp/usr/share/man/man1/job.1
 debian/tmp/usr/share/man/man1/jstop.1
 debian/tmp/usr/share/man/man1/jsub.1
diff --git a/jobutils/bin/Makefile.am b/jobutils/bin/Makefile.am
index 764fc98..7312c92 100644
--- a/jobutils/bin/Makefile.am
+++ b/jobutils/bin/Makefile.am
@@ -1,4 +1,4 @@
-bin_SCRIPTS = job jstop jsub
+bin_SCRIPTS = jmail job jstop jsub
 
 install-exec-hook:
        cd $(DESTDIR)$(bindir) && \
diff --git a/jobutils/bin/jmail b/jobutils/bin/jmail
new file mode 100755
index 0000000..d996f68
--- /dev/null
+++ b/jobutils/bin/jmail
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+#
+# Copyright (C) 2017  Tim Landscheidt
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import pwd
+import shutil
+import subprocess
+import sys
+import tempfile
+
+# Both temporary files need to be created in the tool's home directory
+# on NFS so they can be accessed from any grid host.
+home_directory = pwd.getpwuid(os.getuid()).pw_dir
+with tempfile.NamedTemporaryFile(mode='w+',
+                                 suffix='.in',
+                                 prefix='jmail-',
+                                 dir=home_directory) as input, \
+     tempfile.NamedTemporaryFile(mode='w+',
+                                 suffix='.out',
+                                 prefix='jmail-',
+                                 dir=home_directory) as output:
+    # Determine the full path of the program to execute.
+    program = shutil.which(sys.argv[1])
+    if program is None:
+        sys.exit('Processing program unavailable')
+
+    # Copy the incoming message from stdin to the temporary file.
+    shutil.copyfileobj(sys.stdin, input)
+    input.flush()
+
+    # Execute the given program synchronously on the grid.
+    rv = subprocess.call(['/usr/bin/qsub',
+                          '-N', 'mail.' + pwd.getpwuid(os.getuid()).pw_name,
+                          '-sync', 'y',
+                          '-b', 'y',
+                          '-m', 'n',
+                          '-o', output.name,
+                          '-j', 'y',
+                          '-i', input.name,
+                          '-q', 'mailq',
+                          '-l', 'h_vmem=500M',
+                          '-r', 'n', program] + sys.argv[2:],
+                         stdout=subprocess.DEVNULL)
+
+    # Copy the output of the program to stdout.
+    shutil.copyfileobj(output, sys.stdout)
+    sys.exit(rv)
diff --git a/jobutils/man/Makefile.am b/jobutils/man/Makefile.am
index 77b9af7..a663c81 100644
--- a/jobutils/man/Makefile.am
+++ b/jobutils/man/Makefile.am
@@ -1 +1 @@
-man_MANS = job.1 jstop.1 jsub.1
+man_MANS = jmail.1 job.1 jstop.1 jsub.1
diff --git a/jobutils/man/jmail.1.in b/jobutils/man/jmail.1.in
new file mode 100644
index 0000000..d5a4f84
--- /dev/null
+++ b/jobutils/man/jmail.1.in
@@ -0,0 +1,38 @@
+.TH JMAIL 1 @TOOLLABS_RELEASEDATE@ @PACKAGE_VERSION@ "Wikimedia Labs Tools 
jobutils"
+.SH NAME
+jmail \- execute program synchronously on the grid
+.SH SYNOPSIS
+.RB | jmail
+.IR program
+.RI [ args ]
+.SH DESCRIPTION
+.B jmail
+is used in
+.B .forward
+files to execute a program synchronously on the grid.  In Tool Labs it
+is the only command allowed in
+.B .forward
+files.
+.PP
+.B jmail
+passes its standard input, i. e. the incoming mail, to the specified
+program.  After the program has finished,
+.B jmail
+copies its output to standard output.
+.PP
+Programs are executed in the queue
+.B mailq
+with a memory limit of 500 MBytes and a timeout of 30\~s CPU/60\~s
+wall clock.  It is strongly recommended that programs should not
+attempt any heavy processing, but store the incoming messages for
+later processing by other components.
+.SH EXIT STATUS
+.B jmail
+returns 1 if
+.I program
+cannot be found in
+.BR PATH .
+Otherwise it returns the exit code of the executed
+.IR program .
+.SH AUTHORS
+Marc-André Pelletier, Tim Landscheidt
diff --git a/tox.ini b/tox.ini
index 3954ce5..d71d771 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,12 +1,16 @@
 [tox]
 minversion = 1.6
-envlist = py27, flake8
+envlist = py27, py34, flake8
 
 [testenv]
-basepython = python2.7
-commands = python -m doctest jobutils/bin/jsub
+basepython =
+    py27: python2.7
+    py34: python3.4
+commands =
+    py27: python -m doctest jobutils/bin/jsub
+    py34: python -m doctest jobutils/bin/jmail
 
 [testenv:flake8]
 basepython = python2.7
-commands = flake8 jobutils/bin/jsub
+commands = flake8 jobutils/bin/jmail jobutils/bin/jsub
 deps = flake8

-- 
To view, visit https://gerrit.wikimedia.org/r/340276
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a2a86ecf1f0129374733f9222decf241d13e708
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: ubuntu/precise
Gerrit-Owner: Tim Landscheidt <t...@tim-landscheidt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to