def commonjs_registry_root(req):
    channel = req.matchdict.get('channel', 'default')
    index = req.matchdict.get('index', 'default')

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    relics = DBSession.query(Relic).filter_by(index_id=indexobj.uid)
    uniqrelics = {}
    for relic in relics:
        matches = split_commonjs_name(relic.name)
        relicname = None
        if not matches:
            relicname = relic.name
        else:
            relicname = matches[0]
        relic_url = req.route_url('commonjs_registry_package_root',
                                  channel=channel,
                                  index=index,
                                  package=relicname)
        if relicname not in uniqrelics:
            uniqrelics[relicname] = relic_url

    return Response(json.dumps(uniqrelics, sort_keys=True, indent=2),
                    content_type='application/json',
                    status_code=200)
def commonjs_registry_package_root(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    package = req.matchdict.get('package', None)

    if not channel or not index or not package:
        return HTTPNotFound()

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    # this gets all packages that start with the requested package name,
    # but it may include more than the intended package -- from here,
    # each relic name needs to be broken down into it's name and version
    # then compared with the the given name
    results = DBSession.query(Relic) \
                       .filter_by(index_id=indexobj.uid) \
                       .filter(Relic.name.startswith(package))
    packageobjroot = dict(name=package, versions=dict())
    for relic in results:
        name, version, _ = split_commonjs_name(relic.name)
        if name.strip().lower() == package.strip().lower():
            relic_url = req.route_url('get_relic',
                                      channel=channel,
                                      index=index,
                                      relic_name=relic.name)
            packageobjroot["versions"][version] = dict(
                name=name, version=version, dist=dict(tarball=relic_url))

    return Response(json.dumps(packageobjroot, sort_keys=True, indent=2),
                    content_type='application/json',
                    status_code=200)
Example #3
0
def pypi_simple(req):
    channel = req.matchdict.get('channel', 'default')
    index = req.matchdict.get('index', 'default')

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return dict(lines=[])

    lines = []
    relics = DBSession.query(Relic).filter_by(index_id=indexobj.uid)
    uniqrelics = {}
    for relic in relics:
        matches = split_pypi_name(relic.name)
        # if a name couldn't be satisfactorly extracted, use the the whole
        # relic name as the package name
        if not matches:
            uniqrelics[relic.name] = True
        else:
            uniqrelics[matches[0]] = True
    for relic, _ in uniqrelics.items():
        lines.append("<a href='{0}'>{0}</a><br/>".format(
            pypi_normalize_package_name(relic)))

    lines.sort()

    return dict(lines=lines)
Example #4
0
def pypi_simple_package(req):
    channel = req.matchdict.get('channel', 'default')
    index = req.matchdict.get('index', 'default')
    package = req.matchdict.get('package', None)
    if not package:
        return Response('{"status":"error","package not found"}',
                        content_type='application/json',
                        status_code=404)
    package = pypi_normalize_package_name(package)

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return dict(lines=[])

    lines = []
    relics = DBSession.query(Relic).filter_by(index_id=indexobj.uid)
    matched = []
    for relic in relics:
        rparts = split_pypi_name(relic.name)
        normname = pypi_normalize_package_name(rparts[0])
        if package == normname:
            matched.append((relic.name, normname))
    matched.sort(key=lambda x: x[1])

    for relic in matched:
        packageurl = route_url('get_relic',
                               req,
                               channel=channel,
                               index=index,
                               relic_name=relic[0])
        lines.append("<a href='{0}' rel='internal'>{1}</a><br/>".format(
            packageurl, relic[0]))

    return dict(lines=lines)
Example #5
0
def packages_view(req, compression=None):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    arch = req.matchdict.get('arch', None)

    if not channel or not index or not arch:
        return HTTPNotFound()

    arch = arch.lower().strip()

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    pkgdata = generate_debian_package_index(
        channel,
        index,
        arch,
        compression=compression)

    if not pkgdata:
        return HTTPInternalServerError()

    contenttype = 'text/plain'
    if compression == 'gz':
        contenttype = 'application/gzip'
    elif compression == 'bz2':
        contenttype = 'application/x-bzip2'

    return Response(pkgdata[0], content_type=contenttype, status_code=200)
Example #6
0
def debian_compindex(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    arches = get_unique_architectures_set(indexobj.uid)
    items = []
    for arch in arches:
        items.append(dict(
            url=req.route_url('debian_archindex',
                              channel=channel,
                              index=index,
                              arch=arch),
            text="binary-"+arch,
            cls="folder"))
    items.sort(key=lambda x: x["text"])

    return dict(
        page_title="Index of /{}/dist/{}/main/".format(channel, index),
        items=items,
        datetime_generated=time.strftime("%Y-%m-%d %H:%M:%S"),
        show_updir=True,
    )
Example #7
0
def debian_distindex(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    items = [
        dict(url=req.route_url('debian_compindex',
                               channel=channel,
                               index=index),
             text="main",
             cls="folder"),
        dict(url=req.route_url('debian_distrelease',
                               channel=channel,
                               index=index),
             text="Release",
             cls="file"),
    ]

    return dict(
        page_title="Index of /{}/dist/{}/".format(channel, index),
        items=items,
        datetime_generated=time.strftime("%Y-%m-%d %H:%M:%S"),
        show_updir=True,
    )
Example #8
0
def autoindex(req):
    channel = req.matchdict.get('channel', 'default')
    index = req.matchdict.get('index', 'default')

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return Response('{"status":"error","channel/index not found"}',
                        content_type='application/json',
                        status_code=404)

    # RELIC
    relics = DBSession.query(Relic) \
                      .filter_by(index_id=indexobj.uid)
    if relics.count() <= 0:
        return Response('{"status":"error","/channel/index not found"}',
                        content_type='application/json',
                        status_code=404)
    relicout = []
    for relic in relics:
        relic_url = req.route_url('get_relic',
                                  channel=channel,
                                  index=index,
                                  relic_name=relic.name)
        relic_mtime = time.gmtime(float(relic.mtime))
        relicout.append('<a href="{}">{}</a>{}{}'.format(
            relic_url, relic.name,
            time.strftime('%d-%b-%Y %H:%M',
                          relic_mtime).rjust(79 - len(relic.name), ' '),
            str(relic.size).rjust(20, ' ')))

    return dict(display_path='/autoindex/{}/{}'.format(channel, index),
                relics=relicout)
Example #9
0
def debian_distrelease(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)

    if not channel or not index:
        return HTTPNotFound()

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    data = get_debian_release_data(indexobj.uid)
    return Response(data, content_type='text/plain', status_code=200)
Example #10
0
def debian_archindex(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    arch = req.matchdict.get('arch', None)

    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    items = [
        dict(url=req.route_url('debian_archrelease',
                               channel=channel,
                               index=index,
                               arch=arch),
             text="Release",
             cls="file"),
        dict(url=req.route_url('debian_archpackages',
                               channel=channel,
                               index=index,
                               arch=arch),
             text="Packages",
             cls="file"),
        dict(url=req.route_url('debian_archpackagesgz',
                               channel=channel,
                               index=index,
                               arch=arch),
             text="Packages.gz",
             cls="file"),
        dict(url=req.route_url('debian_archpackagesbz2',
                               channel=channel,
                               index=index,
                               arch=arch),
             text="Packages.bz2",
             cls="file"),
    ]
    items.sort(key=lambda x: x["text"])

    return dict(
        page_title="Index of /{}/dist/{}/main/binary-{}".format(channel, index, arch),
        items=items,
        datetime_generated=time.strftime("%Y-%m-%d %H:%M:%S"),
        show_updir=True,
    )
Example #11
0
def debian_pooldistindex(req):
    channel = req.matchdict.get('channel', None)
    index = req.matchdict.get('index', None)
    indexobj = fetch_index_from_names(channel, index)
    if not indexobj:
        return HTTPNotFound()

    items = []
    relics = DBSession.query(Relic).filter_by(index_id=indexobj.uid)
    for relic in relics:
        items.append(dict(
            url=req.route_url('debian_poolpackage', channel=channel, index=index, relic_name=relic.name),
            text=relic.name,
            cls="file"
        ))
    items.sort(key=lambda x: x["text"])

    return dict(
        page_title="Index of /{}/pool/{}/".format(channel, index),
        items=items,
        datetime_generated=time.strftime("%Y-%m-%d %H:%M:%S"),
        show_updir=True,
    )