Пример #1
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = args.host
    port = args.port or settings.SERVER_PORT
    bottle.TEMPLATE_PATH.insert(
        0, os.path.join(os.path.dirname(__file__), '..', 'views')
    )

    # If you started without WSGI, the base will be '/'.
    if args.baseurl == '' and not args.wsgi:
        args.baseurl = '/'

    # If you specified a base URL, make sure it ends with '/'.
    if args.baseurl != '' and not args.baseurl.endswith('/'):
        args.baseurl += '/'

    bottle.SimpleTemplate.defaults['baseurl'] = args.baseurl
    bottle.SimpleTemplate.defaults['navigation'] = True

    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    if not args.wsgi:
        bottle.run(app=app, host=host, port=port, debug=args.debug, reloader=args.debug)
Пример #2
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = args.host
    port = args.port or settings.SERVER_PORT
    bottle.TEMPLATE_PATH.insert(0, os.path.join(os.path.dirname(__file__),
                                                '..', 'views'))

    # If you started without WSGI, the base will be '/'.
    if args.baseurl == '' and not args.wsgi:
        args.baseurl = '/'

    # If you specified a base URL, make sure it ends with '/'.
    if args.baseurl != '' and not args.baseurl.endswith('/'):
        args.baseurl += '/'

    bottle.SimpleTemplate.defaults['baseurl'] = args.baseurl
    bottle.SimpleTemplate.defaults['navigation'] = True

    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    if not args.wsgi:
        bottle.run(app=app, host=host, port=port,
                   debug=args.debug, reloader=args.debug)
Пример #3
0
def exists(path='/documents'):
    """Determine if the server exists."""
    found = False
    url = utilities.build_url(path=path)
    if url:
        log.debug("looking for {}...".format(url))
        try:
            response = requests.head(url)
        except requests.exceptions.RequestException as exc:
            log.debug(exc)
        else:
            found = response.status_code == 200
        if found:
            log.info("found: {}".format(url))
    return found
Пример #4
0
def exists(path='/documents'):
    """Determine if the server exists."""
    found = False
    url = utilities.build_url(path=path)
    if url:
        log.debug("looking for {}...".format(url))
        try:
            response = requests.head(url)
        except requests.exceptions.RequestException as exc:
            log.debug(exc)
        else:
            found = response.status_code == 200
        if found:
            log.info("found: {}".format(url))
    return found
Пример #5
0
def get_next_number(prefix):
    """Get the next number for the given document prefix."""
    number = None
    url = utilities.build_url(path='/documents/{p}/numbers'.format(p=prefix))
    if not url:
        log.info("no server to get the next number from")
        return None
    headers = {'content-type': 'application/json'}
    response = requests.post(url, headers=headers)
    if response.status_code == 200:
        data = response.json()
        number = data.get('next')
    if number is None:
        raise DoorstopError("bad response from: {}".format(url))
    log.info("next number from the server: {}".format(number))
    return number
Пример #6
0
def get_next_number(prefix):
    """Get the next number for the given document prefix."""
    number = None
    url = utilities.build_url(path='/documents/{p}/numbers'.format(p=prefix))
    if not url:
        log.info("no server to get the next number from")
        return None
    headers = {'content-type': 'application/json'}
    response = requests.post(url, headers=headers)
    if response.status_code == 200:
        data = response.json()
        number = data.get('next')
    if number is None:
        raise DoorstopError("bad response from: {}".format(url))
    log.info("next number from the server: {}".format(number))
    return number
Пример #7
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = "localhost"
    port = args.port or settings.SERVER_PORT
    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    bottle.run(app=app, host=host, port=port, debug=args.debug, reloader=args.debug)
Пример #8
0
def run(args, cwd, _):
    """Start the server.

    :param args: Namespace of CLI arguments (from this module or the CLI)
    :param cwd: current working directory
    :param error: function to call for CLI errors

    """
    global tree  # pylint: disable=W0603,C0103
    tree = build(cwd=cwd, root=args.project)
    tree.load()
    host = 'localhost'
    port = args.port or settings.SERVER_PORT
    if args.launch:
        url = utilities.build_url(host=host, port=port)
        webbrowser.open(url)
    bottle.run(host=host, port=port, debug=args.debug, reloader=args.debug)