Skip to content

Commit

Permalink
added a --server-only option to develop.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Feb 3, 2012
1 parent 91b32d3 commit 8deaf2d
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions develop.py
Expand Up @@ -20,7 +20,9 @@ def get_git_commit():
except Exception: except Exception:
return "unknown" return "unknown"


HOST = 'localhost'
PORT = 8888 PORT = 8888
BASE_URL = 'http://%s:%d/' % (HOST, PORT)
ROOT = os.path.abspath(os.path.dirname(__file__)) ROOT = os.path.abspath(os.path.dirname(__file__))


path = lambda *x: os.path.join(ROOT, *x) path = lambda *x: os.path.join(ROOT, *x)
Expand All @@ -32,30 +34,39 @@ def get_git_commit():


SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map.update(types) SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map.update(types)


def run(server_class=BaseHTTPServer.HTTPServer, def run_web_server(server_class=BaseHTTPServer.HTTPServer,
handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler, handler_class=SimpleHTTPServer.SimpleHTTPRequestHandler):
port=PORT):
os.chdir(path('website')) os.chdir(path('website'))
server_address = ('', port) server_address = (HOST, PORT)
print "Serving files in '%s' on port %d." % (os.getcwd(), port) print "Serving files in '%s' at %s." % (os.getcwd(), BASE_URL)
httpd = server_class(server_address, handler_class) httpd = server_class(server_address, handler_class)
httpd.serve_forever() httpd.serve_forever()


if __name__ == '__main__': def write_deployment_json():
if 'CUDDLEFISH_ROOT' not in os.environ:
print "WARNING: You don't seem to have the Add-on SDK activated. To learn how to activate it, visit: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/installation.html"
print
t = threading.Thread(target=run)
t.setDaemon(True)
t.start()

dep = open(path('data', 'deployment.json'), 'w') dep = open(path('data', 'deployment.json'), 'w')
dep.write(json.dumps({ dep.write(json.dumps({
'name': 'development', 'name': 'development',
'commit': get_git_commit(), 'commit': get_git_commit(),
'url': 'http://localhost:%d/' % PORT, 'url': BASE_URL,
'xpi_url': 'http://localhost:%d/xpi/' % PORT 'xpi_url': BASE_URL + 'xpi/'
})) }))
dep.close() dep.close()


sys.exit(subprocess.call(['cfx', 'run'] + sys.argv[1:], cwd=ROOT)) def run_firefox(args):
if 'CUDDLEFISH_ROOT' not in os.environ:
print "WARNING: You don't seem to have the Add-on SDK activated. To learn how to activate it, visit: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/installation.html"
print
return subprocess.call(['cfx', 'run'] + args, cwd=ROOT)

if __name__ == '__main__':
write_deployment_json()
if '--help' in sys.argv or '-h' in sys.argv:
print "usage: %s [--server-only] [cfx options]" % sys.argv[0]
sys.exit(1)
if '--server-only' in sys.argv:
run_web_server()
else:
t = threading.Thread(target=run_web_server)
t.setDaemon(True)
t.start()
sys.exit(run_firefox(sys.argv[1:]))

0 comments on commit 8deaf2d

Please sign in to comment.