summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-11 11:54:54 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-11 11:54:54 +0100
commit88d9e29c29f770e664ee785fdbf3ff0668fe1c35 (patch)
tree35d11aa7964cbaf1b30c482471c0a1f3ddb5ec89
parentacefe33868585cf31cda53474a3004da42e00896 (diff)
downloadmorph-cache-server-88d9e29c29f770e664ee785fdbf3ff0668fe1c35.tar.gz
Update to latest morph-cache-server code from morph.git
-rwxr-xr-xmorph-cache-server35
-rw-r--r--morphcacheserver/__init__.py5
-rw-r--r--morphcacheserver/repocache.py9
3 files changed, 36 insertions, 13 deletions
diff --git a/morph-cache-server b/morph-cache-server
index a3c3c97..007cfbe 100755
--- a/morph-cache-server
+++ b/morph-cache-server
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (C) 2013, 2014 Codethink Limited
+# Copyright (C) 2013, 2014-2015 Codethink Limited
#
# 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
@@ -12,8 +12,7 @@
# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# with this program. If not, see <http://www.gnu.org/licenses/>.
import base64
@@ -45,6 +44,10 @@ class MorphCacheServer(cliapp.Application):
'port to listen on',
metavar='PORTNUM',
default=defaults['port'])
+ self.settings.string(['port-file'],
+ 'write port number to FILE',
+ metavar='FILE',
+ default='')
self.settings.string(['repo-dir'],
'path to the repository cache directory',
metavar='PATH',
@@ -322,7 +325,8 @@ class MorphCacheServer(cliapp.Application):
% artifact)
return
- filename = os.path.join(self.settings['artifact-dir'], artifact)
+ filename = os.path.join(self.settings['artifact-dir'],
+ artifact)
results[artifact] = os.path.exists(filename)
if results[artifact]:
@@ -338,8 +342,29 @@ class MorphCacheServer(cliapp.Application):
if self.settings['fcgi-server']:
WSGIServer(root).run()
+ elif self.settings['port-file']:
+ import wsgiref.simple_server
+
+ server_port_file = self.settings['port-file']
+ class DebugServer(wsgiref.simple_server.WSGIServer):
+ '''WSGI-like server that uses an ephemeral port.
+
+ Rather than use a specified port, or default, the
+ DebugServer binds to an ephemeral port on 127.0.0.1
+ and writes its number to port-file, so a non-racy
+ temporary port can be used.
+
+ '''
+
+ def __init__(self, (host, port), *args, **kwargs):
+ wsgiref.simple_server.WSGIServer.__init__(
+ self, ('127.0.0.1', 0), *args, **kwargs)
+ with open(server_port_file, 'w') as f:
+ f.write(str(self.server_port) + '\n')
+ run(root, server_class=DebugServer, debug=True)
else:
- run(root, host='0.0.0.0', port=self.settings['port'], reloader=True)
+ run(root, host='0.0.0.0', port=self.settings['port'],
+ reloader=True)
def _unescape_parameter(self, param):
return urllib.unquote(param)
diff --git a/morphcacheserver/__init__.py b/morphcacheserver/__init__.py
index 2c25ce2..c646c1a 100644
--- a/morphcacheserver/__init__.py
+++ b/morphcacheserver/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013,2015 Codethink Limited
#
# 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
@@ -10,8 +10,7 @@
# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# with this program. If not, see <http://www.gnu.org/licenses/>.
import repocache
diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py
index 0e4d909..d45cf86 100644
--- a/morphcacheserver/repocache.py
+++ b/morphcacheserver/repocache.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013,2014-2015 Codethink Limited
#
# 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
@@ -10,8 +10,7 @@
# 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, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# with this program. If not, see <http://www.gnu.org/licenses/>.
import cliapp
@@ -91,7 +90,7 @@ class RepoCache(object):
raise RepositoryNotFoundError(repo_url)
try:
sha1 = self._rev_parse(repo_dir, ref)
- except:
+ except BaseException:
raise InvalidReferenceError(repo_url, ref)
return self._cat_file(repo_dir, sha1, filename)
@@ -110,7 +109,7 @@ class RepoCache(object):
try:
sha1 = self._rev_parse(repo_dir, ref)
- except:
+ except BaseException:
raise InvalidReferenceError(repo_url, ref)
lines = self._ls_tree(repo_dir, sha1, path).strip()