コード例 #1
0
ファイル: packages.py プロジェクト: al4/orlo
def get_packages(package_id=None):
    """
    Return a list of packages to the client

    :param package_id:
    :return:
    """

    booleans = ('rollback', )

    if package_id:  # Simple, just fetch one package
        if not is_uuid(package_id):
            raise InvalidUsage("Package ID given is not a valid UUID")
        query = queries.get_package(package_id)
    elif len([x for x in request.args.keys()]) == 0:
        raise InvalidUsage("Please specify a filter. See "
                           "http://orlo.readthedocs.org/en/latest/rest.html"
                           "#get--packages for more info")
    else:  # Bit more complex
        # Flatten args, as the ImmutableDict puts some values in a list when
        # expanded
        args = {}
        for k in request.args.keys():
            if k in booleans:
                args[k] = str_to_bool(request.args.get(k))
            else:
                args[k] = request.args.get(k)
        query = queries.packages(**args)

    # Execute eagerly to avoid confusing stack traces within the Response on
    # error
    db.session.execute(query)

    return Response(stream_json_list('packages', query),
                    content_type='application/json')
コード例 #2
0
def get_packages(package_id=None):
    """
    Return a list of packages to the client

    :param package_id:
    :return:
    """

    booleans = ('rollback', )

    if package_id:  # Simple, just fetch one package
        if not is_uuid(package_id):
            raise InvalidUsage("Package ID given is not a valid UUID")
        query = queries.get_package(package_id)
    else:  # Bit more complex
        # Flatten args, as the ImmutableDict puts some values in a list when
        # expanded
        args = {'limit': 100}
        for k in request.args.keys():
            if k in booleans:
                args[k] = str_to_bool(request.args.get(k))
            else:
                args[k] = request.args.get(k)
        query = queries.build_query(Package, **args)

    # Execute eagerly to avoid confusing stack traces within the Response on
    # error
    db.session.execute(query)

    if query.count() == 0:
        response = jsonify(message="No packages found", packages=[])
        return response, 404

    return Response(stream_json_list('packages', query),
                    content_type='application/json')
コード例 #3
0
ファイル: releases.py プロジェクト: weargoggles/orlo
def get_releases(release_id=None):
    """
    Return a list of releases to the client, filters optional

    :param string release_id: Optionally specify a single release UUID to
        fetch. This does not disable filters.
    :query bool asc: Normally results are returned ordered by stime
        descending, setting asc to true will reverse this and sort by stime
        ascending
    :query int limit: Limit the results by int (default 100)
    :query int offset: Offset the results by int
    :query string user: Filter releases by user the that performed the release
    :query string platform: Filter releases by platform
    :query string stime_before: Only include releases that started before \
        timestamp given
    :query string stime_after: Only include releases that started after \
        timestamp given
    :query string ftime_before: Only include releases that finished before \
        timestamp given
    :query string ftime_after: Only include releases that finished after \
        timestamp given
    :query string team: Filter releases by team
    :query string status: Filter by release status. This field is calculated \
        from the package status, see special note below.
    :query int duration_lt: Only include releases that took less than (int) \
        seconds
    :query int duration_gt: Only include releases that took more than (int) \
        seconds
    :query boolean package_rollback: Filter on whether or not the releases \
        contain a rollback
    :query string package_name: Filter by package name
    :query string package_version: Filter by package version
    :query int package_duration_gt: Filter by packages of duration greater than
    :query int package_duration_lt: Filter by packages of duration less than
    :query string package_status: Filter by package status. Valid statuses are:\
         "NOT_STARTED", "IN_PROGRESS", "SUCCESSFUL", "FAILED"

    **Note for time arguments**:
        The timestamp format you must use is specified in /etc/orlo/orlo.ini.
        All times are UTC.

    **Note on status**:
        The release status is calculated from the packages it contains. The
        possible values are the same as a package. For a release to be
        considered "SUCCESSFUL" or "NOT_STARTED", all packages must have this
        value. If any one package has the value "IN_PROGRESS" or "FAILED",
        that status applies to the whole release, with "FAILED" overriding
        "IN_PROGRESS".
    """

    booleans = ('rollback', 'package_rollback',)

    if release_id:  # Simple, just fetch one release
        if not is_uuid(release_id):
            raise InvalidUsage("Release ID given is not a valid UUID")
        query = queries.get_release(release_id)
    else:  # Bit more complex
        # Defaults
        args = {
            'limit': 100
        }
        # Flatten args, as the ImmutableDict puts some values in a list when
        # expanded
        for k in request.args.keys():
            if k in booleans:
                args[k] = str_to_bool(request.args.get(k))
            else:
                args[k] = request.args.get(k)
        query = queries.build_query(Release, **args)

    # Execute eagerly to avoid confusing stack traces within the Response on
    # error
    db.session.execute(query)

    if query.count() == 0:
        response = jsonify(message="No releases found", releases=[])
        return response, 404

    return Response(stream_json_list('releases', query),
                    content_type='application/json')
