From e920c98c72fc9674316ae32c26a81fe571964ea5 Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Sun, 3 May 2009 15:35:29 -0400
Subject: The very basics of a working REST server. Only works for
localhost:8001/sys
---
src/mailman/bin/qrunner.py | 16 ++++++++-----
src/mailman/config/mailman.cfg | 3 +++
src/mailman/config/schema.cfg | 3 +++
src/mailman/queue/rest.py | 50 +++++++++++++++++++++++++++++++++++++++++
src/mailman/rest/configure.zcml | 8 +++----
src/mailman/rest/urls.py | 34 +++++++++++++++++++++++-----
src/mailman/rest/webservice.py | 20 ++++++++++-------
7 files changed, 111 insertions(+), 23 deletions(-)
create mode 100644 src/mailman/queue/rest.py
(limited to 'src')
diff --git a/src/mailman/bin/qrunner.py b/src/mailman/bin/qrunner.py
index 62e943aad..0016d082b 100644
--- a/src/mailman/bin/qrunner.py
+++ b/src/mailman/bin/qrunner.py
@@ -202,12 +202,16 @@ def main():
options.initialize()
if options.options.list:
- prefixlen = max(len(shortname)
- for shortname in config.qrunner_shortcuts)
- for shortname in sorted(config.qrunner_shortcuts):
- runnername = config.qrunner_shortcuts[shortname]
- shortname = (' ' * (prefixlen - len(shortname))) + shortname
- print _('$shortname runs $runnername')
+ descriptions = {}
+ for section in config.qrunner_configs:
+ shortname = section.name.rsplit('.', 1)[-1]
+ classname = getattr(section, 'class').rsplit('.', 1)[-1]
+ descriptions[shortname] = classname
+ longest = max(len(name) for name in descriptions)
+ for shortname in sorted(descriptions):
+ classname = descriptions[shortname]
+ name = (' ' * (longest - len(shortname))) + shortname
+ print _('$name runs $classname')
sys.exit(0)
# Fast track for one infinite runner
diff --git a/src/mailman/config/mailman.cfg b/src/mailman/config/mailman.cfg
index d68099ca3..58dcdd4e8 100644
--- a/src/mailman/config/mailman.cfg
+++ b/src/mailman/config/mailman.cfg
@@ -54,6 +54,9 @@ class: mailman.queue.outgoing.OutgoingRunner
[qrunner.pipeline]
class: mailman.queue.pipeline.PipelineRunner
+[qrunner.rest]
+class: mailman.queue.rest.RESTRunner
+
[qrunner.retry]
class: mailman.queue.retry.RetryRunner
sleep_time: 15m
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index a2003d034..73a2ff34e 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -211,6 +211,9 @@ failure: $msgid delivery to $recip failed with code $smtpcode, $smtpmsg
# The hostname at which admin web service resources are exposed.
hostname: localhost
+# The port at which the admin web service resources are exposed.
+port: 8001
+
# Whether or not requests to the web service are secured through SSL.
use_https: no
diff --git a/src/mailman/queue/rest.py b/src/mailman/queue/rest.py
new file mode 100644
index 000000000..3d0eb3bae
--- /dev/null
+++ b/src/mailman/queue/rest.py
@@ -0,0 +1,50 @@
+# Copyright (C) 2009 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman 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.
+#
+# GNU Mailman 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
+# GNU Mailman. If not, see .
+
+"""Start the administrative HTTP server."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'RESTRunner',
+ ]
+
+
+import sys
+import errno
+import select
+import signal
+import logging
+
+from mailman.queue import Runner
+from mailman.rest.webservice import start
+
+
+
+class RESTRunner(Runner):
+ def run(self):
+ try:
+ start()
+ except KeyboardInterrupt:
+ sys.exit(signal.SIGTERM)
+ except select.error as (errcode, message):
+ if errcode == errno.EINTR:
+ sys.exit(signal.SIGTERM)
+ raise
+ except:
+ raise
diff --git a/src/mailman/rest/configure.zcml b/src/mailman/rest/configure.zcml
index edd444d0d..70155bf67 100644
--- a/src/mailman/rest/configure.zcml
+++ b/src/mailman/rest/configure.zcml
@@ -10,11 +10,11 @@
-
-