zurl 1.3.1 (new formula)
Closes Homebrew/homebrew#36923. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
57953d7bf6
commit
5acb9a54dc
1 changed files with 94 additions and 0 deletions
94
Formula/zurl.rb
Normal file
94
Formula/zurl.rb
Normal file
|
@ -0,0 +1,94 @@
|
|||
class Zurl < Formula
|
||||
homepage "https://github.com/fanout/zurl"
|
||||
url "http://packages.fanout.io/source/zurl-1.3.1.tar.bz2"
|
||||
sha1 "8a04ad092a4fd9b174a352b910c190466fc39eb9"
|
||||
|
||||
depends_on "pkg-config" => :build
|
||||
depends_on "curl" if MacOS.version < :lion
|
||||
depends_on "qt"
|
||||
depends_on "zeromq"
|
||||
depends_on "qjson"
|
||||
|
||||
resource "pyzmq" do
|
||||
url "https://pypi.python.org/packages/source/p/pyzmq/pyzmq-14.5.0.tar.gz"
|
||||
sha1 "1dced02ea8527b5870ffdbe835d096aca5c01d2a"
|
||||
end
|
||||
|
||||
def install
|
||||
system "./configure", "--prefix=#{prefix}"
|
||||
system "make"
|
||||
system "make", "install"
|
||||
end
|
||||
|
||||
test do
|
||||
conffile = testpath/"zurl.conf"
|
||||
ipcfile = testpath/"zurl-req"
|
||||
runfile = testpath/"test.py"
|
||||
|
||||
resource("pyzmq").stage { system "python", *Language::Python.setup_install_args(testpath/"vendor") }
|
||||
|
||||
conffile.write(<<-EOS.undent
|
||||
[General]
|
||||
in_req_spec=ipc://#{ipcfile}
|
||||
defpolicy=allow
|
||||
timeout=10
|
||||
EOS
|
||||
)
|
||||
|
||||
runfile.write(<<-EOS.undent
|
||||
import json
|
||||
import threading
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||
import zmq
|
||||
class TestHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write('test response\\n')
|
||||
port = None
|
||||
def server_worker(c):
|
||||
global port
|
||||
server = HTTPServer(('', 0), TestHandler)
|
||||
port = server.server_address[1]
|
||||
c.acquire()
|
||||
c.notify()
|
||||
c.release()
|
||||
try:
|
||||
server.serve_forever()
|
||||
except:
|
||||
server.server_close()
|
||||
c = threading.Condition()
|
||||
c.acquire()
|
||||
server_thread = threading.Thread(target=server_worker, args=(c,))
|
||||
server_thread.daemon = True
|
||||
server_thread.start()
|
||||
c.wait()
|
||||
c.release()
|
||||
ctx = zmq.Context()
|
||||
sock = ctx.socket(zmq.REQ)
|
||||
sock.connect('ipc://#{ipcfile}')
|
||||
req = {'id': '1', 'method': 'GET', 'uri': 'http://localhost:%d/test' % port}
|
||||
sock.send('J' + json.dumps(req))
|
||||
poller = zmq.Poller()
|
||||
poller.register(sock, zmq.POLLIN)
|
||||
socks = dict(poller.poll(15000))
|
||||
assert(socks.get(sock) == zmq.POLLIN)
|
||||
resp = json.loads(sock.recv()[1:])
|
||||
assert('type' not in resp)
|
||||
assert(resp['body'] == 'test response\\n')
|
||||
EOS
|
||||
)
|
||||
|
||||
pid = fork do
|
||||
exec "#{bin}/zurl", "--config=#{conffile}"
|
||||
end
|
||||
|
||||
begin
|
||||
ENV["PYTHONPATH"] = testpath/"vendor/lib/python2.7/site-packages"
|
||||
system "python", runfile
|
||||
ensure
|
||||
Process.kill("TERM", pid)
|
||||
Process.wait(pid)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue