예제 #1
0
def test_out_project(loghub, input, output, monkeypatch):
    from devpi import list_remove
    loghub.current.reconfigure(
        dict(
            simpleindex="/index",
            index="/root/dev/",
            login="******",
        ))
    loghub.args.status = False
    loghub.args.all = True
    loghub.args.failures = None
    loghub.args.toxresults = None
    monkeypatch.setattr(list_remove, "show_test_status", lambda *args: None)

    class reply:
        url = ""
        result = input

    out_project(loghub, reply, parse_requirement("p1"))
    matcher = loghub._getmatcher()
    matcher.fnmatch_lines(output)

    loghub.args.all = False
    out_project(loghub, reply, parse_requirement("p1"))
    matcher = loghub._getmatcher()
    matcher.fnmatch_lines(output[0])
예제 #2
0
def main_remove(hub, args):
    hub.require_valid_current_with_index()
    args = hub.args
    spec_or_url = args.spec_or_url
    if spec_or_url.startswith(('http://', 'https://')):
        # delete specified file
        url = spec_or_url
        if confirm_delete_file(hub, url):
            hub.http_api("delete", url)
        return

    # else delete project, release or distribution
    req = parse_requirement(args.spec_or_url)
    if args.index and args.index.count("/") > 1:
        hub.fatal("index %r not of form USER/NAME or NAME" % args.index)
    index_url = hub.current.get_index_url(indexname=args.index)
    proj_url = hub.current.get_project_url(req.project_name,
                                           indexname=args.index)
    reply = hub.http_api("get", proj_url, type="projectconfig")
    ver_to_delete = get_versions_to_delete(index_url, reply, req)
    if not ver_to_delete:
        hub.error("No releases or distributions found matching '%s'." %
                  args.spec_or_url)
        return 1
    if confirm_delete(hub, ver_to_delete):
        if req.specs:
            # delete specific versions
            for ver, links in ver_to_delete:
                hub.info("deleting release %s of %s" % (ver, req.project_name))
                hub.http_api("delete", proj_url.addpath(ver))
        else:
            # delete whole project
            hub.http_api("delete", proj_url)
    else:
        hub.error("not deleting anything")
예제 #3
0
def new_pr(hub, args):
    (name, ) = args.name
    (target, ) = args.target
    reqs = []
    for pkgspec in args.pkgspec:
        req = parse_requirement(pkgspec)
        if len(req.specs) != 1 or req.specs[0][0] != "==":
            hub.fatal(
                "The release specification needs to be of this form: name==version"
            )
        reqs.append(req)
    indexname = full_indexname(hub, name)
    url = hub.current.get_index_url(indexname, slash=False)
    hub.http_api(
        "put",
        url,
        dict(type="pr",
             bases=target,
             states=["new"],
             messages=["New pull request"]),
    )
    for req in reqs:
        hub.http_api(
            "push",
            hub.current.index,
            kvdict=dict(
                name=req.project_name,
                version="%s" % req.specs[0][1],
                targetindex=indexname,
            ),
            fatal=True,
        )
예제 #4
0
def test_confirm_delete(loghub, monkeypatch):
    loghub.current.reconfigure(
        dict(
            pypisubmit="/post",
            simpleindex="/index",
            index="/root/dev/",
            login="******",
        ))
    monkeypatch.setattr(loghub, "ask_confirm", lambda msg: True)

    class r:
        result = {
            "1.0": linkver("root/dev", "x-1.0.tar.gz"),
            "1.1": linkver("root/dev", "x-1.1.tar.gz")
        }
        type = "projectconfig"

    req = parse_requirement("x>=1.1")
    ver_to_delete = get_versions_to_delete(loghub.current.get_index_url(), r,
                                           req)
    assert confirm_delete(loghub, ver_to_delete)
    m = loghub._getmatcher()
    m.fnmatch_lines("""
        *x-1.1.tar.gz*
    """)
    assert "x-1.0" not in req
