Get list of collections from kwdb, then add urls necessary for hyperlinks
177460
def get_collections(kwdb, libtype="*"):
    """"""
    collections = kwdb.get_collections(libtype=libtype)
    for result in collections:
        url = flask.url_for(".doc_for_library", collection_id=result["collection_id"])
        result["url"] = url

    return collections
989278
function(params, callback) {
			var self = this;
			var collections = [];
		  // Get the collections for this dbName
	  	this.db.listCollections().toArray(function(err, colls) {
			  // Loop through the collections
	  		for (var n = 0; n < colls.length; n++) {

	  			var options = colls[n].options || {};
	  			// Remove the old name.
	  			delete options.create;
		  		// Remove the dbName from the collection name.
	  			options.name = parseName(colls[n].name);
	  			// Set the name as the _id.
	  			options._id = options.name;

	  			// Add it to the list.
	  	  	collections.push(options);
	  	  }

		  	// Async function to add stats to each collection.
		  	var addStats = function(coll, callback){
		  		// Switch databases
		  		var collection = self.db.collection(coll.name);
		  		// Get the stats. null if empty.
		  		collection.stats(function(err, stats){
		  			// Add the stats to the corresponding database.
		  			coll.stats = stats;
			  		callback(err, coll);
		  		});
		  	};

		  	async.each(collections, addStats, function(err){
	  	    if (err) {
	  	    	callback({error:err.errmsg});
	  	    } else {
	  	    	// Sort the collections
	  	    	collections.sort(function (a, b) {
	  	    		return (a.name > b.name) ? 1 : -1;
	  	    	});
	  	    	// Send the collections
					  return callback(null, collections);
	  	    }
		  	});
	  	});
		}
1181953
def list_from_url(cls, url):
        ''''''
        key = cls._get_key(url)
        metadata = cls._get_metadata_from_key(key)
        ct = cls._get_create_time(key)
        time_buckets = cls.get_time_buckets_from_metadata(metadata)
        return [cls(url, metadata, t, ct, key.size) for t in time_buckets]
181928
def links(self):
        
        link_dict = {'self': self.resource_uri()}
        for relationship in inspect(  # pylint: disable=maybe-no-member
                self.__class__).relationships:
            if 'collection' not in relationship.key:
                instance = getattr(self, relationship.key)
                if instance:
                    link_dict[str(relationship.key)] = instance.resource_uri()
        return link_dict
1192287
def index():
    """"""
    kwdb = current_app.kwdb

    libraries = get_collections(kwdb, libtype="library")
    resource_files = get_collections(kwdb, libtype="resource")

    return flask.render_template("libraryNames.html",
                                 data={"libraries": libraries,
                                       "version": __version__,
                                       "resource_files": resource_files
                                   })
693980
def get_collection(self, request, **kwargs):
        
        qs = self.queryset(request, **kwargs)

        if self.display_collection_fields:
            display_fields = self.display_collection_fields
        else:
            display_fields = self.display_fields

        if self.paginate_by is not None:
            page = request.GET.get('page', 1)
            paginator = Paginator(qs, self.paginate_by)
            try:
                qs = paginator.page(page).object_list
            except PageNotAnInteger:
                data = _('Invalid `page` parameter: Not a valid integer.')
                return HttpResponseBadRequest(data)
            except EmptyPage:
                data = _('Invalid `page` parameter: Out of range.')
                return HttpResponseBadRequest(data)
        data = [
            self.serialize(obj, ['id'] + list(display_fields)) for obj in qs
        ]
        return HttpResponse(self.json_dumps(data), content_type='application/json')
800863
def _get_links(network_id, template_id=None):
    
    extras = {'types':[], 'attributes':[]}
    link_qry = db.DBSession.query(Link).filter(
                                        Link.network_id==network_id,
                                        Link.status=='A').options(
                                            noload('network')
                                        )
    if template_id is not None:
        link_qry = link_qry.filter(ResourceType.link_id==Link.id,
                                   TemplateType.id==ResourceType.type_id,
                                   TemplateType.template_id==template_id)

    link_res = db.DBSession.execute(link_qry.statement).fetchall()

    links = []
    for l in link_res:
        links.append(JSONObject(l, extras=extras))

    return links
789621
def get_uri_list(self, **kwargs):
        
        index_status_filter = """
                optional {{ ?s dcterm:modified ?modTime }} .
                optional {{ ?s kds:esIndexTime ?time }} .
                optional {{ ?s kds:esIndexError ?error }}
                filter (
                    !(bound(?time)) ||
                    ?time<?modTime  ||
                    (bound(?error) && ?time < {idx_start_time}))
                """.format(idx_start_time=self.idx_start_time.sparql)
        items_query_template = """
            SELECT DISTINCT ?s ?es_id
            {{
                VALUES ?rdftypes {{\n\t\t{rdf_types} }} .
                ?s a ?rdftypes .
                BIND(SHA1(STR(?s)) as ?es_id) .
                {status_filter}
            }}
            {order_by}
            """
        status_filter = index_status_filter \
                        if not kwargs.get("no_status") else ""
        order_by = kwargs.get("order_by", "")
        sparql = items_query_template.format(
                rdf_types="\n\t\t".join(self.rdf_types),
                status_filter=status_filter,
                order_by=order_by)
        results = [(Uri(item['s']['value']), item['es_id']['value'],)
                   for item in self.tstore_conn.query(sparql=sparql)]
        return results