コード例 #4
0
def get_releases(release_id=None):
    """
    Return a list of releases to the client, filters optional

    :param string release_id: Optionally specify a single release UUID to
        fetch. This does not disable filters.
    :query bool desc: Normally results are returned ordered by stime
        ascending, setting desc to true will reverse this and sort by stime
        descending
    :query int limit: Limit the results by int
    :query int offset: Offset the results by int
    :query string package_name: Filter releases by package name
    :query string user: Filter releases by user the that performed the release
    :query string platform: Filter releases by platform
    :query string stime_before: Only include releases that started before \
        timestamp given
    :query string stime_after: Only include releases that started after \
        timestamp given
    :query string ftime_before: Only include releases that finished before \
        timestamp given
    :query string ftime_after: Only include releases that finished after \
        timestamp given
    :query string team: Filter releases by team
    :query string status: Filter by release status. This field is calculated \
        from the package status, see special note below.
    :query int duration_lt: Only include releases that took less than (int) \
        seconds
    :query int duration_gt: Only include releases that took more than (int) \
        seconds
    :query boolean package_rollback: Filter on whether or not the releases \
        contain a rollback
    :query string package_name: Filter by package name
    :query string package_version: Filter by package version
    :query int package_duration_gt: Filter by packages of duration greater than
    :query int package_duration_lt: Filter by packages of duration less than
    :query string package_status: Filter by package status. Valid statuses are:\
         "NOT_STARTED", "IN_PROGRESS", "SUCCESSFUL", "FAILED"

    **Note for time arguments**:
        The timestamp format you must use is specified in /etc/orlo/orlo.ini.
        All times are UTC.

    **Note on status**:
        The release status is calculated from the packages it contains. The
        possible values are the same as a package. For a release to be
        considered "SUCCESSFUL" or "NOT_STARTED", all packages must have this
        value. If any one package has the value "IN_PROGRESS" or "FAILED",
        that status applies to the whole release, with "FAILED" overriding
        "IN_PROGRESS".

    """

    booleans = ('rollback', 'package_rollback',)

    if release_id:  # Simple, just fetch one release
        if not is_uuid(release_id):
            raise InvalidUsage("Release ID given is not a valid UUID")
        query = queries.get_release(release_id)
    elif len([x for x in request.args.keys()]) == 0:
        raise InvalidUsage("Please specify a filter. See "
                           "http://orlo.readthedocs.org/en/latest/rest.html"
                           "#get--releases for more info")
    else:  # Bit more complex
        # Flatten args, as the ImmutableDict puts some values in a list when
        # expanded
        args = {}
        for k in request.args.keys():
            if k in booleans:
                args[k] = str_to_bool(request.args.get(k))
            else:
                args[k] = request.args.get(k)
        query = queries.releases(**args)

    # Execute eagerly to avoid confusing stack traces within the Response on
    # error
    db.session.execute(query)

    return Response(stream_json_list('releases', query),
                    content_type='application/json')