Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: df4af12efa
Fetching contributors…

Cannot retrieve contributors at this time

executable file 108 lines (83 sloc) 3.016 kB
#!/usr/bin/env python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
import eventlet
eventlet.monkey_patch()
import greenlet
from optparse import OptionParser
from paste import deploy
import os
import sys
# If ../../mock/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(possible_topdir,
'mock',
'__init__.py')):
sys.path.insert(0, possible_topdir)
from mock import utils
from mock import log as logging
from mock import wsgi
LOG = logging.getLogger()
def parse_opts():
parser = OptionParser()
parser.add_option("-v", "--verbose",
action="append_const",
const=1,
dest="verbosity",
default=[1],
help="increase the verbose level")
parser.add_option("-p",
action="store",
type="string",
dest="paste_config_fn",
metavar="FILE",
help="paste config file (default: %default)")
# Extract only what we care about
(options, args) = parser.parse_args()
return options
def find_paste_conf():
lookups = list()
lookups.append(os.path.join('/', 'etc', 'mock', 'mock.conf'))
lookups.append(os.path.join(possible_topdir, 'etc', 'mock.conf'))
for fn in lookups:
LOG.debug("Looking for paste config at %r", fn)
if os.path.isfile(fn):
return fn
return None
def create_server(paste_conf_fn, name, port):
app = deploy.loadapp('config:%s' % paste_conf_fn,
name=name)
return wsgi.Server(app, port)
def serve(*servers):
for server in servers:
LOG.debug("Starting server %s on port %s",
server.application,
server.port)
server.start()
for server in servers:
try:
server.wait()
except greenlet.GreenletExit:
pass
def main():
cmd_options = parse_opts()
utils.setup_logging(len(cmd_options.verbosity))
LOG.debug("Command line options: %s", cmd_options)
paste_config_fn = cmd_options.paste_config_fn
if not paste_config_fn:
paste_config_fn = find_paste_conf()
if not paste_config_fn or not os.path.isfile(paste_config_fn):
print("No readable paste config file found!")
sys.exit(1)
paste_config_fn = os.path.abspath(paste_config_fn)
LOG.info("Using paste config found at %r", paste_config_fn)
app_options = deploy.appconfig('config:%s' % paste_config_fn)
LOG.debug("Paste %r with options: %s", paste_config_fn, app_options)
# This shouldn't terminate...
servers = []
servers.append(create_server(paste_config_fn, 'main', int(app_options['proxy_port'])))
serve(*servers)
if __name__ == '__main__':
main()
Jump to Line
Something went wrong with that request. Please try again.