784047
function getIndexes(done, results) {
  var client = results.client;
  var ns = mongodbNS(results.namespace);
  client
    .db(ns.database)
    .collection(ns.collection)
    .indexes(function(err, indexes) {
      if (err) {
        done(err);
      }
      // add ns field to each index
      _.each(indexes, function(idx) {
        idx.ns = ns.ns;
      });
      done(null, indexes);
    });
}
1073705
function getCollection(items, query, cb, argsLength) {
  var skip = 0, limit = Number.MAX_SAFE_INTEGER;
  setImmediate(function() {
    if (argsLength === 1) {
      cb = query;
    } else {
      skip = (query.skip) ? query.skip : 0;
      limit = (query.limit) ? query.limit : Number.MAX_SAFE_INTEGER;
    }
    var sortedKeys = Object.keys(items);
    var qKeys = remove(remove(Object.keys(query), /skip/), /limit/);
    qKeys.forEach(function (k) {
      try {
        var re = new RegExp(query[k]);
        sortedKeys = sortedKeys.filter(function (l) {
          return items[l][k].toString().match(re);
        });
      } catch (e) {
        console.error(`Problem filtering collection for parameter ${k}.`,
          e.message);
      }
    });
    skip = checkSkip(skip, sortedKeys);
    limit = checkLimit(limit, sortedKeys);
    if (sortedKeys.length === 0 || limit === 0 || skip >= sortedKeys.length) {
      return cb(null, [], sortedKeys.length, 1, 1, 0);
    }
    var pages = Math.ceil(sortedKeys.length / limit);
    var pageOf = Math.ceil(skip / limit) + 1;
    var itemArray = new Array();
    for ( var x = skip ; x < Math.min(skip + limit, sortedKeys.length) ; x++ ) {
      itemArray.push(items[sortedKeys[x]]);
    }
    cb(null, itemArray, sortedKeys.length, pageOf, pages, itemArray.length);
  });
}
709874
def _db_urls(opts: Namespace) -> Tuple[str, str]:
        
        return opts.crcdb.replace("//", "//{crcuser}:{crcpassword}@".format(**opts.__dict__)),\
            opts.ontodb.replace("//", "//{ontouser}:{ontopassword}@".format(**opts.__dict__))
333721
def collection_get_options(collection_name, **kwargs):
    '''
    
    '''

    cluster = cluster_status(**kwargs)

    options = {
        "collection.configName": cluster["collections"][collection_name]["configName"],
        "router.name": cluster["collections"][collection_name]["router"]["name"],
        "replicationFactor": int(cluster["collections"][collection_name]["replicationFactor"]),
        "maxShardsPerNode": int(cluster["collections"][collection_name]["maxShardsPerNode"]),
        "autoAddReplicas": cluster["collections"][collection_name]["autoAddReplicas"] is True
    }

    if 'rule' in cluster["collections"][collection_name]:
        options['rule'] = cluster["collections"][collection_name]['rule']
    if 'snitch' in cluster["collections"][collection_name]:
        options['snitch'] = cluster["collections"][collection_name]['rule']

    return options
250120
def get_collection(self, collection, **kwargs):
        
        query = kwargs.get('query', {})
        projection = kwargs.get('projection', {})
        projection = None if len(projection) < 1 else projection
        limit = kwargs.get('limit', 0)  # no limit by default
        # sort = kwargs.get('sort', {})
        logging.info("About to get a collection from the database")
        logging.debug("Collection: {}".format(collection))
        logging.debug("Query: {}".format(query))
        logging.debug("Projection: {}".format(projection))
        logging.debug("Limit: {}".format(limit))
        records = \
            list(self.db[collection].find(query, projection).limit(limit))
        logging.debug("Got {} results".format(len(records)))
        return records
875694
def marvcli_query(ctx, list_tags, collections, discarded, outdated, path, tags, null):
    
    if not any([collections, discarded, list_tags, outdated, path, tags]):
        click.echo(ctx.get_help())
        ctx.exit(1)

    sep = '\x00' if null else '\n'

    site = create_app().site

    if '*' in collections:
        collections = None
    else:
        for col in collections:
            if col not in site.collections:
                ctx.fail('Unknown collection: {}'.format(col))

    if list_tags:
        tags = site.listtags(collections)
        if tags:
            click.echo(sep.join(tags), nl=not null)
        else:
            click.echo('no tags', err=True)
        return

    setids = site.query(collections, discarded, outdated, path, tags)
    if setids:
        sep = '\x00' if null else '\n'
        click.echo(sep.join(setids), nl=not null)
360957
private Map<String, Set<String>> scanForAnnotatedClasses(Set<URL> urls) throws IOException {
        AnnotationDB db = new AnnotationDB();
        db.setScanClassAnnotations(true);
        db.setScanFieldAnnotations(false);
        db.setScanMethodAnnotations(false);
        db.setScanParameterAnnotations(false);
      
        db.scanArchives(urls.toArray(new URL[urls.size()]));
        return db.getAnnotationIndex();
        
    }
240111
def get_collection(self, path):
        """"""
        while True:
            items = self.get(path)
            req = self.req
            for item in items:
                yield item
            if req.links and req.links['next'] and\
                    req.links['next']['rel'] == 'next':
                path = req.links['next']['url']
            else:
                break
16512
def collection(name=None):
    
    if name is None:
        collection = Collection.query.get_or_404(1)
    else:
        collection = Collection.query.filter(
            Collection.name == name).first_or_404()

    # TODO add breadcrumbs
    # breadcrumbs = current_breadcrumbs + collection.breadcrumbs(ln=g.ln)[1:]
    return render_template([
        'invenio_collections/collection_{0}.html'.format(collection.id),
        'invenio_collections/collection_{0}.html'.format(slugify(name, '_')),
        current_app.config['COLLECTIONS_DEFAULT_TEMPLATE']
    ], collection=collection)