예제 #5
0
def main(hub, args):
    pusher = parse_target(hub, args)
    name = None
    version = None
    if '==' not in args.pkgspec and '-' in args.pkgspec:
        name, version = splitbasename(args.pkgspec + ".zip")[:2]
    if not name or not version:
        req = parse_requirement(args.pkgspec)
        if len(req.specs) != 1 or req.specs[0][0] != '==':
            hub.fatal(
                "The release specification needs to be of this form: name==version"
            )
        name = req.project_name
        version = req.specs[0][1]
    else:
        hub.warn("Old style package specification is deprecated, "
                 "use this form: your-pkg-name==your.version.specifier")
    r = pusher.execute(hub, name, version)
    failed = r.status_code not in (200, 201)
    if r.type == "actionlog":
        for action in r["result"]:
            red = int(action[0]) not in (200, 201, 410)
            failed = failed or red
            for line in (" ".join(map(str, action))).split("\n"):
                hub.line("   " + line, red=red)
    if failed:
        hub.fatal("Failure during upload")
예제 #6
0
def get_release_filter(stage):
    requirements = stage.ixconfig.get("releasefilter", "").splitlines()
    result = {}
    for requirement in requirements:
        requirement = requirement.strip()
        if not requirement:
            continue
        requirement = parse_requirement(requirement)
        result[requirement.project_name] = requirement
    return result
예제 #7
0
def main_list(hub, args):
    hub.require_valid_current_with_index()
    if hub.args.spec:
        req = parse_requirement(hub.args.spec)
        url = hub.current.get_project_url(req.project_name)
        reply = hub.http_api("get", url, type="projectconfig")
        out_project(hub, reply, req)
    else:
        reply = hub.http_api("get", hub.current.index, type="indexconfig")
        out_index(hub, reply.result["projects"])
예제 #8
0
def main_list(hub, args):
    hub.require_valid_current_with_index()
    if hub.args.spec:
        req = parse_requirement(hub.args.spec)
        url = hub.current.get_project_url(req.project_name)
        reply = hub.http_api("get", url, type="projectconfig")
        out_project(hub, reply.result, req)
    else:
        reply = hub.http_api("get", hub.current.index,
                             type="list:projectconfig")
        out_index(hub, reply.result)
예제 #9
0
def main_remove(hub, args):
    hub.require_valid_current_with_index()
    args = hub.args
    req = parse_requirement(args.spec)
    url = hub.current.get_project_url(req.project_name)
    reply = hub.http_api("get", url, type="projectconfig")
    ver_to_delete = confirm_delete(hub, reply, req)
    if ver_to_delete is None:
        hub.error("not deleting anything")
        return 1
    else:
        for ver, files in ver_to_delete:
            hub.info("deleting release %s of %s" % (ver, req.project_name))
            hub.http_api("delete", url.addpath(ver))
예제 #10
0
def main_list(hub, args):
    hub.require_valid_current_with_index()
    if hub.args.spec:
        req = parse_requirement(hub.args.spec)
        url = hub.current.get_project_url(
            req.project_name, indexname=args.index)
        reply = hub.http_api("get", url, type="projectconfig")
        out_project(hub, reply, req)
    else:
        index = hub.current.index
        if args.index:
            if args.index.count("/") > 1:
                hub.fatal("index %r not of form USER/NAME or NAME" % args.index)
            index = hub.current.get_index_url(args.index, slash=False)
        reply = hub.http_api("get", index, type="indexconfig")
        out_index(hub, reply.result["projects"])
예제 #11
0
def main_remove(hub, args):
    hub.require_valid_current_with_index()
    args = hub.args
    req = parse_requirement(args.spec)
    if args.index and args.index.count("/") > 1:
        hub.fatal("index %r not of form USER/NAME or NAME" % args.index)
    index_url = hub.current.get_index_url(indexname=args.index)
    proj_url = hub.current.get_project_url(req.project_name,
                                           indexname=args.index)
    reply = hub.http_api("get", proj_url, type="projectconfig")
    ver_to_delete = confirm_delete(hub, index_url, reply, req)
    if not ver_to_delete:
        hub.error("not deleting anything")
        return 1
    else:
        for ver, links in ver_to_delete:
            hub.info("deleting release %s of %s" % (ver, req.project_name))
            hub.http_api("delete", proj_url.addpath(ver))
예제 #12
0
def test_parse_requirement():
    req = parse_requirement("hello>=1.0")
    assert req.project_name == "hello"
    assert "1.0" in req
    assert "0.9" not in req